Skip to content

Commit

Permalink
Merge pull request #5778 from nextcloud-libraries/backport/5771/next
Browse files Browse the repository at this point in the history
[next] fix(NcDialog): Ensure the dialog is correctly labelled by its name
  • Loading branch information
susnux authored Jul 9, 2024
2 parents 9949c44 + 9141727 commit 74289da
Show file tree
Hide file tree
Showing 18 changed files with 526 additions and 161 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 { defineComponent, h } from 'vue'

import NcAppSettingsDialog from '../../src/components/NcAppSettingsDialog/NcAppSettingsDialog.vue'
import NcAppSettingsSection from '../../src/components/NcAppSettingsSection/NcAppSettingsSection.vue'

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

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

it('Dialog sections are correctly labelled', () => {
cy.mount(NcAppSettingsDialog, {
propsData: {
open: true,
name: 'My settings dialog',
showNavigation: true,
},
slots: {
default: defineComponent({
render: () => 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')
})
})
22 changes: 22 additions & 0 deletions cypress/component/NcDialog.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import NcDialog from '../../src/components/NcDialog/NcDialog.vue'

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

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

import type { Component } from 'vue'

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


describe('NcModal', () => {
it('Modal is labelled correctly if name is set', () => {
cy.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', () => {
cy.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', () => {
cy.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', () => {
cy.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.

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

import { addCompareSnapshotCommand } from 'cypress-visual-regression/dist/command'
import { mount } from 'cypress/vue'
import '@testing-library/cypress/add-commands'

addCompareSnapshotCommand()

// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
mount: typeof mount
}
}
}

// Example use:
// cy.mount(MyComponent)
Cypress.Commands.add('mount', mount)
23 changes: 3 additions & 20 deletions cypress/support/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

// register commands
import './commands.ts'

// setup styles
import '../../styleguide/assets/default.css'
import '../../styleguide/assets/additional.css'
import '../../styleguide/assets/icons.css'

import './commands.ts'
import { mount } from '@cypress/vue'

// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
mount: typeof mount
}
}
}

// Example use:
// cy.mount(MyComponent)
Cypress.Commands.add('mount', mount)
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 74289da

Please sign in to comment.