Skip to content

Commit 083cd8f

Browse files
committed
test(NcCheckboxRadioSwitch): Add cypress test to ensure attributes, class and style are correctly set
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 74dc419 commit 083cd8f

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

.reuse/dep5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Files: package.json package-lock.json .github/pull_request_template.md
77
Copyright: Nextcloud GmbH and Nextcloud contributors
88
License: AGPL-3.0-or-later
99

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

cypress/commands.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import type { mount } from '@cypress/vue2'
7+
8+
// Augment the Cypress namespace to include type definitions for
9+
// your custom commands
10+
declare global {
11+
// eslint-disable-next-line @typescript-eslint/no-namespace
12+
namespace Cypress {
13+
interface Chainable {
14+
mount: typeof mount
15+
}
16+
}
17+
}
18+
19+
export {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import NcCheckboxRadioSwitch from '../../src/components/NcCheckboxRadioSwitch/NcCheckboxRadioSwitch.vue'
7+
8+
describe('NcCheckboxRadioSwitch', () => {
9+
it('Sets attributes correctly', () => {
10+
cy.mount({
11+
render: (h) => h(NcCheckboxRadioSwitch, {
12+
// TODO: With Vue3 move class and style to attrs
13+
class: 'my-class',
14+
style: 'background: red;',
15+
attrs: {
16+
'aria-describedby': 'unique-id',
17+
'data-my-attribute': 'yes',
18+
},
19+
}, ['My checkbox']),
20+
}).then(({ wrapper }) => {
21+
// Class and style belong the wrapper
22+
expect(wrapper.classes('my-class')).to.be.true
23+
// expect(wrapper.attributes('style')).to.equal('background: red;')
24+
// Custom data attributes too
25+
expect(wrapper.attributes('data-my-attribute')).to.equal('yes')
26+
// real HTML attributes are passed to the real checkbox
27+
expect(wrapper.attributes('aria-describedby')).to.be.undefined
28+
})
29+
30+
cy.findByRole('checkbox').should('have.attr', 'aria-describedby', 'unique-id')
31+
})
32+
})

cypress/support/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

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

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

1011
addCompareSnapshotCommand()
12+
13+
// Example use:
14+
// cy.mount(MyComponent)
15+
Cypress.Commands.add('mount', mount)

cypress/support/component.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,3 @@ import '../../styleguide/assets/icons.css'
1010

1111
// cypress commands
1212
import './commands'
13-
import { mount } from '@cypress/vue2'
14-
15-
// Augment the Cypress namespace to include type definitions for
16-
// your custom command.
17-
// Alternatively, can be defined in cypress/support/component.d.ts
18-
// with a <reference path="./component" /> at the top of your spec.
19-
20-
declare global {
21-
// eslint-disable-next-line @typescript-eslint/no-namespace
22-
namespace Cypress {
23-
interface Chainable {
24-
mount: typeof mount
25-
}
26-
}
27-
}
28-
29-
// Example use:
30-
// cy.mount(MyComponent)
31-
Cypress.Commands.add('mount', mount)

0 commit comments

Comments
 (0)