#8448 - devToTest #1254
|
@ -4,21 +4,23 @@ import VnNotes from 'src/components/ui/VnNotes.vue';
|
||||||
|
|
||||||
describe('VnNotes', () => {
|
describe('VnNotes', () => {
|
||||||
let vm;
|
let vm;
|
||||||
|
let wrapper;
|
||||||
let spyFetch;
|
let spyFetch;
|
||||||
let postMock;
|
let postMock;
|
||||||
|
let expectedBody;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
vi.spyOn(axios, 'get').mockReturnValue({ data: [] });
|
vi.spyOn(axios, 'get').mockReturnValue({ data: [] });
|
||||||
|
|
||||||
vm = createWrapper(VnNotes, {
|
wrapper = createWrapper(VnNotes, {
|
||||||
propsData: {
|
propsData: {
|
||||||
url: '/test',
|
url: '/test',
|
||||||
filter: { order: 'created DESC' },
|
|
||||||
body: { name: 'Tony', lastName: 'Stark' },
|
body: { name: 'Tony', lastName: 'Stark' },
|
||||||
addNote: false,
|
selectType: false,
|
||||||
selectType: true,
|
|
||||||
}
|
}
|
||||||
}).vm;
|
});
|
||||||
|
wrapper = wrapper.wrapper;
|
||||||
|
vm = wrapper.vm;
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -31,9 +33,10 @@ describe('VnNotes', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('insert', () => {
|
describe('insert', () => {
|
||||||
it('should not call axios.post if newNote.text is empty', async () => {
|
it('should not call axios.post and vnPaginateRef.fetch if newNote.text is null', async () => {
|
||||||
vm.newNote.text = '';
|
vm.newNote.text = null;
|
||||||
vm.newNote.observationTypeFk = 1;
|
vm.newNote.observationTypeFk = null;
|
||||||
|
await wrapper.setProps({ selectType: true });
|
||||||
|
|
||||||
await vm.insert();
|
await vm.insert();
|
||||||
|
|
||||||
|
@ -41,9 +44,10 @@ describe('VnNotes', () => {
|
||||||
expect(spyFetch).not.toHaveBeenCalled();
|
expect(spyFetch).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not call axios.post if observationTypeFk is missing and selectType is set', async () => {
|
it('should not call axios.post and vnPaginateRef.fetch if newNote.text is empty', async () => {
|
||||||
vm.newNote.text = 'Test Note';
|
vm.newNote.text = "";
|
||||||
vm.newNote.observationTypeFk = null;
|
vm.newNote.observationTypeFk = null;
|
||||||
|
await wrapper.setProps({ selectType: false });
|
||||||
|
|
||||||
await vm.insert();
|
await vm.insert();
|
||||||
|
|
||||||
|
@ -51,11 +55,49 @@ describe('VnNotes', () => {
|
||||||
expect(spyFetch).not.toHaveBeenCalled();
|
expect(spyFetch).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not call axios.post and vnPaginateRef.fetch if observationTypeFk is missing and selectType is true', async () => {
|
||||||
|
vm.newNote.text = 'Test Note';
|
||||||
|
vm.newNote.observationTypeFk = null;
|
||||||
|
await wrapper.setProps({ selectType: true });
|
||||||
|
|
||||||
|
await vm.insert();
|
||||||
|
|
||||||
|
expect(postMock).not.toHaveBeenCalled();
|
||||||
|
expect(spyFetch).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is missing and selectType is false', async () => {
|
||||||
|
vm.newNote.text = "Test Note";
|
||||||
|
vm.newNote.observationTypeFk = null;
|
||||||
|
await wrapper.setProps({ selectType: false });
|
||||||
|
|
||||||
|
expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
|
||||||
|
|
||||||
|
await vm.insert();
|
||||||
|
|
||||||
|
expect(postMock).toHaveBeenCalledWith(vm.$props.url, expectedBody);
|
||||||
|
expect(spyFetch).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is setted and selectType is false', async () => {
|
||||||
|
vm.newNote.text = "Test Note";
|
||||||
|
vm.newNote.observationTypeFk = 1;
|
||||||
|
await wrapper.setProps({ selectType: false });
|
||||||
|
|
||||||
|
expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
|
||||||
|
|
||||||
|
await vm.insert();
|
||||||
|
|
||||||
|
expect(postMock).toHaveBeenCalledWith(vm.$props.url, expectedBody);
|
||||||
|
expect(spyFetch).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should call axios.post and vnPaginateRef.fetch when newNote is valid', async () => {
|
it('should call axios.post and vnPaginateRef.fetch when newNote is valid', async () => {
|
||||||
vm.newNote.text = 'Test Note';
|
vm.newNote.text = 'Test Note';
|
||||||
vm.newNote.observationTypeFk = 1;
|
vm.newNote.observationTypeFk = 1;
|
||||||
|
wrapper.setProps({ selectType: false });
|
||||||
|
|
||||||
const expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
|
expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
|
||||||
|
|
||||||
await vm.insert();
|
await vm.insert();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue