Skip to content

Commit 159af91

Browse files
committed
test: ✅ Ajoute des CT pour la modale
1 parent 772323f commit 159af91

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { mount } from '@cypress/vue'
2+
import DsfrButton from '../DsfrButton/DsfrButton.vue'
3+
import DsfrModal from './DsfrModal.vue'
4+
import VIcon from '../../icons.js'
5+
import '../../main.css'
6+
7+
const ModalWrapper = {
8+
components: {
9+
DsfrModal,
10+
DsfrButton,
11+
VIcon,
12+
},
13+
14+
data () {
15+
return {
16+
opened: false,
17+
title: 'Titre de la modale',
18+
actions: [
19+
{
20+
label: 'Valider',
21+
onClick: () => this.close(),
22+
},
23+
{
24+
label: 'Annuler',
25+
secondary: true,
26+
onClick: () => this.close(),
27+
},
28+
],
29+
}
30+
},
31+
32+
template: `
33+
<div>
34+
<DsfrButton
35+
id="modal-opener"
36+
label="Ouvre la modale"
37+
@click="open()"
38+
ref="modalOrigin"
39+
/>
40+
<DsfrModal
41+
ref="modal"
42+
:opened="opened"
43+
:actions="actions"
44+
:title="title"
45+
:origin="$refs.modalOrigin"
46+
@close="close()"
47+
>
48+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas varius tortor nibh, sit amet tempor nibh finibus et. Aenean eu enim justo. Vestibulum aliquam hendrerit molestie. Mauris malesuada nisi sit amet augue accumsan tincidunt. Maecenas tincidunt, velit ac porttitor pulvinar, tortor eros facilisis libero, vitae commodo nunc quam et ligula. Ut nec ipsum sapien. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer id nisi nec nulla luctus lacinia non eu turpis. Etiam in ex imperdiet justo tincidunt egestas. Ut porttitor urna ac augue cursus tincidunt sit amet sed orci.</p>
49+
</DsfrModal>
50+
</div>
51+
`,
52+
53+
methods: {
54+
close () {
55+
this.opened = false
56+
},
57+
open () {
58+
this.opened = true
59+
},
60+
},
61+
}
62+
63+
describe('DsfrModal', () => {
64+
it('should mount a button, and a modal on click that traps focus and exits on ESC', () => {
65+
mount(ModalWrapper)
66+
.get('button')
67+
.contains('Ouvre la modale')
68+
.type('{enter}')
69+
70+
cy.get('.fr-link--close')
71+
.should('have.focus')
72+
73+
cy.get('.fr-link--close')
74+
.tab()
75+
76+
cy.get('.fr-link--close')
77+
.should('not.have.focus')
78+
79+
cy.tab().tab()
80+
81+
cy.get('.fr-link--close')
82+
.should('have.focus')
83+
84+
cy.tab().type('{esc}')
85+
86+
cy.get('button')
87+
.contains('Ouvre la modale')
88+
})
89+
})

0 commit comments

Comments
 (0)