Skip to content

Commit c42b6e1

Browse files
authored
Merge pull request #5771 from nextcloud-libraries/fix/dialog-label
fix(NcDialog): Ensure the dialog is correctly labelled by its name
2 parents a671ba4 + 4ae8678 commit c42b6e1

File tree

11 files changed

+356
-43
lines changed

11 files changed

+356
-43
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { mount } from 'cypress/vue2'
7+
import NcAppSettingsDialog from '../../src/components/NcAppSettingsDialog/NcAppSettingsDialog.vue'
8+
import NcAppSettingsSection from '../../src/components/NcAppSettingsSection/NcAppSettingsSection.vue'
9+
import { defineComponent } from 'vue'
10+
11+
describe('NcAppSettingsDialog', () => {
12+
it('Dialog is correctly labelled', () => {
13+
mount(NcAppSettingsDialog, {
14+
propsData: {
15+
open: true,
16+
name: 'My settings dialog',
17+
},
18+
slots: {
19+
default: defineComponent({
20+
render: (h) => h(NcAppSettingsSection, { props: { name: 'First section', id: 'first' } })
21+
})
22+
},
23+
})
24+
25+
cy.findByRole('dialog', { name: 'My settings dialog' }).should('exist')
26+
})
27+
28+
it('Dialog sections are correctly labelled', () => {
29+
mount(NcAppSettingsDialog, {
30+
propsData: {
31+
open: true,
32+
name: 'My settings dialog',
33+
showNavigation: true,
34+
},
35+
slots: {
36+
default: defineComponent({
37+
render: (h) => h(NcAppSettingsSection, { props: { name: 'First section', id: 'first' } }, ['The section content'])
38+
})
39+
},
40+
})
41+
42+
cy.findByRole('dialog', { name: 'My settings dialog' }).should('exist')
43+
cy.findByRole('dialog', { name: 'My settings dialog' })
44+
.findByRole('region', { name: 'First section' })
45+
.should('exist')
46+
.and('contain.text', 'The section content')
47+
})
48+
})

cypress/component/NcDialog.cy.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { mount } from 'cypress/vue2'
7+
import NcDialog from '../../src/components/NcDialog/NcDialog.vue'
8+
9+
describe('NcDialog', () => {
10+
it('Dialog is correctly labelled', () => {
11+
mount(NcDialog, {
12+
propsData: {
13+
show: true,
14+
name: 'My dialog',
15+
},
16+
slots: {
17+
default: 'Text',
18+
},
19+
})
20+
21+
cy.findByRole('dialog', { name: 'My dialog' }).should('exist')
22+
})
23+
})

cypress/component/NcModal.cy.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { mount } from 'cypress/vue2'
7+
import NcModal from '../../src/components/NcModal/NcModal.vue'
8+
import type { Component } from 'vue'
9+
10+
describe('NcModal', () => {
11+
it('Modal is labelled correctly if name is set', () => {
12+
mount(NcModal, {
13+
propsData: {
14+
show: true,
15+
name: 'My modal',
16+
size: 'small',
17+
},
18+
slots: {
19+
default: 'Text',
20+
},
21+
})
22+
23+
cy.findByRole('dialog', { name: 'My modal' }).should('exist')
24+
})
25+
26+
it('Modal is labelled correctly if `labelId` is set', () => {
27+
mount(NcModal, {
28+
propsData: {
29+
show: true,
30+
size: 'small',
31+
labelId: 'my-id',
32+
},
33+
slots: {
34+
default: '<h2 id="my-id">Labelled dialog</h2>',
35+
},
36+
})
37+
38+
cy.findByRole('dialog', { name: 'Labelled dialog' }).should('exist')
39+
})
40+
41+
it('Modal is labelled correctly if `labelId` and `name` are set', () => {
42+
mount(NcModal, {
43+
propsData: {
44+
show: true,
45+
size: 'small',
46+
name: 'My modal',
47+
labelId: 'my-id',
48+
},
49+
slots: {
50+
default: '<h2 id="my-id">Real name</h2>',
51+
},
52+
})
53+
54+
cy.findByRole('dialog', { name: 'Real name' }).should('exist')
55+
})
56+
57+
it('close button is visible when content is scrolled', () => {
58+
mount(NcModal, {
59+
propsData: {
60+
show: true,
61+
size: 'small',
62+
name: 'Name',
63+
},
64+
slots: {
65+
// Create two div as children, first is 100vh = overflows the content, second just gets some data attribute so we can scroll into view
66+
default: {
67+
render: (h) =>
68+
h('div', [
69+
h('div', { style: 'height: 100vh;' }),
70+
h('div', { attrs: { 'data-cy': 'bottom' } }),
71+
]),
72+
} as Component,
73+
},
74+
})
75+
76+
cy.get('[data-cy="bottom"]').scrollIntoView()
77+
cy.get('button.modal-container__close').should('be.visible')
78+
})
79+
})

cypress/component/modal.cy.ts

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

cypress/support/commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55

66
import { addCompareSnapshotCommand } from 'cypress-visual-regression/dist/command'
77

8+
import '@testing-library/cypress/add-commands'
9+
810
addCompareSnapshotCommand()

cypress/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"compilerOptions": {
55
"types": [
66
"cypress",
7-
"cypress-visual-regression"
7+
"cypress-visual-regression",
8+
"@testing-library/cypress"
89
]
910
}
1011
}

0 commit comments

Comments
 (0)