diff --git a/src/pages/Claim/Card/ClaimLines.vue b/src/pages/Claim/Card/ClaimLines.vue index f2814458b..8680ff922 100644 --- a/src/pages/Claim/Card/ClaimLines.vue +++ b/src/pages/Claim/Card/ClaimLines.vue @@ -16,7 +16,7 @@ import ClaimLinesImport from './ClaimLinesImport.vue'; const quasar = useQuasar(); const route = useRoute(); const { t } = useI18n(); -console.log(t); + const stateStore = useStateStore(); const arrayData = useArrayData('ClaimLines'); const store = arrayData.store; diff --git a/src/pages/Wagon/WagonCreate.vue b/src/pages/Wagon/WagonCreate.vue index 3f7824975..123e01d36 100644 --- a/src/pages/Wagon/WagonCreate.vue +++ b/src/pages/Wagon/WagonCreate.vue @@ -20,7 +20,7 @@ const $props = defineProps({ }); const entityId = computed(() => $props.id || route.params.id); -let wagonTypes; +let wagonTypes = []; let originalData = {}; const wagon = ref({}); const filteredWagonTypes = ref(wagonTypes); diff --git a/test/vitest/__tests__/components/common/CrudModel.spec.js b/test/vitest/__tests__/components/common/CrudModel.spec.js index 9c000e48d..3e0fe06f2 100644 --- a/test/vitest/__tests__/components/common/CrudModel.spec.js +++ b/test/vitest/__tests__/components/common/CrudModel.spec.js @@ -1,7 +1,6 @@ import { createWrapper, axios } from 'app/test/vitest/helper'; import CrudModel from 'components/CrudModel.vue'; -import { vi, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest'; -import { onMounted, ref } from 'vue'; +import { vi, afterEach, beforeAll, describe, expect, it } from 'vitest'; describe.only('CrudModel', () => { let vm; @@ -13,7 +12,7 @@ describe.only('CrudModel', () => { 'useState', 'arrayData', 'useStateStore', - 'useValidator', + 'vue-i18n', ], mocks: { fetch: vi.fn(), @@ -27,6 +26,7 @@ describe.only('CrudModel', () => { autoLoad: true, }, dataKey: 'crudModelKey', + model: 'crudModel', url: 'crudModelUrl', }, attrs: { @@ -44,15 +44,14 @@ describe.only('CrudModel', () => { describe('insert()', () => { it('should new element in list with index 0 if formData not has data', () => { - // vi.spyOn(axios, 'get').mockResolvedValue({ - // data: [ - // { id: 1, name: 'Tony Stark' }, - // { id: 2, name: 'Jessica Jones' }, - // { id: 3, name: 'Bruce Wayne' }, - // ], - // }); - // vm.state.set('crudModel', []); - vm.formData = ref([]); + vi.spyOn(axios, 'get').mockResolvedValue({ + data: [ + { id: 1, name: 'Tony Stark' }, + { id: 2, name: 'Jessica Jones' }, + { id: 3, name: 'Bruce Wayne' }, + ], + }); + vm.state.set('crudModel', []); vm.insert(); diff --git a/test/vitest/__tests__/pages/Claims/ClaimLines.spec.js b/test/vitest/__tests__/pages/Claims/ClaimLines.spec.js index e846eebf0..6dd6b89e6 100644 --- a/test/vitest/__tests__/pages/Claims/ClaimLines.spec.js +++ b/test/vitest/__tests__/pages/Claims/ClaimLines.spec.js @@ -14,9 +14,6 @@ describe('ClaimLines', () => { }, }, }).vm; - vi.mock('src/composables/useValidator', () => ({ - fetch: () => vi.fn(), - })); }); beforeEach(() => { diff --git a/test/vitest/__tests__/pages/Wagons/WagonCreate.spec.js b/test/vitest/__tests__/pages/Wagons/WagonCreate.spec.js index bc6b92639..f195c183f 100644 --- a/test/vitest/__tests__/pages/Wagons/WagonCreate.spec.js +++ b/test/vitest/__tests__/pages/Wagons/WagonCreate.spec.js @@ -7,9 +7,11 @@ describe('WagonCreate', () => { const entityId = 1; beforeAll(() => { - vmEdit = createWrapper(WagonCreate, {propsData: { + vmEdit = createWrapper(WagonCreate, { + propsData: { id: entityId, - }}).vm; + }, + }).vm; vmCreate = createWrapper(WagonCreate).vm; }); @@ -29,9 +31,7 @@ describe('WagonCreate', () => { await vmCreate.onSubmit(); - expect(axios.patch).toHaveBeenCalledWith( - `Wagons`, vmCreate.wagon - ); + expect(axios.patch).toHaveBeenCalledWith(`Wagons`, vmCreate.wagon); }); it('should update a wagon', async () => { @@ -46,9 +46,7 @@ describe('WagonCreate', () => { await vmEdit.onSubmit(); - expect(axios.patch).toHaveBeenCalledWith( - `Wagons`, vmEdit.wagon - ); + expect(axios.patch).toHaveBeenCalledWith(`Wagons`, vmEdit.wagon); }); }); @@ -88,16 +86,12 @@ describe('WagonCreate', () => { describe('fetch()', () => { it('should fetch data', async () => { - vi.spyOn(axios, 'get').mockResolvedValue({ data: true }); + vi.spyOn(axios, 'get').mockResolvedValue({ data: [] }); await vmEdit.fetch(); - expect(axios.get).toHaveBeenCalledWith( - `WagonTypes` - ); - expect(axios.get).toHaveBeenCalledWith( - `Wagons/${entityId}` - ); + expect(axios.get).toHaveBeenCalledWith(`WagonTypes`); + expect(axios.get).toHaveBeenCalledWith(`Wagons/${entityId}`); }); }); }); diff --git a/test/vitest/helper.js b/test/vitest/helper.js index 186f4ee3a..8f4dc3221 100644 --- a/test/vitest/helper.js +++ b/test/vitest/helper.js @@ -5,6 +5,7 @@ import { vi } from 'vitest'; import { i18n } from 'src/boot/i18n'; import { Notify, Dialog } from 'quasar'; import axios from 'axios'; +import * as useValidator from 'src/composables/useValidator'; installQuasarPlugin({ plugins: { @@ -34,6 +35,10 @@ vi.mock('vue-router', () => ({ }), })); +vi.spyOn(useValidator, 'useValidator').mockImplementation(() => { + return { validate: vi.fn(), fetch: vi.fn() }; +}); + class FormDataMock { append() { vi.fn(); @@ -79,7 +84,6 @@ export function createWrapper(component, options) { mountOptions.global.plugins = defaultOptions.global.plugins; } } - console.log(mountOptions); const wrapper = mount(component, mountOptions); const vm = wrapper.vm;