refactor: refs #7100 refactorized with methods
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
788d7b09cf
commit
771ecf1cc6
|
@ -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();
|
||||
|
||||
|
@ -79,11 +82,9 @@ describe('VnNotes', () => {
|
|||
});
|
||||
|
||||
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 });
|
||||
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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue