This commit is contained in:
parent
967848c790
commit
a7af697947
|
@ -30,8 +30,8 @@ describe('CrudModel', () => {
|
||||||
saveFn: '',
|
saveFn: '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
wrapper=wrapper.wrapper;
|
wrapper = wrapper.wrapper;
|
||||||
vm=wrapper.vm;
|
vm = wrapper.vm;
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -143,14 +143,14 @@ describe('CrudModel', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if object is empty', async () => {
|
it('should return true if object is empty', async () => {
|
||||||
dummyObj ={};
|
dummyObj = {};
|
||||||
result = vm.isEmpty(dummyObj);
|
result = vm.isEmpty(dummyObj);
|
||||||
|
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false if object is not empty', async () => {
|
it('should return false if object is not empty', async () => {
|
||||||
dummyObj = {a:1, b:2, c:3};
|
dummyObj = { a: 1, b: 2, c: 3 };
|
||||||
result = vm.isEmpty(dummyObj);
|
result = vm.isEmpty(dummyObj);
|
||||||
|
|
||||||
expect(result).toBe(false);
|
expect(result).toBe(false);
|
||||||
|
@ -158,29 +158,31 @@ describe('CrudModel', () => {
|
||||||
|
|
||||||
it('should return true if array is empty', async () => {
|
it('should return true if array is empty', async () => {
|
||||||
dummyArray = [];
|
dummyArray = [];
|
||||||
result = vm.isEmpty(dummyArray);
|
result = vm.isEmpty(dummyArray);
|
||||||
|
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false if array is not empty', async () => {
|
it('should return false if array is not empty', async () => {
|
||||||
dummyArray = [1,2,3];
|
dummyArray = [1, 2, 3];
|
||||||
result = vm.isEmpty(dummyArray);
|
result = vm.isEmpty(dummyArray);
|
||||||
|
|
||||||
expect(result).toBe(false);
|
expect(result).toBe(false);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('resetData()', () => {
|
describe('resetData()', () => {
|
||||||
it('should add $index to elements in data[] and sets originalData and formData with data', async () => {
|
it('should add $index to elements in data[] and sets originalData and formData with data', async () => {
|
||||||
data = [{
|
data = [
|
||||||
name: 'Tony',
|
{
|
||||||
lastName: 'Stark',
|
name: 'Tony',
|
||||||
age: 42,
|
lastName: 'Stark',
|
||||||
}];
|
age: 42,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
vm.resetData(data);
|
vm.resetData(data);
|
||||||
|
|
||||||
expect(vm.originalData).toEqual(data);
|
expect(vm.originalData).toEqual(data);
|
||||||
expect(vm.originalData[0].$index).toEqual(0);
|
expect(vm.originalData[0].$index).toEqual(0);
|
||||||
expect(vm.formData).toEqual(data);
|
expect(vm.formData).toEqual(data);
|
||||||
|
@ -200,7 +202,7 @@ describe('CrudModel', () => {
|
||||||
lastName: 'Stark',
|
lastName: 'Stark',
|
||||||
age: 42,
|
age: 42,
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.resetData(data);
|
vm.resetData(data);
|
||||||
|
|
||||||
expect(vm.originalData).toEqual(data);
|
expect(vm.originalData).toEqual(data);
|
||||||
|
@ -210,17 +212,19 @@ describe('CrudModel', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('saveChanges()', () => {
|
describe('saveChanges()', () => {
|
||||||
data = [{
|
data = [
|
||||||
name: 'Tony',
|
{
|
||||||
lastName: 'Stark',
|
name: 'Tony',
|
||||||
age: 42,
|
lastName: 'Stark',
|
||||||
}];
|
age: 42,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
it('should call saveFn if exists', async () => {
|
it('should call saveFn if exists', async () => {
|
||||||
await wrapper.setProps({ saveFn: vi.fn() });
|
await wrapper.setProps({ saveFn: vi.fn() });
|
||||||
|
|
||||||
vm.saveChanges(data);
|
vm.saveChanges(data);
|
||||||
|
|
||||||
expect(vm.saveFn).toHaveBeenCalledOnce();
|
expect(vm.saveFn).toHaveBeenCalledOnce();
|
||||||
expect(vm.isLoading).toBe(false);
|
expect(vm.isLoading).toBe(false);
|
||||||
expect(vm.hasChanges).toBe(false);
|
expect(vm.hasChanges).toBe(false);
|
||||||
|
@ -229,13 +233,15 @@ describe('CrudModel', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should use default url if there's not saveFn", async () => {
|
it("should use default url if there's not saveFn", async () => {
|
||||||
const postMock =vi.spyOn(axios, 'post');
|
const postMock = vi.spyOn(axios, 'post');
|
||||||
|
|
||||||
vm.formData = [{
|
vm.formData = [
|
||||||
name: 'Bruce',
|
{
|
||||||
lastName: 'Wayne',
|
name: 'Bruce',
|
||||||
age: 45,
|
lastName: 'Wayne',
|
||||||
}]
|
age: 45,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
await vm.saveChanges(data);
|
await vm.saveChanges(data);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue