0
0
Fork 0

revert: refs #8061 test #8061 updates

This commit is contained in:
Javier Segarra 2024-11-16 14:32:41 +01:00
parent 69a2eae542
commit e8ad185873
4 changed files with 0 additions and 224 deletions

View File

@ -1,41 +0,0 @@
// tests/CreateNewCityForm.spec.js
import { mount } from '@vue/test-utils';
import { describe, it, expect, vi } from 'vitest';
import CreateNewCityForm from 'src/components/CreateNewCityForm.vue';
import { Quasar } from 'quasar';
import { createWrapper, axios } from 'app/test/vitest/helper';
describe('CreateNewCityForm.vue', () => {
it('renders the form correctly', () => {
const wrapper = createWrapper(CreateNewCityForm);
expect(wrapper.find('form').exists()).toBe(true);
expect(wrapper.find('input[name="cityName"]').exists()).toBe(true);
expect(wrapper.find('select[name="province"]').exists()).toBe(true);
expect(wrapper.find('select[name="country"]').exists()).toBe(true);
});
it('emits onDataSaved when form is submitted', async () => {
const wrapper = createWrapper(CreateNewCityForm);
const form = wrapper.find('form');
await form.trigger('submit.prevent');
expect(wrapper.emitted().onDataSaved).toBeTruthy();
});
it('calls t function from useI18n', () => {
const wrapper = createWrapper(CreateNewCityForm);
expect(wrapper.vm.t).toBeDefined();
});
it('updates city data correctly', async () => {
const wrapper = createWrapper(CreateNewCityForm);
const cityNameInput = wrapper.find('input[name="cityName"]');
await cityNameInput.setValue('New City');
expect(wrapper.vm.cityName).toBe('New City');
});
});

View File

@ -1,56 +0,0 @@
// tests/CreateNewPostcodeForm.spec.js
import { mount } from '@vue/test-utils';
import { describe, it, expect, vi } from 'vitest';
import CreateNewPostcodeForm from 'src/components/CreateNewPostcodeForm.vue';
import { Quasar } from 'quasar';
import { createWrapper, axios } from 'app/test/vitest/helper';
describe('CreateNewPostcodeForm.vue', () => {
it('renders the form correctly', () => {
const wrapper = createWrapper(CreateNewPostcodeForm);
expect(wrapper.find('form').exists()).toBe(true);
expect(wrapper.find('input[label="Postcode"]').exists()).toBe(true);
expect(wrapper.find('select[label="City"]').exists()).toBe(true);
expect(wrapper.find('select[label="Province"]').exists()).toBe(true);
expect(wrapper.find('select[label="Country"]').exists()).toBe(true);
});
it('calls onDataSaved when form is submitted', async () => {
const wrapper = createWrapper(CreateNewPostcodeForm);
const formModelPopup = wrapper.findComponent({ name: 'FormModelPopup' });
await formModelPopup.vm.$emit('onDataSaved', { code: '12345' });
expect(wrapper.emitted().onDataSaved).toBeTruthy();
expect(wrapper.emitted().onDataSaved[0]).toEqual([{ code: '12345' }]);
});
it('updates town when a new city is created', async () => {
const wrapper = createWrapper(CreateNewPostcodeForm);
const createNewCityForm = wrapper.findComponent({ name: 'CreateNewCityForm' });
const newTown = { id: 1, name: 'New Town', provinceFk: 2 };
await createNewCityForm.vm.$emit('onDataSaved', newTown, {});
expect(wrapper.vm.town).toEqual(newTown);
});
it('fetches provinces and towns when country changes', async () => {
const wrapper = createWrapper(CreateNewPostcodeForm);
wrapper.vm.postcodeFormData.countryFk = 1;
await wrapper.vm.$nextTick();
expect(wrapper.vm.provincesFetchDataRef.fetch).toHaveBeenCalledWith({
where: { countryFk: 1 },
});
expect(wrapper.vm.townsFetchDataRef.fetch).toHaveBeenCalledWith({
where: {
provinceFk: {
inq: wrapper.vm.provincesOptions.map(({ id }) => id),
},
},
});
});
});

View File

