Skip to content

Commit

Permalink
test(NcCheckboxRadioSwitch): Add cypress test to ensure attributes, c…
Browse files Browse the repository at this point in the history
…lass and style are correctly set

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Jul 4, 2024
1 parent 74dc419 commit 083cd8f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Files: package.json package-lock.json .github/pull_request_template.md
Copyright: Nextcloud GmbH and Nextcloud contributors
License: AGPL-3.0-or-later

Files: styleguide/assets/icons.css styleguide/assets/server.css cypress/snapshots/* tests/unit/functions/usernameToColor/__snapshots__/usernameToColor.spec.js.snap
Files: styleguide/assets/icons.css cypress/snapshots/* tests/unit/functions/usernameToColor/__snapshots__/usernameToColor.spec.js.snap
Copyright: Nextcloud GmbH and Nextcloud contributors
License: AGPL-3.0-or-later

Expand Down
19 changes: 19 additions & 0 deletions cypress/commands.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { mount } from '@cypress/vue2'

// Augment the Cypress namespace to include type definitions for
// your custom commands
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
mount: typeof mount
}
}
}

export {}
32 changes: 32 additions & 0 deletions cypress/component/NcCheckboxRadioSwitch.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

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

describe('NcCheckboxRadioSwitch', () => {
it('Sets attributes correctly', () => {
cy.mount({
render: (h) => h(NcCheckboxRadioSwitch, {
// TODO: With Vue3 move class and style to attrs
class: 'my-class',
style: 'background: red;',
attrs: {
'aria-describedby': 'unique-id',
'data-my-attribute': 'yes',
},
}, ['My checkbox']),
}).then(({ wrapper }) => {
// Class and style belong the wrapper
expect(wrapper.classes('my-class')).to.be.true
// expect(wrapper.attributes('style')).to.equal('background: red;')
// Custom data attributes too
expect(wrapper.attributes('data-my-attribute')).to.equal('yes')
// real HTML attributes are passed to the real checkbox
expect(wrapper.attributes('aria-describedby')).to.be.undefined
})

cy.findByRole('checkbox').should('have.attr', 'aria-describedby', 'unique-id')
})
})
5 changes: 5 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

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

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

addCompareSnapshotCommand()

// Example use:
// cy.mount(MyComponent)
Cypress.Commands.add('mount', mount)
19 changes: 0 additions & 19 deletions cypress/support/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,3 @@ import '../../styleguide/assets/icons.css'

// cypress commands
import './commands'
import { mount } from '@cypress/vue2'

// 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)

0 comments on commit 083cd8f

Please sign in to comment.