refactor: refs #7100 refactorized with methods
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jose Antonio Tubau 2024-12-30 07:40:25 +01:00
parent 788d7b09cf
commit 771ecf1cc6
1 changed files with 21 additions and 22 deletions

View File

@ -9,6 +9,16 @@ describe('VnNotes', () => {
let postMock;
let expectedBody;
function generateExpectedBody() {
expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
}
async function setTestParams(text, observationType, type){
vm.newNote.text = text;
vm.newNote.observationTypeFk = observationType;
wrapper.setProps({ selectType: type });
}
beforeAll(async () => {
vi.spyOn(axios, 'get').mockReturnValue({ data: [] });
@ -29,13 +39,12 @@ describe('VnNotes', () => {
afterEach(() => {
vi.clearAllMocks();
expectedBody = {};
});
describe('insert', () => {
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 setTestParams( null, null, true );
await vm.insert();
@ -44,9 +53,7 @@ describe('VnNotes', () => {
});
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 setTestParams( "", null, false );
await vm.insert();
@ -55,9 +62,7 @@ describe('VnNotes', () => {
});
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 setTestParams( "Test Note", null, true );
await vm.insert();
@ -66,11 +71,9 @@ describe('VnNotes', () => {
});
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 });
await setTestParams( "Test Note", null, false );
expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
generateExpectedBody();
await vm.insert();
@ -78,12 +81,10 @@ describe('VnNotes', () => {
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 });
it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is setted and selectType is false', async () => {
await setTestParams( "Test Note", 1, false );
expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
generateExpectedBody();
await vm.insert();
@ -92,11 +93,9 @@ describe('VnNotes', () => {
});
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 });
await setTestParams( "Test Note", 1, true );
expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
generateExpectedBody();
await vm.insert();