-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Changelog: * Fix(frontend): Fixed dynamic field value reset. See merge request vst/vst-utils!613
- Loading branch information
Showing
3 changed files
with
72 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
frontend_src/vstutils/fields/dynamic/__tests__/DynamicField.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { beforeAll, describe, expect, test, jest } from '@jest/globals'; | ||
import { StringField } from '@/vstutils/fields/text'; | ||
import { DynamicField } from '../DynamicField'; | ||
import { createApp } from '@/unittests'; | ||
import VueI18n from 'vue-i18n'; | ||
import { nextTick, reactive } from 'vue'; | ||
import { mount } from '@vue/test-utils'; | ||
|
||
let app: Awaited<ReturnType<typeof createApp>>; | ||
|
||
beforeAll(async () => { | ||
app = await createApp(); | ||
}); | ||
|
||
describe('DynamicField', () => { | ||
test('real field with same structure will not trigger value reset', async () => { | ||
const field = new DynamicField({ | ||
name: 'field', | ||
type: 'string', | ||
'x-options': { | ||
field: ['someField'], | ||
types: {}, | ||
}, | ||
}); | ||
|
||
// Override getRealField to return field of same type but different instance | ||
field.getRealField = function getRealField() { | ||
return new StringField({ | ||
name: 'field', | ||
type: 'string', | ||
}); | ||
}; | ||
|
||
const data = reactive({ someField: 'val 1', field: 'initial value' }); | ||
const setValue = jest.fn(); | ||
const wrapper = mount( | ||
{ | ||
template: `<Field :field="field" :data="data" type="readonly" @set-value="setValue" />`, | ||
components: { Field: field.getComponent() }, | ||
setup() { | ||
return { | ||
field, | ||
data: data, | ||
setValue, | ||
}; | ||
}, | ||
}, | ||
{ localVue: app.vue, i18n: new VueI18n() }, | ||
); | ||
|
||
expect(wrapper.html()).toMatch(/initial value/); | ||
expect(setValue).toBeCalledTimes(0); | ||
data.someField = 'val 2'; | ||
await nextTick(); | ||
expect(wrapper.html()).toMatch(/initial value/); | ||
expect(setValue).toBeCalledTimes(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# pylint: disable=django-not-available | ||
__version__: str = '5.8.11' | ||
__version__: str = '5.8.12' |