@ -1,41 +0,0 @@
// tests/CreateNewProvinceForm.spec.js
import { mount } from '@vue/test-utils';
import { describe, it, expect, vi } from 'vitest';
import CreateNewProvinceForm from 'src/components/CreateNewProvinceForm.vue';
import { Quasar } from 'quasar';
import { createWrapper, axios } from 'app/test/vitest/helper';
describe('CreateNewProvinceForm.vue', () => {
it('renders the form correctly', () => {
const wrapper = createWrapper(CreateNewProvinceForm);
expect(wrapper.find('form').exists()).toBe(true);
expect(wrapper.findComponent({ name: 'VnInput' }).exists()).toBe(true);
expect(wrapper.findComponent({ name: 'VnSelect' }).exists()).toBe(true);
});
it('emits onDataSaved when form is submitted', async () => {
const wrapper = createWrapper(CreateNewProvinceForm);
const formModelPopup = wrapper.findComponent({ name: 'FormModelPopup' });
await formModelPopup.vm.$emit('onDataSaved', { name: 'New Province' });
expect(wrapper.emitted().onDataSaved).toBeTruthy();
expect(wrapper.emitted().onDataSaved[0]).toEqual([{ name: 'New Province' }]);
});
it('calls t function from useI18n', () => {
const wrapper = createWrapper(CreateNewProvinceForm);
expect(wrapper.vm.t).toBeDefined();
});
it('updates province data correctly', async () => {
const wrapper = createWrapper(CreateNewProvinceForm);
const provinceNameInput = wrapper.findComponent({ name: 'VnInput' });
await provinceNameInput.setValue('New Province');
expect(wrapper.vm.provinceFormData.name).toBe('New Province');
});
});

View File

@ -1,86 +0,0 @@
import { mount } from '@vue/test-utils';
import { describe, it, expect, vi } from 'vitest';
import VnSelectProvince from 'src/components/VnSelectProvince.vue';
import FetchData from 'components/FetchData.vue';
import VnSelectDialog from 'components/common/VnSelectDialog.vue';
import CreateNewProvinceForm from './CreateNewProvinceForm.vue';
import { createWrapper, axios } from 'app/test/vitest/helper';
// vi.mock('components/FetchData.vue', () => ({
// default: {
// name: 'FetchData',
// template: '<div><slot></slot></div>',
// },
// }));
// vi.mock('components/common/VnSelectDialog.vue', () => ({
// default: {
// name: 'VnSelectDialog',
// template: '<div><slot></slot><slot name="form"></slot></div>',
// },
// }));
// vi.mock('./CreateNewProvinceForm.vue', () => ({
// default: {
// name: 'CreateNewProvinceForm',
// template: '<div></div>',
// },
// }));
describe('VnSelectProvince.vue', () => {
it('renders correctly with default props', () => {
const wrapper = createWrapper(VnSelectProvince, {
props: {
countryFk: 1,
provinceSelected: 2,
},
});
expect(wrapper.exists()).toBe(true);
});
it('calls fetch method on countryFk change', async () => {
const fetchMock = vi.fn();
const wrapper = createWrapper(VnSelectProvince, {
props: {
countryFk: 1,
provinceSelected: 2,
},
global: {
mocks: {
provincesFetchDataRef: {
fetch: fetchMock,
},
},
},
});
await wrapper.setProps({ countryFk: 2 });
expect(fetchMock).toHaveBeenCalled();
});
it('emits onProvinceCreated event when a new province is created', async () => {
const wrapper = createWrapper(VnSelectProvince, {
props: {
countryFk: 1,
provinceSelected: 2,
},
});
await wrapper.vm.onProvinceCreated(null, { id: 3 });
expect(wrapper.emitted().onProvinceCreated).toBeTruthy();
expect(wrapper.emitted().onProvinceCreated[0]).toEqual([{ id: 3 }]);
});
it('updates provincesOptions when handleProvinces is called', async () => {
const wrapper = createWrapper(VnSelectProvince, {
props: {
countryFk: 1,
provinceSelected: 2,
},
});
const data = [{ id: 1, name: 'Province 1' }];
await wrapper.vm.handleProvinces(data);
expect(wrapper.vm.provincesOptions).toEqual(data);
});
});