From 7dd1c8140acaac6904f4ba845748f5b8d109c077 Mon Sep 17 00:00:00 2001 From: Maud Royer Date: Tue, 9 Apr 2024 11:20:34 +0200 Subject: [PATCH] fix: tests for MainHeader, Table and FeatureGroup Signed-off-by: Maud Royer --- src/components/Features/FeatureGroup.test.js | 4 ++-- src/components/Features/Table.test.js | 11 ++++++----- src/components/MainHeader.test.js | 16 +++++++++------- src/components/MainHeader.vue | 8 ++++++-- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/components/Features/FeatureGroup.test.js b/src/components/Features/FeatureGroup.test.js index c1e3ef32..846c81bd 100644 --- a/src/components/Features/FeatureGroup.test.js +++ b/src/components/Features/FeatureGroup.test.js @@ -40,11 +40,11 @@ describe("FeatureGroup", () => { expect(header.attributes()).not.toHaveProperty('hidden') // we have default columns - const headers = header.findAll('*') + const headers = header.findAll('th') expect(headers.at(0).text()).toEqual('') expect(headers.at(1).text()).toEqual('Nom') expect(headers.at(2).text()).toEqual('Certification') - expect(headers.at(3).text()).toEqual('') + expect(headers.at(3).text()).toEqual('Surface') // we should have a multi culture name within the 3rd cell expect(wrapper.find('#parcelle-2 .feature-precision').text()).toEqual('Multi-culture') diff --git a/src/components/Features/Table.test.js b/src/components/Features/Table.test.js index fb8daf3a..dbc70356 100644 --- a/src/components/Features/Table.test.js +++ b/src/components/Features/Table.test.js @@ -31,7 +31,7 @@ describe("Features Table", () => { test("features are listed as 3 groups of 2 and 1 and 2 features (one being multi-crops)", () => { const wrapper = mount(TableComponent) - expect(wrapper.find('tr.summary td:nth-child(2)').text()).toBe("4 parcelles") + expect(wrapper.find('tr.summary td:nth-child(2)').text()).toContain("4 parcelles") expect(wrapper.findAll('table tbody')).toHaveLength(3) expect(wrapper.find('#parcelle-1').attributes()).toHaveProperty('hidden', '') }) @@ -69,7 +69,7 @@ describe("Features Table", () => { await wrapper.find('.fr-tags-group--tags .tag--annotation_surveyed').trigger('click') await flushPromises() - expect(wrapper.find('tr.summary td:nth-child(2)').text()).toBe("1 parcelles") + expect(wrapper.find('tr.summary td:nth-child(2)').text()).toContain("1 parcelles") expect(wrapper.findAll('tr.parcelle')).toHaveLength(1) expect(featuresStore.all).toHaveLength(4) }) @@ -83,8 +83,8 @@ describe("Features Table", () => { await flushPromises() const groups = wrapper.findAll('table tbody') - expect(groups.at(0).find('th[scope="row"]').text()).toEqual('26108') - expect(groups.at(1).find('th[scope="row"]').text()).toEqual('26113') + expect(groups.at(0).find('th[scope="row"]').text()).toContain('26108') + expect(groups.at(1).find('th[scope="row"]').text()).toContain('26113') }) test("we select a feature and its unfolds the group", async () => { @@ -133,12 +133,13 @@ describe("Features Table", () => { await wrapper.find('.group-header').trigger('click') await wrapper.find('#parcelle-3 .show-actions').trigger('click') - await wrapper.find('.fr-icon-delete-line').trigger('click') + await wrapper.find('#parcelle-3 .menu-container .fr-icon-delete-line').trigger('click') // we trigger the deletion axios.__createMock.delete.mockResolvedValueOnce(record) const modal = wrapper.getComponent(DeleteFeatureModal) + expect(modal.text()).toContain("parcelle 3") await modal.find('#deletion-reason').setValue(DeletionReasonsCode.OTHER) await modal.find('#deletion-details').setValue('Parce que') await modal.find('button.fr-icon-delete-line').trigger('click') diff --git a/src/components/MainHeader.test.js b/src/components/MainHeader.test.js index 758d6f20..f8bb175c 100644 --- a/src/components/MainHeader.test.js +++ b/src/components/MainHeader.test.js @@ -21,8 +21,8 @@ describe("MainHeader", () => { const wrapper = mount(MainHeader) expect(wrapper.find('.tool-username').exists()).toEqual(false) - expect(wrapper.find('.fr-header__tools').text()).toEqual('Connexion À propos') - expect(wrapper.find('[role="navigation"]').text()).toEqual('Grand public Agriculteur·ice') + expect(wrapper.find('.fr-header__tools').text()).toEqual('À propos Aide Connexion') + expect(wrapper.find('[role="navigation"]').text()).toEqual('Aide À propos de CartoBio Connexion') }) test("with a warning header", async () => { @@ -51,18 +51,18 @@ describe("MainHeader", () => { }) expect(wrapper.find('.tool-username').exists()).toEqual(false) - expect(wrapper.find('.fr-header__tools').text()).toEqual('Connexion À propos') - expect(wrapper.find('[role="navigation"] a[target="_blank"]').exists()).toEqual(false) + expect(wrapper.find('.fr-header__tools').text()).toEqual('À propos Aide Connexion') }) test("as a certification body", async () => { const wrapper = mount(MainHeader) user.isLogged = true + user.user = { nom: 'Nom' } user.roles = [ROLES.OC_AUDIT] await flushPromises() expect(wrapper.find('.tool-username a').classes('fr-icon-medal-fill')).toEqual(true) - expect(wrapper.find('[role="navigation"]').text()).toEqual('Exploitations Centre d\'aide Déconnexion') + expect(wrapper.find('[role="navigation"]').text()).toEqual('Nom Aide À propos de CartoBio Déconnexion') expect(wrapper.find('[role="navigation"] a').attributes('href')).toEqual('/certification/exploitations') expect(wrapper.find('[role="navigation"] a[target="_blank"]').attributes('href')).toEqual('https://docs-cartobio.agencebio.org/organisme-certification') @@ -73,11 +73,12 @@ describe("MainHeader", () => { test("as a farmer", async () => { const wrapper = mount(MainHeader) user.isLogged = true + user.user = { nom: 'Nom' } user.roles = [ROLES.OPERATEUR] await flushPromises() expect(wrapper.find('.tool-username a').classes('fr-icon-plant-fill')).toEqual(true) - expect(wrapper.find('[role="navigation"]').text()).toEqual('Exploitations Centre d\'aide Déconnexion') + expect(wrapper.find('[role="navigation"]').text()).toEqual('Nom Aide À propos de CartoBio Déconnexion') expect(wrapper.find('[role="navigation"] a').attributes('href')).toEqual('/exploitations') expect(wrapper.find('[role="navigation"] a[target="_blank"]').attributes('href')).toEqual('https://docs-cartobio.agencebio.org/agriculteurs.trices') }) @@ -85,10 +86,11 @@ describe("MainHeader", () => { test("as unknown role", async () => { const wrapper = mount(MainHeader) user.isLogged = true + user.user = { nom: 'Nom' } user.roles = [] await flushPromises() expect(wrapper.find('.tool-username a').classes('fr-icon-account-circle-fill')).toEqual(true) - expect(wrapper.find('[role="navigation"]').text()).toEqual('Exploitations Centre d\'aide Déconnexion') + expect(wrapper.find('[role="navigation"]').text()).toEqual('Nom Aide À propos de CartoBio Déconnexion') }) }) diff --git a/src/components/MainHeader.vue b/src/components/MainHeader.vue index c369d1cf..f162bd9d 100644 --- a/src/components/MainHeader.vue +++ b/src/components/MainHeader.vue @@ -100,10 +100,14 @@
  • - Aide + + Aide +
  • - À propos de CartoBio + + À propos de CartoBio +