@@ -49,22 +49,22 @@ describe('search-box()', () => {
49
49
} ) ;
50
50
51
51
context ( 'targeting a div' , ( ) => {
52
+ let opts ;
53
+
52
54
beforeEach ( ( ) => {
53
55
container = document . createElement ( 'div' ) ;
54
- widget = searchBox ( { container} ) ;
55
- } ) ;
56
-
57
- it ( 'configures nothing' , ( ) => {
58
- expect ( widget . getConfiguration ) . toEqual ( undefined ) ;
56
+ opts = { container} ;
59
57
} ) ;
60
58
61
59
it ( 'adds an input inside the div' , ( ) => {
60
+ widget = searchBox ( opts ) ;
62
61
widget . init ( { state, helper} ) ;
63
62
let inputs = container . getElementsByTagName ( 'input' ) ;
64
63
expect ( inputs . length ) . toEqual ( 1 ) ;
65
64
} ) ;
66
65
67
66
it ( 'sets default HTML attribute to the input' , ( ) => {
67
+ widget = searchBox ( opts ) ;
68
68
widget . init ( { state, helper} ) ;
69
69
let input = container . getElementsByTagName ( 'input' ) [ 0 ] ;
70
70
expect ( input . getAttribute ( 'autocapitalize' ) ) . toEqual ( 'off' ) ;
@@ -76,6 +76,23 @@ describe('search-box()', () => {
76
76
expect ( input . getAttribute ( 'spellcheck' ) ) . toEqual ( 'false' ) ;
77
77
expect ( input . getAttribute ( 'type' ) ) . toEqual ( 'text' ) ;
78
78
} ) ;
79
+
80
+ it ( 'supports cssClasses option' , ( ) => {
81
+ opts . cssClasses = {
82
+ root : 'root-class' ,
83
+ input : 'input-class'
84
+ } ;
85
+
86
+ widget = searchBox ( opts ) ;
87
+ widget . init ( { state, helper} ) ;
88
+ let actualRootClasses = container . querySelector ( 'input' ) . parentNode . getAttribute ( 'class' ) ;
89
+ let actualInputClasses = container . querySelector ( 'input' ) . getAttribute ( 'class' ) ;
90
+ let expectedRootClasses = 'ais-search-box root-class' ;
91
+ let expectedInputClasses = 'ais-search-box--input input-class' ;
92
+
93
+ expect ( actualRootClasses ) . toEqual ( expectedRootClasses ) ;
94
+ expect ( actualInputClasses ) . toEqual ( expectedInputClasses ) ;
95
+ } ) ;
79
96
} ) ;
80
97
81
98
context ( 'targeting an input' , ( ) => {
@@ -102,6 +119,20 @@ describe('search-box()', () => {
102
119
expect ( container . getAttribute ( 'class' ) ) . toEqual ( 'my-class ais-search-box--input' ) ;
103
120
expect ( container . getAttribute ( 'placeholder' ) ) . toEqual ( 'Search' ) ;
104
121
} ) ;
122
+
123
+ it ( 'supports cssClasses' , ( ) => {
124
+ container = createHTMLNodeFromString ( '<input class="my-class" />' ) ;
125
+ widget = searchBox ( { container, cssClasses : { root : 'root-class' , input : 'input-class' } } ) ;
126
+ widget . init ( { state, helper} ) ;
127
+
128
+ let actualRootClasses = container . parentNode . getAttribute ( 'class' ) ;
129
+ let actualInputClasses = container . getAttribute ( 'class' ) ;
130
+ let expectedRootClasses = 'ais-search-box root-class' ;
131
+ let expectedInputClasses = 'my-class ais-search-box--input input-class' ;
132
+
133
+ expect ( actualRootClasses ) . toEqual ( expectedRootClasses ) ;
134
+ expect ( actualInputClasses ) . toEqual ( expectedInputClasses ) ;
135
+ } ) ;
105
136
} ) ;
106
137
107
138
context ( 'wraps the input in a div' , ( ) => {
0 commit comments