feat: refs #7079 created VnLocation front test
This commit is contained in:
parent
67315cc9e3
commit
bf41f338b7
|
@ -26,7 +26,7 @@ const locationProperties = [
|
||||||
(obj) => obj.country?.name,
|
(obj) => obj.country?.name,
|
||||||
];
|
];
|
||||||
|
|
||||||
const formatLocation = (obj, properties) => {
|
const formatLocation = (obj, properties = locationProperties) => {
|
||||||
const parts = properties.map((prop) => {
|
const parts = properties.map((prop) => {
|
||||||
if (typeof prop === 'string') {
|
if (typeof prop === 'string') {
|
||||||
return obj[prop];
|
return obj[prop];
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
import { createWrapper } from 'app/test/vitest/helper';
|
||||||
|
import VnLocation from 'components/common/VnLocation.vue';
|
||||||
|
import { vi, afterEach, expect, it, beforeEach, describe } from 'vitest';
|
||||||
|
|
||||||
|
function buildComponent(data) {
|
||||||
|
return createWrapper(VnLocation, {
|
||||||
|
global: {
|
||||||
|
stubs: [''],
|
||||||
|
props: {
|
||||||
|
location: data
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}).vm;
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('formatLocation', () => {
|
||||||
|
let locationBase;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
locationBase = {
|
||||||
|
postcode: '46680',
|
||||||
|
city: 'Algemesi',
|
||||||
|
province: { name: 'Valencia' },
|
||||||
|
country: { name: 'Spain' }
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the postcode, city, province and country', () => {
|
||||||
|
const location = { ...locationBase };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
const parts = vm.formatLocation(location);
|
||||||
|
expect(parts).toEqual('46680, Algemesi(Valencia), Spain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the postcode and country', () => {
|
||||||
|
const location = { ...locationBase, city: undefined };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
const parts = vm.formatLocation(location);
|
||||||
|
expect(parts).toEqual('46680, Spain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the city, province and country', () => {
|
||||||
|
const location = { ...locationBase, postcode: undefined };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
const parts = vm.formatLocation(location);
|
||||||
|
expect(parts).toEqual('Algemesi(Valencia), Spain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the country', () => {
|
||||||
|
const location = { ...locationBase, postcode: undefined, city: undefined, province: undefined };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
const parts = vm.formatLocation(location);
|
||||||
|
expect(parts).toEqual('Spain');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('showLabel', () => {
|
||||||
|
let locationBase;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
locationBase = {
|
||||||
|
code: '46680',
|
||||||
|
town: 'Algemesi',
|
||||||
|
province: 'Valencia',
|
||||||
|
country: 'Spain'
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show the label with postcode, city, province and country', () => {
|
||||||
|
const location = { ...locationBase };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
const label = vm.showLabel(location);
|
||||||
|
expect(label).toEqual('46680, Algemesi(Valencia), Spain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show the label with postcode and country', () => {
|
||||||
|
const location = { ...locationBase, town: undefined };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
const label = vm.showLabel(location);
|
||||||
|
expect(label).toEqual('46680, Spain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show the label with city, province and country', () => {
|
||||||
|
const location = { ...locationBase, code: undefined };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
const label = vm.showLabel(location);
|
||||||
|
expect(label).toEqual('Algemesi(Valencia), Spain');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show the label with country', () => {
|
||||||
|
const location = { ...locationBase, code: undefined, town: undefined, province: undefined };
|
||||||
|
const vm = buildComponent(location);
|
||||||
|
const label = vm.showLabel(location);
|
||||||
|
expect(label).toEqual('Spain');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue