From ac41240c0ace71c5ead0463d5ed556d2efc80ae9 Mon Sep 17 00:00:00 2001 From: "M.Palerme" Date: Wed, 24 Jul 2024 09:30:47 +0200 Subject: [PATCH] #48 first test for DaughterTable --- components/DaughterTable.vue | 1 + test/component/DaughterTable.test.ts | 101 +++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 test/component/DaughterTable.test.ts diff --git a/components/DaughterTable.vue b/components/DaughterTable.vue index d70e88d..ddddcb4 100644 --- a/components/DaughterTable.vue +++ b/components/DaughterTable.vue @@ -60,6 +60,7 @@ function delDaughterFile(idFile: string) { v-model:items="model" :headers="headers" :group-by="groupBy" + :no-data-text="t('message.noDaughterFile')" item-key="nameMeta" > diff --git a/test/component/DaughterTable.test.ts b/test/component/DaughterTable.test.ts new file mode 100644 index 0000000..d56cfd2 --- /dev/null +++ b/test/component/DaughterTable.test.ts @@ -0,0 +1,101 @@ +/** SPDX-FileCopyrightText: 2024 Marcellino Palerme + * + * SPDX-License-Identifier: MIT + * + * This file test the DaughterTable component +*/ + +import { mount, config } from '@vue/test-utils'; +import { expect, test, describe } from 'vitest'; +import { vuetify4Test } from '../extra/vuetify4Test'; +import { selectByText } from '../extra/selectByText'; +import DaughterTable from '@/components/DaughterTable.vue'; + +const vuetify = vuetify4Test(); + + +const globalConfig = { + global: { + plugins: [vuetify], + stubs: { + // Default layout is unactive + NuxtLayout: true, + }, + mocks:{ + // thx https://stackoverflow.com/a/73630072 + // Get key of translate + t: (tKey:string) => tKey + } +}} + + +function checkHearder(wrapper: any){ + expect(wrapper.text()).toContain('header.nameDaughterFile'); + expect(wrapper.text()).toContain('header.nameMeta'); + expect(wrapper.text()).toContain('header.area'); + expect(wrapper.text()).toContain('header.concentration'); +} + +describe('DaughterTable', () => { + + beforeEach(async () => { + // abort a tag without delete inside + config.global.renderStubDefaultSlot = true + }) + + afterEach(() => { + config.global.renderStubDefaultSlot = false; + }) + + test('DaughterTable empty', async () => { + const wrapper = mount(DaughterTable, { + ...globalConfig + }); + checkHearder(wrapper); + expect(wrapper.text()).toContain('message.noDaughterFile'); + }); + + test('DaughterTable with data', async () => { + const wrapper = mount(DaughterTable, { + ...globalConfig, + props: { + modelValue: [ + { + idFile: "1", + nameFile: 'name_one', + nameMeta: 'meta_one', + area: 17754, + concentration: 221584 + }, + { + idFile: "1", + nameFile: 'name_one', + nameMeta: 'meta_two', + area: 314, + concentration: 4788 + } + ] + } + }); + + + checkHearder(wrapper); + // Group of idFile1 is closed + expect(wrapper.text()).not.toContain('meta_one'); + expect(wrapper.text()).not.toContain('17754'); + expect(wrapper.text()).not.toContain('221584'); + expect(wrapper.text()).not.toContain('meta_one'); + expect(wrapper.text()).not.toContain('314'); + expect(wrapper.text()).not.toContain('4788'); + expect(wrapper.text()).toContain('name_one'); + // Check group of name1 in same column with delete button + const tBody = wrapper.find('tbody'); + + const tRow= tBody.findAll('tr'); + + expect(tRow.length).toBe(3); + expect(tRow[1].text()).toContain('name_one'); + expect(tRow[1].find("mdi-delete")).toBeTruthy(); + + }); +}); \ No newline at end of file