Skip to content

Commit

Permalink
Merge pull request #5771 from nextcloud-libraries/fix/dialog-label
Browse files Browse the repository at this point in the history
fix(NcDialog): Ensure the dialog is correctly labelled by its name
  • Loading branch information
skjnldsv committed Jul 4, 2024
2 parents a671ba4 + 4ae8678 commit c42b6e1
Show file tree
Hide file tree
Showing 11 changed files with 356 additions and 43 deletions.
48 changes: 48 additions & 0 deletions cypress/component/NcAppSettingsDialog.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { mount } from 'cypress/vue2'
import NcAppSettingsDialog from '../../src/components/NcAppSettingsDialog/NcAppSettingsDialog.vue'
import NcAppSettingsSection from '../../src/components/NcAppSettingsSection/NcAppSettingsSection.vue'
import { defineComponent } from 'vue'

describe('NcAppSettingsDialog', () => {
it('Dialog is correctly labelled', () => {
mount(NcAppSettingsDialog, {
propsData: {
open: true,
name: 'My settings dialog',
},
slots: {
default: defineComponent({
render: (h) => h(NcAppSettingsSection, { props: { name: 'First section', id: 'first' } })
})
},
})

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

it('Dialog sections are correctly labelled', () => {
mount(NcAppSettingsDialog, {
propsData: {
open: true,
name: 'My settings dialog',
showNavigation: true,
},
slots: {
default: defineComponent({
render: (h) => h(NcAppSettingsSection, { props: { name: 'First section', id: 'first' } }, ['The section content'])
})
},
})

cy.findByRole('dialog', { name: 'My settings dialog' }).should('exist')
cy.findByRole('dialog', { name: 'My settings dialog' })
.findByRole('region', { name: 'First section' })
.should('exist')
.and('contain.text', 'The section content')
})
})
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/vue2'
import NcDialog from '../../src/components/NcDialog/NcDialog.vue'

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

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

import { mount } from 'cypress/vue2'
import NcModal from '../../src/components/NcModal/NcModal.vue'
import type { Component } from 'vue'

describe('NcModal', () => {
it('Modal is labelled correctly if name is set', () => {
mount(NcModal, {
propsData: {
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, {
propsData: {
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, {
propsData: {
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, {
propsData: {
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) =>
h('div', [
h('div', { style: 'height: 100vh;' }),
h('div', { attrs: { 'data-cy': 'bottom' } }),
]),
} as Component,
},
})

cy.get('[data-cy="bottom"]').scrollIntoView()
cy.get('button.modal-container__close').should('be.visible')
})
})
33 changes: 0 additions & 33 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 @@ -4,7 +4,8 @@
"compilerOptions": {
"types": [
"cypress",
"cypress-visual-regression"
"cypress-visual-regression",
"@testing-library/cypress"
]
}
}
Loading

0 comments on commit c42b6e1

Please sign in to comment.