@@ -10,6 +10,7 @@ const mockEvent = jest.fn(() => {});
10
10
const params = {
11
11
name : 'test' ,
12
12
category : 'shortAnswer' ,
13
+ neighborNames : [ 'test' , 'input2' ] ,
13
14
} ;
14
15
15
16
const props = {
@@ -122,8 +123,32 @@ describe('Card', () => {
122
123
key . simulate ( 'change' , { target : { value : 'test' } } ) ;
123
124
key . simulate ( 'blur' ) ;
124
125
expect ( mockEvent . mock . calls ) . toEqual ( [
125
- [ '{"name":"wow_name_change","category":"shortAnswer"}' ] ,
126
- [ '{"name":"test","category":"shortAnswer"}' ] ,
126
+ [
127
+ '{"name":"wow_name_change","category":"shortAnswer","neighborNames":["test","input2"]}' ,
128
+ ] ,
129
+ [
130
+ '{"name":"test","category":"shortAnswer","neighborNames":["test","input2"]}' ,
131
+ ] ,
132
+ ] ) ;
133
+ mockEvent . mockClear ( ) ;
134
+ } ) ;
135
+
136
+ it ( 'does not change the name if the name is already in use' , ( ) => {
137
+ const div = document . createElement ( 'div' ) ;
138
+ document . body . appendChild ( div ) ;
139
+ const wrapper = mount ( < Card { ...props } /> , { attachTo : div } ) ;
140
+ const key = wrapper
141
+ . find ( '.card-container' )
142
+ . first ( )
143
+ . find ( '.card-text' )
144
+ . at ( 1 ) ;
145
+ key . simulate ( 'focus' ) ;
146
+ key . simulate ( 'change' , { target : { value : 'input2' } } ) ;
147
+ key . simulate ( 'blur' ) ;
148
+ expect ( mockEvent . mock . calls ) . toEqual ( [
149
+ [
150
+ '{"name":"test","category":"shortAnswer","neighborNames":["test","input2"]}' ,
151
+ ] ,
127
152
] ) ;
128
153
mockEvent . mockClear ( ) ;
129
154
} ) ;
@@ -149,9 +174,13 @@ describe('Card', () => {
149
174
} ) ;
150
175
description . simulate ( 'blur' ) ;
151
176
expect ( mockEvent . mock . calls ) . toEqual ( [
152
- [ '{"name":"test","category":"shortAnswer","title":"wow title change"}' ] ,
153
177
[
154
- '{"name":"test","category":"shortAnswer","description":"wow description change"}' ,
178
+ '{"name":"test","category":"shortAnswer","neighborNames":["test","input2"],"title":' +
179
+ '"wow title change"}' ,
180
+ ] ,
181
+ [
182
+ '{"name":"test","category":"shortAnswer","neighborNames":["test","input2"],' +
183
+ '"description":"wow description change"}' ,
155
184
] ,
156
185
] ) ;
157
186
mockEvent . mockClear ( ) ;
0 commit comments