feat: refs #7056 add tests in FormModel
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
dd7b6a7732
commit
48742289fe
|
@ -54,46 +54,13 @@ describe('FormModel', () => {
|
||||||
const { vm } = mount({
|
const { vm } = mount({
|
||||||
propsData: { url, model, formInitialData },
|
propsData: { url, model, formInitialData },
|
||||||
});
|
});
|
||||||
vm.state.set(model, { mockKey: 'mockVal' });
|
vm.state.set(model, formInitialData);
|
||||||
expect(vm.hasChanges).toBe(false);
|
expect(vm.hasChanges).toBe(false);
|
||||||
|
|
||||||
vm.formData.mockKey = 'newVal';
|
vm.formData.mockKey = 'newVal';
|
||||||
await vm.$nextTick();
|
await vm.$nextTick();
|
||||||
expect(vm.hasChanges).toBe(true);
|
expect(vm.hasChanges).toBe(true);
|
||||||
});
|
vm.formData.mockKey = 'mockVal';
|
||||||
});
|
|
||||||
|
|
||||||
describe.skip('watch()', () => {
|
|
||||||
let wrapper;
|
|
||||||
let vm;
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
wrapper = mount({
|
|
||||||
propsData: { url, model, formInitialData },
|
|
||||||
});
|
|
||||||
vm = wrapper.vm;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call updateAndEmit when arrayData.store.data changes', async () => {
|
|
||||||
const updateAndEmitSpy = vi.spyOn(vm, 'updateAndEmit');
|
|
||||||
await vm.$nextTick();
|
|
||||||
console.log('vm.arrayData.store.data', vm.arrayData.store.data);
|
|
||||||
vm.arrayData.store.data = { newData: 'newValue' };
|
|
||||||
await vm.$nextTick();
|
|
||||||
vm.arrayData.store.data = { newData: 'anotherVal' };
|
|
||||||
await vm.$nextTick();
|
|
||||||
|
|
||||||
expect(updateAndEmitSpy).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call reset and fetch when $props.url or $props.filter changes', async () => {
|
|
||||||
const resetSpy = vi.spyOn(vm, 'reset');
|
|
||||||
const fetchSpy = vi.spyOn(vm, 'fetch');
|
|
||||||
|
|
||||||
wrapper.setProps({ url: 'newMockUrl' });
|
|
||||||
await wrapper.vm.$nextTick();
|
|
||||||
expect(resetSpy).toHaveBeenCalled();
|
|
||||||
expect(fetchSpy).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -116,24 +83,34 @@ describe('FormModel', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onUnmounted()', () => {
|
describe('save()', async () => {
|
||||||
it('should restore original data in the store if changes were made but not saved', async () => {
|
it('should not call if there are not changes', async () => {
|
||||||
const wrapper = mount({ propsData: { model, formInitialData } });
|
const { vm } = mount({ propsData: { url, model } });
|
||||||
const vm = wrapper.vm;
|
|
||||||
vm.formData.mockKey = 'newVal';
|
await vm.save();
|
||||||
await vm.$nextTick();
|
expect(vm.hasChanges).toBe(false);
|
||||||
await wrapper.unmount();
|
|
||||||
expect(vm.state.get(model)).toEqual(formInitialData);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should clear the store on unmount if clearStoreOnUnmount is true', async () => {
|
it('should call axios.patch with the right data', async () => {
|
||||||
const wrapper = mount({
|
const spy = vi.spyOn(axios, 'patch').mockResolvedValue({ data: {} });
|
||||||
propsData: { model, formInitialData, clearStoreOnUnmount: true },
|
const { vm } = mount({ propsData: { url, model, formInitialData } });
|
||||||
|
vm.formData.mockKey = 'newVal';
|
||||||
|
await vm.$nextTick();
|
||||||
|
await vm.save();
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
vm.formData.mockKey = 'mockVal';
|
||||||
});
|
});
|
||||||
const vm = wrapper.vm;
|
|
||||||
vm.hasChanges = false;
|
it('should call axios.post with the right data', async () => {
|
||||||
await wrapper.unmount();
|
const spy = vi.spyOn(axios, 'post').mockResolvedValue({ data: {} });
|
||||||
expect(vm.state.get(model)).toBeUndefined();
|
const { vm } = mount({
|
||||||
|
propsData: { url, model, formInitialData, urlCreate: 'mockUrlCreate' },
|
||||||
|
});
|
||||||
|
vm.formData.mockKey = 'newVal';
|
||||||
|
await vm.$nextTick();
|
||||||
|
await vm.save();
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
vm.formData.mockKey = 'mockVal';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue