Skip to content

Commit 3a1f9b1

Browse files
committed
Prevent duplicate key assignment
Prevent an input from being assigned a key that is already being used.
1 parent 07174c8 commit 3a1f9b1

File tree

4 files changed

+228
-150
lines changed

4 files changed

+228
-150
lines changed

src/formBuilder/Card.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ const useStyles = createUseStyles({
2929
'font-size': '14px',
3030
'font-weight': 'bold',
3131
},
32+
'& .card-entry-row': {
33+
display: 'flex',
34+
},
3235
'& .card-entry': {
33-
display: 'inline-block',
3436
margin: 0,
3537
width: '50%',
3638
'text-align': 'left',

src/formBuilder/Card.test.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const mockEvent = jest.fn(() => {});
1010
const params = {
1111
name: 'test',
1212
category: 'shortAnswer',
13+
neighborNames: ['test', 'input2'],
1314
};
1415

1516
const props = {
@@ -122,8 +123,32 @@ describe('Card', () => {
122123
key.simulate('change', { target: { value: 'test' } });
123124
key.simulate('blur');
124125
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+
],
127152
]);
128153
mockEvent.mockClear();
129154
});
@@ -149,9 +174,13 @@ describe('Card', () => {
149174
});
150175
description.simulate('blur');
151176
expect(mockEvent.mock.calls).toEqual([
152-
['{"name":"test","category":"shortAnswer","title":"wow title change"}'],
153177
[
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"}',
155184
],
156185
]);
157186
mockEvent.mockClear();

0 commit comments

Comments
 (0)