|
1 | 1 | import { expect } from 'chai'; |
| 2 | +import '../setup'; |
2 | 3 | import { mountJsonForms } from '../util'; |
3 | 4 |
|
| 5 | +const schemaWithVariousTypes = { |
| 6 | + type: 'object', |
| 7 | + properties: { |
| 8 | + oneOfProp: { |
| 9 | + title: 'Boolean or Array', |
| 10 | + oneOf: [ |
| 11 | + { |
| 12 | + title: 'Boolean', |
| 13 | + type: 'boolean', |
| 14 | + }, |
| 15 | + { |
| 16 | + title: 'Array', |
| 17 | + type: 'array', |
| 18 | + items: { |
| 19 | + type: 'string', |
| 20 | + }, |
| 21 | + }, |
| 22 | + { |
| 23 | + title: 'Object', |
| 24 | + type: 'object', |
| 25 | + properties: { |
| 26 | + name: { |
| 27 | + type: 'string', |
| 28 | + }, |
| 29 | + }, |
| 30 | + }, |
| 31 | + ], |
| 32 | + }, |
| 33 | + }, |
| 34 | +}; |
| 35 | + |
| 36 | +const uischemaWithVariousTypes = { |
| 37 | + type: 'Control', |
| 38 | + scope: '#/properties/oneOfProp', |
| 39 | +}; |
| 40 | + |
4 | 41 | const schema = { |
5 | 42 | title: 'My Object', |
6 | 43 | oneOf: [ |
@@ -34,6 +71,95 @@ const uischema = { |
34 | 71 | }; |
35 | 72 |
|
36 | 73 | describe('OneOfRenderer.vue', () => { |
| 74 | + it('shows confirmation dialog when switching from boolean true to array', async () => { |
| 75 | + const wrapper = mountJsonForms( |
| 76 | + { oneOfProp: true }, |
| 77 | + schemaWithVariousTypes, |
| 78 | + uischemaWithVariousTypes |
| 79 | + ); |
| 80 | + const oneOfSelect = wrapper.find('select'); |
| 81 | + const dialog = wrapper.find('dialog'); |
| 82 | + |
| 83 | + expect(oneOfSelect.element.value).to.equal('0'); |
| 84 | + expect(dialog.element.open).to.be.false; |
| 85 | + |
| 86 | + await oneOfSelect.setValue('1'); |
| 87 | + |
| 88 | + expect(dialog.element.open).to.be.true; |
| 89 | + }); |
| 90 | + |
| 91 | + it('shows confirmation dialog when switching from boolean false to array', async () => { |
| 92 | + const wrapper = mountJsonForms( |
| 93 | + { oneOfProp: false }, |
| 94 | + schemaWithVariousTypes, |
| 95 | + uischemaWithVariousTypes |
| 96 | + ); |
| 97 | + const oneOfSelect = wrapper.find('select'); |
| 98 | + const dialog = wrapper.find('dialog'); |
| 99 | + |
| 100 | + expect(oneOfSelect.element.value).to.equal('0'); |
| 101 | + expect(dialog.element.open).to.be.false; |
| 102 | + |
| 103 | + await oneOfSelect.setValue('1'); |
| 104 | + |
| 105 | + expect(dialog.element.open).to.be.true; |
| 106 | + }); |
| 107 | + |
| 108 | + it('allows adding items after switching from boolean to array', async () => { |
| 109 | + const wrapper = mountJsonForms( |
| 110 | + { oneOfProp: true }, |
| 111 | + schemaWithVariousTypes, |
| 112 | + uischemaWithVariousTypes |
| 113 | + ); |
| 114 | + const oneOfSelect = wrapper.find('select'); |
| 115 | + |
| 116 | + await oneOfSelect.setValue('1'); |
| 117 | + |
| 118 | + const confirmButton = wrapper.find('dialog button:last-child'); |
| 119 | + await confirmButton.trigger('click'); |
| 120 | + |
| 121 | + const addButton = wrapper.find('.array-list-add'); |
| 122 | + await addButton.trigger('click'); |
| 123 | + |
| 124 | + expect(wrapper.vm.data).to.deep.equal({ oneOfProp: [''] }); |
| 125 | + }); |
| 126 | + |
| 127 | + it('does not show confirmation dialog when switching from undefined to array', async () => { |
| 128 | + const wrapper = mountJsonForms( |
| 129 | + {}, |
| 130 | + schemaWithVariousTypes, |
| 131 | + uischemaWithVariousTypes |
| 132 | + ); |
| 133 | + const oneOfSelect = wrapper.find('select'); |
| 134 | + const dialog = wrapper.find('dialog'); |
| 135 | + |
| 136 | + await oneOfSelect.setValue('1'); |
| 137 | + |
| 138 | + expect(dialog.element.open).to.be.false; |
| 139 | + expect(wrapper.vm.data).to.deep.equal({}); |
| 140 | + }); |
| 141 | + |
| 142 | + it('allows adding items after switching from object to array', async () => { |
| 143 | + const wrapper = mountJsonForms( |
| 144 | + { oneOfProp: { name: 'test' } }, |
| 145 | + schemaWithVariousTypes, |
| 146 | + uischemaWithVariousTypes |
| 147 | + ); |
| 148 | + const oneOfSelect = wrapper.find('select'); |
| 149 | + |
| 150 | + expect(oneOfSelect.element.value).to.equal('2'); |
| 151 | + |
| 152 | + await oneOfSelect.setValue('1'); |
| 153 | + |
| 154 | + const confirmButton = wrapper.find('dialog button:last-child'); |
| 155 | + await confirmButton.trigger('click'); |
| 156 | + |
| 157 | + const addButton = wrapper.find('.array-list-add'); |
| 158 | + await addButton.trigger('click'); |
| 159 | + |
| 160 | + expect(wrapper.vm.data).to.deep.equal({ oneOfProp: [''] }); |
| 161 | + }); |
| 162 | + |
37 | 163 | it('render has a class', () => { |
38 | 164 | const wrapper = mountJsonForms({ variant: 'b', b: 'b' }, schema, uischema); |
39 | 165 | expect(wrapper.find('div.one-of').exists()).to.be.true; |
|
0 commit comments