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
43const 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
8886describe ( '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 }
0 commit comments