From 7f25059206213e4795d39b663cff4d8318dacd9e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 10 Nov 2023 10:03:01 +0100 Subject: [PATCH] refs #6416 test: create spec file for each Vn --- .../__tests__/components/common/VnBtn.js | 75 +++++++++++++++++++ .../__tests__/components/common/VnCard.js | 75 +++++++++++++++++++ .../components/common/VnCardSection.js | 75 +++++++++++++++++++ .../__tests__/components/common/VnChip.js | 75 +++++++++++++++++++ .../__tests__/components/common/VnTable.js | 75 +++++++++++++++++++ 5 files changed, 375 insertions(+) create mode 100644 test/vitest/__tests__/components/common/VnBtn.js create mode 100644 test/vitest/__tests__/components/common/VnCard.js create mode 100644 test/vitest/__tests__/components/common/VnCardSection.js create mode 100644 test/vitest/__tests__/components/common/VnChip.js create mode 100644 test/vitest/__tests__/components/common/VnTable.js diff --git a/test/vitest/__tests__/components/common/VnBtn.js b/test/vitest/__tests__/components/common/VnBtn.js new file mode 100644 index 000000000..c6dc1cd9e --- /dev/null +++ b/test/vitest/__tests__/components/common/VnBtn.js @@ -0,0 +1,75 @@ +import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; +import { createWrapper } from 'app/test/vitest/helper'; +import VnBtn from 'src/components/common/VnBtn.vue'; + +describe('VnBtn', () => { + let vm; + beforeAll(() => { + vm = createWrapper(VnBtn, { + global: { + stubs: ['FetchData', 'VnPaginate'], + mocks: { + fetch: vi.fn(), + }, + }, + propsData: { + model: 'Claim', + }, + }).vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('formatValue()', () => { + it('should return Yes if has a true boolean', async () => { + const result = vm.formatValue(true); + + expect(result).toEqual('Yes'); + }); + it('should return No if has a true boolean', async () => { + const result = vm.formatValue(false); + + expect(result).toEqual('No'); + }); + it('should return Nothing if has no params', async () => { + const result = vm.formatValue(); + + expect(result).toEqual('Nothing'); + }); + it('should return a string from a string value', async () => { + const result = vm.formatValue('Something'); + + expect(result).toEqual(`"Something"`); + }); + it('should call to format a date', async () => { + vi.mock('src/filters', () => ({ + toDate: () => { + return 'Date formatted'; + }, + })); + + const result = vm.formatValue('01-01-1970'); + expect(result).toEqual('Date formatted'); + }); + }); + + describe('actionColor()', () => { + it('should return positive if insert', async () => { + const result = vm.actionColor('insert'); + + expect(result).toEqual('positive'); + }); + it('should return positive if update', async () => { + const result = vm.actionColor('update'); + + expect(result).toEqual('positive'); + }); + it('should return negative if delete', async () => { + const result = vm.actionColor('delete'); + + expect(result).toEqual('negative'); + }); + }); +}); diff --git a/test/vitest/__tests__/components/common/VnCard.js b/test/vitest/__tests__/components/common/VnCard.js new file mode 100644 index 000000000..ba9221d20 --- /dev/null +++ b/test/vitest/__tests__/components/common/VnCard.js @@ -0,0 +1,75 @@ +import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; +import { createWrapper } from 'app/test/vitest/helper'; +import VnCard from 'src/components/common/VnCard.vue'; + +describe('VnCard', () => { + let vm; + beforeAll(() => { + vm = createWrapper(VnCard, { + global: { + stubs: ['FetchData', 'VnPaginate'], + mocks: { + fetch: vi.fn(), + }, + }, + propsData: { + model: 'Claim', + }, + }).vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('formatValue()', () => { + it('should return Yes if has a true boolean', async () => { + const result = vm.formatValue(true); + + expect(result).toEqual('Yes'); + }); + it('should return No if has a true boolean', async () => { + const result = vm.formatValue(false); + + expect(result).toEqual('No'); + }); + it('should return Nothing if has no params', async () => { + const result = vm.formatValue(); + + expect(result).toEqual('Nothing'); + }); + it('should return a string from a string value', async () => { + const result = vm.formatValue('Something'); + + expect(result).toEqual(`"Something"`); + }); + it('should call to format a date', async () => { + vi.mock('src/filters', () => ({ + toDate: () => { + return 'Date formatted'; + }, + })); + + const result = vm.formatValue('01-01-1970'); + expect(result).toEqual('Date formatted'); + }); + }); + + describe('actionColor()', () => { + it('should return positive if insert', async () => { + const result = vm.actionColor('insert'); + + expect(result).toEqual('positive'); + }); + it('should return positive if update', async () => { + const result = vm.actionColor('update'); + + expect(result).toEqual('positive'); + }); + it('should return negative if delete', async () => { + const result = vm.actionColor('delete'); + + expect(result).toEqual('negative'); + }); + }); +}); diff --git a/test/vitest/__tests__/components/common/VnCardSection.js b/test/vitest/__tests__/components/common/VnCardSection.js new file mode 100644 index 000000000..5c906a3d8 --- /dev/null +++ b/test/vitest/__tests__/components/common/VnCardSection.js @@ -0,0 +1,75 @@ +import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; +import { createWrapper } from 'app/test/vitest/helper'; +import VnCardSection from 'src/components/common/VnCardSection.vue'; + +describe('VnCardSection', () => { + let vm; + beforeAll(() => { + vm = createWrapper(VnCardSection, { + global: { + stubs: ['FetchData', 'VnPaginate'], + mocks: { + fetch: vi.fn(), + }, + }, + propsData: { + model: 'Claim', + }, + }).vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('formatValue()', () => { + it('should return Yes if has a true boolean', async () => { + const result = vm.formatValue(true); + + expect(result).toEqual('Yes'); + }); + it('should return No if has a true boolean', async () => { + const result = vm.formatValue(false); + + expect(result).toEqual('No'); + }); + it('should return Nothing if has no params', async () => { + const result = vm.formatValue(); + + expect(result).toEqual('Nothing'); + }); + it('should return a string from a string value', async () => { + const result = vm.formatValue('Something'); + + expect(result).toEqual(`"Something"`); + }); + it('should call to format a date', async () => { + vi.mock('src/filters', () => ({ + toDate: () => { + return 'Date formatted'; + }, + })); + + const result = vm.formatValue('01-01-1970'); + expect(result).toEqual('Date formatted'); + }); + }); + + describe('actionColor()', () => { + it('should return positive if insert', async () => { + const result = vm.actionColor('insert'); + + expect(result).toEqual('positive'); + }); + it('should return positive if update', async () => { + const result = vm.actionColor('update'); + + expect(result).toEqual('positive'); + }); + it('should return negative if delete', async () => { + const result = vm.actionColor('delete'); + + expect(result).toEqual('negative'); + }); + }); +}); diff --git a/test/vitest/__tests__/components/common/VnChip.js b/test/vitest/__tests__/components/common/VnChip.js new file mode 100644 index 000000000..f8901dd10 --- /dev/null +++ b/test/vitest/__tests__/components/common/VnChip.js @@ -0,0 +1,75 @@ +import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; +import { createWrapper } from 'app/test/vitest/helper'; +import VnChip from 'src/components/common/VnChip.vue'; + +describe('VnChip', () => { + let vm; + beforeAll(() => { + vm = createWrapper(VnChip, { + global: { + stubs: ['FetchData', 'VnPaginate'], + mocks: { + fetch: vi.fn(), + }, + }, + propsData: { + model: 'Claim', + }, + }).vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('formatValue()', () => { + it('should return Yes if has a true boolean', async () => { + const result = vm.formatValue(true); + + expect(result).toEqual('Yes'); + }); + it('should return No if has a true boolean', async () => { + const result = vm.formatValue(false); + + expect(result).toEqual('No'); + }); + it('should return Nothing if has no params', async () => { + const result = vm.formatValue(); + + expect(result).toEqual('Nothing'); + }); + it('should return a string from a string value', async () => { + const result = vm.formatValue('Something'); + + expect(result).toEqual(`"Something"`); + }); + it('should call to format a date', async () => { + vi.mock('src/filters', () => ({ + toDate: () => { + return 'Date formatted'; + }, + })); + + const result = vm.formatValue('01-01-1970'); + expect(result).toEqual('Date formatted'); + }); + }); + + describe('actionColor()', () => { + it('should return positive if insert', async () => { + const result = vm.actionColor('insert'); + + expect(result).toEqual('positive'); + }); + it('should return positive if update', async () => { + const result = vm.actionColor('update'); + + expect(result).toEqual('positive'); + }); + it('should return negative if delete', async () => { + const result = vm.actionColor('delete'); + + expect(result).toEqual('negative'); + }); + }); +}); diff --git a/test/vitest/__tests__/components/common/VnTable.js b/test/vitest/__tests__/components/common/VnTable.js new file mode 100644 index 000000000..9ebc78a04 --- /dev/null +++ b/test/vitest/__tests__/components/common/VnTable.js @@ -0,0 +1,75 @@ +import { vi, describe, expect, it, beforeAll, afterEach } from 'vitest'; +import { createWrapper } from 'app/test/vitest/helper'; +import VnTable from 'src/components/common/VnTable.vue'; + +describe('VnTable', () => { + let vm; + beforeAll(() => { + vm = createWrapper(VnTable, { + global: { + stubs: ['FetchData', 'VnPaginate'], + mocks: { + fetch: vi.fn(), + }, + }, + propsData: { + model: 'Claim', + }, + }).vm; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + describe('formatValue()', () => { + it('should return Yes if has a true boolean', async () => { + const result = vm.formatValue(true); + + expect(result).toEqual('Yes'); + }); + it('should return No if has a true boolean', async () => { + const result = vm.formatValue(false); + + expect(result).toEqual('No'); + }); + it('should return Nothing if has no params', async () => { + const result = vm.formatValue(); + + expect(result).toEqual('Nothing'); + }); + it('should return a string from a string value', async () => { + const result = vm.formatValue('Something'); + + expect(result).toEqual(`"Something"`); + }); + it('should call to format a date', async () => { + vi.mock('src/filters', () => ({ + toDate: () => { + return 'Date formatted'; + }, + })); + + const result = vm.formatValue('01-01-1970'); + expect(result).toEqual('Date formatted'); + }); + }); + + describe('actionColor()', () => { + it('should return positive if insert', async () => { + const result = vm.actionColor('insert'); + + expect(result).toEqual('positive'); + }); + it('should return positive if update', async () => { + const result = vm.actionColor('update'); + + expect(result).toEqual('positive'); + }); + it('should return negative if delete', async () => { + const result = vm.actionColor('delete'); + + expect(result).toEqual('negative'); + }); + }); +});