@@ -86,31 +86,76 @@ describe('ThemeQuickPresets', () => {
8686 } ) ;
8787} ) ;
8888
89- describe ( 'ThemeQuickPresets responsive rendering' , ( ) => {
89+ describe ( 'ThemeQuickPresets responsive rendering & high-contrast ' , ( ) => {
9090 const onThemeChange = vi . fn ( ) ;
9191
9292 beforeEach ( ( ) => {
9393 onThemeChange . mockClear ( ) ;
9494 } ) ;
9595
96- it ( 'renders every preset with accessible labels, high-contrast styling, and wrap layout' , ( ) => {
96+ it ( 'checks rendering of preset buttons on sm and lg viewports' , ( ) => {
97+ window . innerWidth = 375 ;
98+ window . dispatchEvent ( new Event ( 'resize' ) ) ;
99+
100+ const { rerender } = render ( < ThemeQuickPresets theme = "dark" onThemeChange = { onThemeChange } /> ) ;
101+
102+ expect ( screen . getAllByRole ( 'button' , { name : / a p p l y .+ t h e m e / i } ) ) . toHaveLength (
103+ validKeys . length
104+ ) ;
105+
106+ window . innerWidth = 1280 ;
107+ window . dispatchEvent ( new Event ( 'resize' ) ) ;
108+
109+ rerender ( < ThemeQuickPresets theme = "dark" onThemeChange = { onThemeChange } /> ) ;
110+
111+ expect ( screen . getAllByRole ( 'button' , { name : / a p p l y .+ t h e m e / i } ) ) . toHaveLength (
112+ validKeys . length
113+ ) ;
114+ } ) ;
115+
116+ it ( 'checks rendering of all preset buttons with accessible labels' , ( ) => {
97117 render ( < ThemeQuickPresets theme = "dark" onThemeChange = { onThemeChange } /> ) ;
98118
99119 const presetButtons = screen . getAllByRole ( 'button' , { name : / a p p l y .+ t h e m e / i } ) ;
100120 expect ( presetButtons ) . toHaveLength ( validKeys . length ) ;
121+ } ) ;
101122
123+ it ( 'active preset is announced to screen readers via aria-pressed' , ( ) => {
124+ render ( < ThemeQuickPresets theme = "dark" onThemeChange = { onThemeChange } /> ) ;
102125 expect (
103126 screen . getByRole ( 'button' , { name : / a p p l y d a r k t h e m e / i } ) . getAttribute ( 'aria-pressed' )
104127 ) . toBe ( 'true' ) ;
128+ } ) ;
105129
106- const highContrastButton = screen . getByRole ( 'button' , { name : / a p p l y h i g h c o n t r a s t t h e m e / i } ) ;
107- expect ( highContrastButton ) . toBeDefined ( ) ;
108- expect ( highContrastButton . getAttribute ( 'title' ) ) . toBe ( 'Highcontrast ') ;
109- expect ( highContrastButton . getAttribute ( 'style' ) ) . toContain ( 'rgb(10, 10, 10)' ) ;
130+ it ( 'check if wrapper div uses flex and wrap so buttons reflow on narrow viewports' , ( ) => {
131+ render ( < ThemeQuickPresets theme = "dark" onThemeChange = { onThemeChange } /> ) ;
132+ const buttons = screen . getAllByRole ( 'button ') ;
133+ const grid = buttons . at ( 0 ) ?. parentElement ;
110134
111- const grid = highContrastButton . closest ( 'div' ) ;
112135 expect ( grid ) . not . toBeNull ( ) ;
113- expect ( grid ?. style . display ) . toBe ( 'flex' ) ;
114- expect ( grid ?. style . flexWrap ) . toBe ( 'wrap' ) ;
136+ expect ( grid ?. className ) . toContain ( 'theme-quick-presets' ) ;
137+ } ) ;
138+
139+ it ( 'check if each preset button has theme bg colour(inline)' , ( ) => {
140+ render ( < ThemeQuickPresets theme = "dark" onThemeChange = { onThemeChange } /> ) ;
141+ const buttons = screen . getAllByRole ( 'button' ) ;
142+
143+ buttons . forEach ( ( btn ) => {
144+ expect ( btn . getAttribute ( 'style' ) ) . not . toBeNull ( ) ;
145+ expect ( btn . getAttribute ( 'style' ) ) . toMatch ( / b a c k g r o u n d / i) ;
146+ } ) ;
147+ } ) ;
148+
149+ it ( 'checking if highcontrast is inactive when different theme is active' , ( ) => {
150+ render ( < ThemeQuickPresets theme = "dark" onThemeChange = { onThemeChange } /> ) ;
151+ const hcBtn = screen . getByRole ( 'button' , { name : / a p p l y h i g h c o n t r a s t t h e m e / i } ) ;
152+
153+ expect ( hcBtn . getAttribute ( 'aria-pressed' ) ) . toBe ( 'false' ) ;
154+ } ) ;
155+
156+ it ( 'check if highcontrast button becomes active when selected' , ( ) => {
157+ render ( < ThemeQuickPresets theme = "highcontrast" onThemeChange = { onThemeChange } /> ) ;
158+ const hcBtn = screen . getByRole ( 'button' , { name : / a p p l y h i g h c o n t r a s t t h e m e / i } ) ;
159+ expect ( hcBtn . getAttribute ( 'aria-pressed' ) ) . toBe ( 'true' ) ;
115160 } ) ;
116161} ) ;
0 commit comments