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({
|
||||
propsData: { url, model, formInitialData },
|
||||
});
|
||||
vm.state.set(model, { mockKey: 'mockVal' });
|
||||
vm.state.set(model, formInitialData);
|
||||
expect(vm.hasChanges).toBe(false);
|
||||
|
||||
vm.formData.mockKey = 'newVal';
|
||||
await vm.$nextTick();
|
||||
expect(vm.hasChanges).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
vm.formData.mockKey = 'mockVal';
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -116,24 +83,34 @@ describe('FormModel', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('onUnmounted()', () => {
|
||||
it('should restore original data in the store if changes were made but not saved', async () => {
|
||||
const wrapper = mount({ propsData: { model, formInitialData } });
|
||||
const vm = wrapper.vm;
|
||||
vm.formData.mockKey = 'newVal';
|
||||
await vm.$nextTick();
|
||||
await wrapper.unmount();
|
||||
expect(vm.state.get(model)).toEqual(formInitialData);
|
||||
describe('save()', async () => {
|
||||
it('should not call if there are not changes', async () => {
|
||||
const { vm } = mount({ propsData: { url, model } });
|
||||
|
||||
await vm.save();
|
||||
expect(vm.hasChanges).toBe(false);
|
||||
});
|
||||
|
||||
it('should clear the store on unmount if clearStoreOnUnmount is true', async () => {
|
||||
const wrapper = mount({
|
||||
propsData: { model, formInitialData, clearStoreOnUnmount: true },
|
||||
it('should call axios.patch with the right data', async () => {
|
||||
const spy = vi.spyOn(axios, 'patch').mockResolvedValue({ data: {} });
|
||||
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;
|
||||
await wrapper.unmount();
|
||||
expect(vm.state.get(model)).toBeUndefined();
|
||||
|
||||
it('should call axios.post with the right data', async () => {
|
||||
const spy = vi.spyOn(axios, 'post').mockResolvedValue({ data: {} });
|
||||
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