Skip to content

Commit

Permalink
fix: tests for MainHeader, Table and FeatureGroup
Browse files Browse the repository at this point in the history
Signed-off-by: Maud Royer <hello@maudroyer.fr>
  • Loading branch information
jillro committed Apr 9, 2024
1 parent bb16683 commit 7dd1c81
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/components/Features/FeatureGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
11 changes: 6 additions & 5 deletions src/components/Features/Table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
})
Expand Down Expand Up @@ -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)
})
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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')
Expand Down
16 changes: 9 additions & 7 deletions src/components/MainHeader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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')

Expand All @@ -73,22 +73,24 @@ 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')
})

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')
})
})
8 changes: 6 additions & 2 deletions src/components/MainHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@
</router-link>
</li>
<li class="fr-nav__item">
<a :href="documentationPage" target="_blank" rel="noopener" class="fr-nav__link fr-btn--icon-left fr-icon-questionnaire-fill">Aide</a>
<a :href="documentationPage" target="_blank" rel="noopener" class="fr-nav__link fr-btn--icon-left fr-icon-questionnaire-fill">
Aide
</a>
</li>
<li class="fr-nav__item">
<router-link to="/projet" class="fr-nav__link">À propos de CartoBio</router-link>
<router-link to="/projet" class="fr-nav__link">
À propos de CartoBio
</router-link>
</li>
<li class="fr-nav__item fr-hidden-lg">
<router-link v-if="isLogged" to="/logout" custom v-slot="{ href }">
Expand Down

0 comments on commit 7dd1c81

Please sign in to comment.