Skip to content

Commit ccc86e3

Browse files
committed
test(DsfrHeader): ✅ use storybook play
and remove cypress tests
1 parent bc97084 commit ccc86e3

File tree

2 files changed

+60
-45
lines changed

2 files changed

+60
-45
lines changed

src/components/DsfrHeader/DsfrHeader.e2e.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/components/DsfrHeader/DsfrHeader.stories.ts

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { fn } from '@storybook/test'
1+
import { fn, expect, within } from '@storybook/test'
22

33
import DsfrHeader from './DsfrHeader.vue'
44
import DsfrNavigation from '../DsfrNavigation/DsfrNavigation.vue'
55
import type { DsfrLanguageSelectorElement } from '../DsfrLanguageSelector/DsfrLanguageSelector.types'
66

7+
const delay = (timeout = 100) =>
8+
new Promise((resolve) => setTimeout(resolve, timeout))
9+
710
/**
811
* [Voir quand l’utiliser sur la documentation du DSFR](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/en-tete)
912
*/
@@ -180,6 +183,23 @@ EnTeteSimple.args = {
180183
},
181184
],
182185
}
186+
EnTeteSimple.play = async ({ canvasElement }) => {
187+
const canvas = within(canvasElement)
188+
const links = canvas.getAllByRole('link')
189+
expect(links).toHaveLength(4)
190+
191+
const knownLinks = [
192+
{ name: '', href: EnTeteSimple.args.homeTo },
193+
...EnTeteSimple.args.quickLinks.map(({ to }) => ({ href: to })),
194+
]
195+
196+
let i = 0
197+
198+
for (const link of links) {
199+
expect(link).toHaveAttribute('href', knownLinks.at(i)?.href)
200+
i++
201+
}
202+
}
183203

184204
export const EnTeteAvecLogoOperateur = (args) => ({
185205
components: {
@@ -371,23 +391,23 @@ EnTeteAvecNavigation.args = {
371391
title: 'Nom de catégorie',
372392
links: [
373393
{
374-
text: 'Lien 1',
394+
text: 'Lien megamenu 1.1',
375395
to: '#',
376396
},
377397
{
378-
text: 'Lien 2',
398+
text: 'Lien megamenu 1.2',
379399
to: '#',
380400
},
381401
{
382-
text: 'Lien 3',
402+
text: 'Lien megamenu 1.3',
383403
to: '#',
384404
},
385405
{
386-
text: 'Lien 4',
406+
text: 'Lien megamenu 1.4',
387407
to: '#',
388408
},
389409
{
390-
text: 'Lien 5',
410+
text: 'Lien megamenu 1.5',
391411
to: '#',
392412
},
393413
],
@@ -396,23 +416,23 @@ EnTeteAvecNavigation.args = {
396416
title: 'Nom de catégorie',
397417
links: [
398418
{
399-
text: 'Lien 1',
419+
text: 'Lien megamenu 2.1',
400420
to: '#',
401421
},
402422
{
403-
text: 'Lien 2',
423+
text: 'Lien megamenu 2.2',
404424
to: '#',
405425
},
406426
{
407-
text: 'Lien 3',
427+
text: 'Lien megamenu 2.3',
408428
to: '#',
409429
},
410430
{
411-
text: 'Lien 4',
431+
text: 'Lien megamenu 2.4',
412432
to: '#',
413433
},
414434
{
415-
text: 'Lien 5',
435+
text: 'Lien megamenu 2.5',
416436
to: '#',
417437
},
418438
],
@@ -421,23 +441,23 @@ EnTeteAvecNavigation.args = {
421441
title: 'Nom de catégorie',
422442
links: [
423443
{
424-
text: 'Lien 1',
444+
text: 'Lien megamenu 3.1',
425445
to: '#',
426446
},
427447
{
428-
text: 'Lien 2',
448+
text: 'Lien megamenu 3.2',
429449
to: '#',
430450
},
431451
{
432-
text: 'Lien 3',
452+
text: 'Lien megamenu 3.3',
433453
to: '#',
434454
},
435455
{
436-
text: 'Lien 4',
456+
text: 'Lien megamenu 3.4',
437457
to: '#',
438458
},
439459
{
440-
text: 'Lien 5',
460+
text: 'Lien megamenu 3.5',
441461
to: '#',
442462
},
443463
],
@@ -446,6 +466,30 @@ EnTeteAvecNavigation.args = {
446466
},
447467
],
448468
}
469+
EnTeteAvecNavigation.play = async ({ canvasElement }) => {
470+
const canvas = within(canvasElement)
471+
const menuTitle = canvas.getByText(EnTeteAvecNavigation.args.navItems.at(1)?.title as string)
472+
const lien1 = menuTitle?.parentElement?.nextElementSibling
473+
474+
const megaMenuTitle = canvas.getByText(EnTeteAvecNavigation.args.navItems.at(2)?.title as string, { selector: 'button' })
475+
const megaMenuLien1 = canvas.getByText(EnTeteAvecNavigation.args.navItems.at(2)?.menus?.at(0)?.links?.at(0)?.text as string)
476+
477+
expect(lien1).not.toBeVisible()
478+
menuTitle.click()
479+
await delay(300)
480+
expect(lien1).toBeVisible()
481+
menuTitle.click()
482+
await delay(500)
483+
expect(lien1).not.toBeVisible()
484+
485+
expect(megaMenuLien1).not.toBeVisible()
486+
megaMenuTitle.click()
487+
await delay(500)
488+
expect(megaMenuLien1).toBeVisible()
489+
megaMenuTitle.click()
490+
await delay(500)
491+
expect(megaMenuLien1).not.toBeVisible()
492+
}
449493

450494
export const EnTeteAvecBadgeBeta = (args) => ({
451495
components: {

0 commit comments

Comments
 (0)