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