11import { ComponentFixture , TestBed , waitForAsync } from "@angular/core/testing" ;
22import { By } from "@angular/platform-browser" ;
33
4- import { Search } from "./search.component" ;
54import { FormsModule } from "@angular/forms" ;
65import { I18nModule } from "../i18n/index" ;
76import { IconModule } from "../icon/index" ;
7+ import { Search } from "./search.component" ;
88
99describe ( "Search" , ( ) => {
1010 let component : Search ;
@@ -38,46 +38,46 @@ describe("Search", () => {
3838 } ) ;
3939
4040 it ( "should bind input value" , ( ) => {
41- component . value = "Text" ;
41+ fixture . componentRef . setInput ( " value" , "Text" ) ;
4242 fixture . detectChanges ( ) ;
4343 expect ( inputElement . value ) . toEqual ( "Text" ) ;
4444 } ) ;
4545
4646 it ( "should bind input disabled" , ( ) => {
4747 expect ( inputElement . disabled ) . toEqual ( false ) ;
48- component . disabled = true ;
48+ fixture . componentRef . setInput ( " disabled" , true ) ;
4949 fixture . detectChanges ( ) ;
5050 expect ( inputElement . disabled ) . toEqual ( true ) ;
5151 } ) ;
5252
5353 it ( "should bind input required" , ( ) => {
54- component . required = true ;
54+ fixture . componentRef . setInput ( " required" , true ) ;
5555 fixture . detectChanges ( ) ;
5656 expect ( inputElement . required ) . toEqual ( true ) ;
5757 } ) ;
5858
5959 it ( "should display component of the correct size" , ( ) => {
6060 containerElement = fixture . debugElement . query ( By . css ( ".cds--search" ) ) . nativeElement ;
61- component . size = "lg" ;
61+ fixture . componentRef . setInput ( " size" , "lg" ) ;
6262 fixture . detectChanges ( ) ;
6363 expect ( containerElement . className . includes ( "cds--search--lg" ) ) . toEqual ( true ) ;
64- component . size = "sm" ;
64+ fixture . componentRef . setInput ( " size" , "sm" ) ;
6565 fixture . detectChanges ( ) ;
6666 expect ( containerElement . className . includes ( "cds--search--sm" ) ) . toEqual ( true ) ;
6767 } ) ;
6868
6969 it ( "should display clear button" , ( ) => {
7070 clearButtonElement = fixture . debugElement . query ( By . css ( "button" ) ) . nativeElement ;
71- component . value = "" ;
71+ fixture . componentRef . setInput ( " value" , "" ) ;
7272 fixture . detectChanges ( ) ;
7373 expect ( clearButtonElement . className . includes ( "cds--search-close--hidden" ) ) . toEqual ( true ) ;
74- component . value = "Text" ;
74+ fixture . componentRef . setInput ( " value" , "Text" ) ;
7575 fixture . detectChanges ( ) ;
7676 expect ( clearButtonElement . className . includes ( "cds--search-close--hidden" ) ) . toEqual ( false ) ;
7777 } ) ;
7878
7979 it ( "should clear input when clear button is clicked" , ( ) => {
80- component . value = "Text" ;
80+ fixture . componentRef . setInput ( " value" , "Text" ) ;
8181 fixture . detectChanges ( ) ;
8282 clearButtonElement = fixture . debugElement . query ( By . css ( "button" ) ) . nativeElement ;
8383 clearButtonElement . click ( ) ;
@@ -86,8 +86,8 @@ describe("Search", () => {
8686 } ) ;
8787
8888 it ( "should clear the input when the clear button is clicked on the expandable component" , ( ) => {
89- component . expandable = true ;
90- component . value = "TextToClear" ;
89+ fixture . componentRef . setInput ( " expandable" , true ) ;
90+ fixture . componentRef . setInput ( " value" , "TextToClear" ) ;
9191 fixture . detectChanges ( ) ;
9292 clearButtonElement = fixture . debugElement . query ( By . css ( "button" ) ) . nativeElement ;
9393 clearButtonElement . click ( ) ;
@@ -97,7 +97,7 @@ describe("Search", () => {
9797
9898 it ( "should clear the input when the escape key is pressed" , ( ) => {
9999 clearButtonElement = fixture . debugElement . query ( By . css ( "button" ) ) . nativeElement ;
100- component . value = "TextToClear" ;
100+ fixture . componentRef . setInput ( " value" , "TextToClear" ) ;
101101 fixture . detectChanges ( ) ;
102102 expect ( clearButtonElement . className . includes ( "cds--search-close--hidden" ) ) . toEqual ( false ) ;
103103 component . keyDown ( new KeyboardEvent ( "keydown" , {
@@ -109,10 +109,10 @@ describe("Search", () => {
109109 } ) ;
110110
111111 it ( "should clear the input and keep the expanded state open when the escape key is pressed" , ( ) => {
112- component . expandable = true ;
113- component . active = true ;
112+ fixture . componentRef . setInput ( " expandable" , true ) ;
113+ fixture . componentRef . setInput ( " active" , true ) ;
114114 containerElement = fixture . debugElement . query ( By . css ( ".cds--search" ) ) . nativeElement ;
115- component . value = "TextToClear" ;
115+ fixture . componentRef . setInput ( " value" , "TextToClear" ) ;
116116 fixture . detectChanges ( ) ;
117117 expect ( containerElement . className . includes ( "cds--search--expanded" ) ) . toEqual ( true ) ;
118118 component . keyDown ( new KeyboardEvent ( "keydown" , {
@@ -124,10 +124,10 @@ describe("Search", () => {
124124 } ) ;
125125
126126 it ( "should close the expandable search component when esc is pressed when content is empty" , ( ) => {
127- component . expandable = true ;
128- component . active = true ;
127+ fixture . componentRef . setInput ( " expandable" , true ) ;
128+ fixture . componentRef . setInput ( " active" , true ) ;
129129 containerElement = fixture . debugElement . query ( By . css ( ".cds--search" ) ) . nativeElement ;
130- component . value = "" ;
130+ fixture . componentRef . setInput ( " value" , "" ) ;
131131 fixture . detectChanges ( ) ;
132132 expect ( containerElement . className . includes ( "cds--search--expanded" ) ) . toEqual ( true ) ;
133133 component . keyDown ( new KeyboardEvent ( "keydown" , {
@@ -140,10 +140,10 @@ describe("Search", () => {
140140
141141 it ( "should have dark and light theme" , ( ) => {
142142 containerElement = fixture . debugElement . query ( By . css ( ".cds--search" ) ) . nativeElement ;
143- component . theme = "dark" ;
143+ fixture . componentRef . setInput ( " theme" , "dark" ) ;
144144 fixture . detectChanges ( ) ;
145145 expect ( containerElement . className . includes ( "cds--search--light" ) ) . toEqual ( false ) ;
146- component . theme = "light" ;
146+ fixture . componentRef . setInput ( " theme" , "light" ) ;
147147 fixture . detectChanges ( ) ;
148148 expect ( containerElement . className . includes ( "cds--search--light" ) ) . toEqual ( true ) ;
149149 } ) ;
0 commit comments