Skip to content

Commit

Permalink
fix(NcDialog): Ensure the dialog is correctly labelled by its name
Browse files Browse the repository at this point in the history
* Added `labelId` prop to NcModal to allow label modal without a name
* Pass the navigation id (the ID of the headline element of NcDialog) to `labelId`
* Added cypress tests

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Jul 4, 2024
1 parent 25872ad commit 9534883
Show file tree
Hide file tree
Showing 9 changed files with 374 additions and 107 deletions.
23 changes: 23 additions & 0 deletions cypress/component/NcDialog.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { mount } from 'cypress/vue'
import NcDialog from '../../src/components/NcDialog/NcDialog.vue'

describe('NcDialog', () => {
it('Dialog is correctly labelled', () => {
mount(NcDialog, {
props: {
show: true,
name: 'My dialog',
},
slots: {
default: 'Text',
},
})

cy.findByRole('dialog', { name: 'My dialog' }).should('exist')
})
})
82 changes: 82 additions & 0 deletions cypress/component/NcModal.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { Component } from 'vue'

import { mount } from 'cypress/vue'
import { h } from 'vue'
import NcModal from '../../src/components/NcModal/NcModal.vue'


describe('NcModal', () => {
it('Modal is labelled correctly if name is set', () => {
mount(NcModal, {
props: {
show: true,
name: 'My modal',
size: 'small',
},
slots: {
default: 'Text',
},
})

cy.findByRole('dialog', { name: 'My modal' }).should('exist')
})

it('Modal is labelled correctly if `labelId` is set', () => {
mount(NcModal, {
props: {
show: true,
size: 'small',
labelId: 'my-id',
},
slots: {
default: '<h2 id="my-id">Labelled dialog</h2>',
},
})

cy.findByRole('dialog', { name: 'Labelled dialog' }).should('exist')
})

it('Modal is labelled correctly if `labelId` and `name` are set', () => {
mount(NcModal, {
props: {
show: true,
size: 'small',
name: 'My modal',
labelId: 'my-id',
},
slots: {
default: '<h2 id="my-id">Real name</h2>',
},
})

cy.findByRole('dialog', { name: 'Real name' }).should('exist')
})

it('close button is visible when content is scrolled', () => {
mount(NcModal, {
props: {
show: true,
size: 'small',
name: 'Name',
},
slots: {
// Create two div as children, first is 100vh = overflows the content, second just gets some data attribute so we can scroll into view
default: {
render: () =>
h('div', [
h('div', { style: 'height: 100vh;' }),
h('div', { 'data-cy': 'bottom' }),
]),
} as Component,
},
})

cy.get('[data-cy="bottom"]').scrollIntoView()
cy.get('button.modal-container__close').should('be.visible')
})
})
34 changes: 0 additions & 34 deletions cypress/component/modal.cy.ts

This file was deleted.

2 changes: 2 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

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

import '@testing-library/cypress/add-commands'

addCompareSnapshotCommand()
3 changes: 2 additions & 1 deletion cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"rootDir": "..",
"types": [
"cypress",
"cypress-visual-regression"
"cypress-visual-regression",
"@testing-library/cypress"
]
}
}
Loading

0 comments on commit 9534883

Please sign in to comment.