Skip to content

Commit

Permalink
#48 first test for DaughterTable
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcellino-Palerme committed Jul 24, 2024
1 parent 334a367 commit ac41240
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/DaughterTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<!-- Redefine name of header of groupe -->
Expand Down
101 changes: 101 additions & 0 deletions test/component/DaughterTable.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/** SPDX-FileCopyrightText: 2024 Marcellino Palerme <[email protected]>
*
* 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();

});
});

0 comments on commit ac41240

Please sign in to comment.