Skip to content

Commit 77d86cc

Browse files
committed
fix(theming): Adjust dark theme to be accessible adjust cypress tests
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent e0d1e7c commit 77d86cc

3 files changed

Lines changed: 45 additions & 40 deletions

File tree

apps/theming/lib/Themes/DarkTheme.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ public function getCSSVariables(): array {
5555
$colorMainText = '#D8D8D8';
5656
$colorMainBackground = '#171717';
5757
$colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
58-
$colorTextMaxcontrast = $this->util->darken($colorMainText, 30);
58+
$colorTextMaxcontrast = $this->util->darken($colorMainText, 28);
5959

6060
$colorBoxShadow = $this->util->darken($colorMainBackground, 70);
6161
$colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
6262

63-
$colorError = '#d91812';
63+
$colorError = '#ec1a13';
6464
$colorWarning = '#c28900';
65-
$colorSuccess = '#2d7b41';
65+
$colorSuccess = '#328647';
6666
$colorInfo = '#0071ad';
6767

6868
return array_merge(

apps/theming/__tests__/accessibility.cy.ts renamed to cypress/e2e/theming/accessibility.cy.ts

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// eslint-disable-next-line import/no-webpack-loader-syntax, import/no-unresolved
2-
import style from '!raw-loader!../css/default.css'
1+
const themesToTest = ['light', 'dark', 'light-highcontrast', 'dark-highcontrast']
32

43
const testCases = {
54
'Main text': {
@@ -8,7 +7,6 @@ const testCases = {
87
// 'color-text-light', deprecated
98
// 'color-text-lighter', deprecated
109
'color-text-maxcontrast',
11-
'color-text-maxcontrast-default',
1210
],
1311
backgroundColors: [
1412
'color-background-main',
@@ -86,42 +84,48 @@ function createTestCase(foreground: string, background: string) {
8684
}
8785

8886
describe('Accessibility of Nextcloud theming', () => {
89-
before(() => {
90-
cy.injectAxe()
87+
for (const theme of themesToTest) {
88+
context(`Theme: ${theme}`, () => {
89+
before(() => {
90+
cy.createRandomUser().then(($user) => {
91+
// set user theme
92+
cy.runOccCommand(`user:setting -- '${$user.userId}' theming enabled-themes '["${theme}"]'`)
93+
cy.login($user)
94+
cy.visit('/')
95+
cy.injectAxe({ axeCorePath: 'node_modules/axe-core/axe.min.js' })
96+
})
97+
})
9198

92-
const el = document.createElement('style')
93-
el.innerText = style
94-
document.head.appendChild(el)
95-
})
99+
beforeEach(() => {
100+
cy.document().then(doc => {
101+
const root = doc.querySelector('main')
102+
if (root === null) {
103+
throw new Error('No test root found')
104+
}
105+
for (const child of root.children) {
106+
root.removeChild(child)
107+
}
108+
})
109+
})
96110

97-
beforeEach(() => {
98-
cy.document().then(doc => {
99-
const root = doc.querySelector('[data-cy-root]')
100-
if (root === null) {
101-
throw new Error('No test root found')
102-
}
103-
for (const child of root.children) {
104-
root.removeChild(child)
105-
}
106-
})
107-
})
108-
109-
for (const [name, { backgroundColors, foregroundColors }] of Object.entries(testCases)) {
110-
context(`Accessibility of CSS color variables for ${name}`, () => {
111-
for (const foreground of foregroundColors) {
112-
for (const background of backgroundColors) {
113-
it(`color contrast of ${foreground} on ${background}`, () => {
114-
const element = createTestCase(foreground, background)
115-
cy.document().then(doc => {
116-
const root = doc.querySelector('[data-cy-root]')
117-
// eslint-disable-next-line no-unused-expressions
118-
expect(root).not.to.be.undefined
119-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
120-
root!.appendChild(element)
121-
cy.checkA11y('[data-cy-testcase]')
122-
})
123-
})
124-
}
111+
for (const [name, { backgroundColors, foregroundColors }] of Object.entries(testCases)) {
112+
context(`Accessibility of CSS color variables for ${name}`, () => {
113+
for (const foreground of foregroundColors) {
114+
for (const background of backgroundColors) {
115+
it(`color contrast of ${foreground} on ${background}`, () => {
116+
const element = createTestCase(foreground, background)
117+
cy.document().then(doc => {
118+
const root = doc.querySelector('main')
119+
// eslint-disable-next-line no-unused-expressions
120+
expect(root).not.to.be.undefined
121+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
122+
root!.appendChild(element)
123+
cy.checkA11y('[data-cy-testcase]')
124+
})
125+
})
126+
}
127+
}
128+
})
125129
}
126130
})
127131
}

cypress/support/e2e.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22+
import 'cypress-axe'
2223
import './commands.ts'
2324

2425
// Fix ResizeObserver loop limit exceeded happening in Cypress only

0 commit comments

Comments
 (0)