Skip to content

Commit 55abf8e

Browse files
committed
test: Add cypress integration tests
1 parent 1f88f1b commit 55abf8e

File tree

6 files changed

+175
-3
lines changed

6 files changed

+175
-3
lines changed

cypress.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"baseUrl": "http://localhost:8080",
33
"fixturesFolder": "tests/e2e/fixtures",
44
"screenshotsFolder": "tests/e2e/screenshots",
5-
"integrationFolder": "tests/e2e/specs",
5+
"integrationFolder": "tests/e2e/integration",
66
"fileServerFolder": "demo",
77
"pluginsFile": false,
8-
"supportFile": false
8+
"supportFile": "tests/e2e/support"
99
}

tests/e2e/integration/aria.spec.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,71 @@
1-
describe('Aria test', () => {
1+
describe('Aria label', () => {
22
before(() => {
33
cy.visit('/')
44
})
5+
6+
it('Button color mode must be visible', () => {
7+
cy.getColorModeButtonIsVisible()
8+
})
9+
10+
it('Current color mode must be "light"', () => {
11+
cy.getCurrentColorMode()
12+
.should('contain', 'light')
13+
})
14+
15+
it('Must have the aria-label attribute and contain text for the "dark" color mode', () => {
16+
cy.getColorModeButton()
17+
.should('have.attr', 'aria-label', 'toggle to dark mode color')
18+
})
19+
20+
it('Button color mode must be clicked', () => {
21+
cy.toggleColorMode()
22+
})
23+
24+
it('Current color mode must be "dark"', () => {
25+
cy.getCurrentColorMode()
26+
.should('contain', 'dark')
27+
})
28+
29+
it('Must have the aria-label attribute and contain text for the "system" color mode', () => {
30+
cy.getColorModeButton()
31+
.should('have.attr', 'aria-label', 'toggle to system mode color')
32+
})
33+
})
34+
35+
describe('Aria live regions', () => {
36+
before(() => {
37+
cy.visit('/')
38+
})
39+
40+
it('Button color mode must be visible', () => {
41+
cy.getColorModeButtonIsVisible()
42+
})
43+
44+
it('Current color mode must be "light"', () => {
45+
cy.getCurrentColorMode()
46+
.should('contain', 'light')
47+
})
48+
49+
it('There must be an element with aria-live', () => {
50+
cy.getColorModeButton()
51+
.get('span[aria-live]')
52+
})
53+
54+
it('The element with aria-live must contain "light" in the announced text', () => {
55+
cy.getColorModeButton()
56+
.get('span[aria-live]')
57+
.invoke('text')
58+
.should('eq', 'light color mode is enabled')
59+
})
60+
61+
it('Button color mode must be clicked', () => {
62+
cy.toggleColorMode()
63+
})
64+
65+
it('The element with aria-live must contain "dark" in the announced text', () => {
66+
cy.getColorModeButton()
67+
.get('span[aria-live]')
68+
.invoke('text')
69+
.should('eq', 'dark color mode is enabled')
70+
})
571
})

tests/e2e/integration/meta-theme-color.spec.js

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
describe('Dark mode storage', () => {
2+
before(() => {
3+
cy.visit('/')
4+
})
5+
6+
beforeEach(() => {
7+
cy.restoreLocalStorageCache()
8+
})
9+
10+
afterEach(() => {
11+
cy.saveLocalStorageCache()
12+
})
13+
14+
it('Button color mode must be visible', () => {
15+
cy.getColorModeButtonIsVisible()
16+
})
17+
18+
it('Current color mode must be "light"', () => {
19+
cy.getCurrentColorMode().should('contain', 'light')
20+
})
21+
22+
it('the color mode "light" must contain in localStorage by key "colorMode"', () => {
23+
cy.getLocalStorage('colorMode').should('contain', 'light')
24+
})
25+
26+
it('Button color mode must be clicked', () => {
27+
cy.toggleColorMode()
28+
})
29+
30+
it('the color mode "dark" must contain in localStorage by key "colorMode"', () => {
31+
cy.getLocalStorage('colorMode').should('contain', 'dark')
32+
})
33+
})

tests/e2e/integration/toggle-class.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,28 @@ describe('Dark mode toggle class', () => {
22
before(() => {
33
cy.visit('/')
44
})
5+
6+
it('Button color mode must be visible', () => {
7+
cy.getColorModeButtonIsVisible()
8+
})
9+
10+
it('Class name must contain "light" color mode', () => {
11+
cy.getColorModeClassName().should('contain', 'light')
12+
})
13+
14+
it('Current color mode must be "light"', () => {
15+
cy.getCurrentColorMode().should('contain', 'light')
16+
})
17+
18+
it('Button color mode must be clicked', () => {
19+
cy.toggleColorMode()
20+
})
21+
22+
it('Class name must contain "dark" color mode', () => {
23+
cy.getColorModeClassName().should('contain', 'dark')
24+
})
25+
26+
it('Current color mode must be "dark"', () => {
27+
cy.getCurrentColorMode().should('contain', 'dark')
28+
})
529
})

tests/e2e/support/commands.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,52 @@
2323
//
2424
// -- This is will overwrite an existing command --
2525
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
26+
27+
let LOCAL_STORAGE_MEMORY = {}
28+
29+
Cypress.Commands.add('saveLocalStorageCache', () => {
30+
Object.keys(localStorage).forEach(key => {
31+
LOCAL_STORAGE_MEMORY[key] = localStorage[key]
32+
})
33+
})
34+
35+
Cypress.Commands.add('restoreLocalStorageCache', () => {
36+
Object.keys(LOCAL_STORAGE_MEMORY).forEach(key => {
37+
localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key])
38+
})
39+
})
40+
41+
Cypress.Commands.add('clearLocalStorageCache', () => {
42+
localStorage.clear()
43+
LOCAL_STORAGE_MEMORY = {}
44+
})
45+
46+
Cypress.Commands.add('getColorModeButton', () => {
47+
cy.get('[data-cy="color-mode-button"')
48+
})
49+
50+
Cypress.Commands.add('getColorModeButtonIsVisible', () => {
51+
cy.getColorModeButton().should('be.visible')
52+
})
53+
54+
Cypress.Commands.add('getCurrentColorMode', () => {
55+
cy.getColorModeButton().get('[data-cy="color-mode"]').invoke('text')
56+
})
57+
58+
Cypress.Commands.add('getColorModeClassName', () => {
59+
cy.document().then((doc) => doc.documentElement.className)
60+
})
61+
62+
Cypress.Commands.add('getLocalStorage', (key) => {
63+
cy.window().then((window) => window.localStorage.getItem(key))
64+
})
65+
66+
Cypress.Commands.add('toggleColorMode', () => {
67+
cy.getColorModeButton().click()
68+
})
69+
70+
Cypress.Commands.add('checkColorModeStorage', (storage, key, token) => {
71+
cy.window()
72+
.its(`${storage}.${key}`)
73+
.should('eq', token)
74+
})

0 commit comments

Comments
 (0)