@@ -5,6 +5,11 @@ import { AssessmentItemToolbarActions } from '../../constants';
55import HintsEditor from './HintsEditor' ;
66
77jest . mock ( 'shared/views/TipTapEditor/TipTapEditor/TipTapEditor.vue' ) ;
8+ jest . mock ( 'kolibri-design-system/lib/composables/useKResponsiveWindow' , ( ) => {
9+ return function useKResponsiveWindow ( ) {
10+ return { windowBreakpoint : { value : 4 } } ;
11+ } ;
12+ } ) ;
813
914configure ( {
1015 testIdAttribute : 'data-test' ,
@@ -20,6 +25,10 @@ const renderComponent = props => {
2025 } ) ;
2126} ;
2227
28+ const openHintsSection = async user => {
29+ await user . click ( screen . getByText ( HintsEditor . $trs . hintsLabel ) ) ;
30+ } ;
31+
2332const getHintCards = ( ) => {
2433 return screen . getAllByTestId ( 'hint' ) ;
2534} ;
@@ -31,29 +40,35 @@ const clickToolbarAction = async ({ action, hintIdx, user }) => {
3140} ;
3241
3342describe ( 'HintsEditor' , ( ) => {
34- it ( 'smoke test' , ( ) => {
43+ it ( 'smoke test' , async ( ) => {
44+ const user = userEvent . setup ( ) ;
3545 renderComponent ( ) ;
46+ await openHintsSection ( user ) ;
3647
3748 expect (
3849 screen . getByRole ( 'button' , { name : HintsEditor . $trs . newHintBtnLabel } ) ,
3950 ) . toBeInTheDocument ( ) ;
4051 } ) ;
4152
42- it ( 'shows an empty-state message when a question has no hints' , ( ) => {
53+ it ( 'shows an empty-state message when a question has no hints' , async ( ) => {
54+ const user = userEvent . setup ( ) ;
4355 renderComponent ( {
4456 hints : [ ] ,
4557 } ) ;
58+ await openHintsSection ( user ) ;
4659
4760 expect ( screen . getByText ( HintsEditor . $trs . noHintsPlaceholder ) ) . toBeInTheDocument ( ) ;
4861 } ) ;
4962
50- it ( 'shows hints in the same order as the question' , ( ) => {
63+ it ( 'shows hints in the same order as the question' , async ( ) => {
64+ const user = userEvent . setup ( ) ;
5165 renderComponent ( {
5266 hints : [
5367 { hint : 'First hint' , order : 1 } ,
5468 { hint : 'Second hint' , order : 2 } ,
5569 ] ,
5670 } ) ;
71+ await openHintsSection ( user ) ;
5772
5873 const hintCards = getHintCards ( ) ;
5974 expect ( within ( hintCards [ 0 ] ) . getByText ( 'First hint' ) ) . toBeInTheDocument ( ) ;
@@ -69,6 +84,7 @@ describe('HintsEditor', () => {
6984 ] ,
7085 openHintIdx : 1 ,
7186 } ) ;
87+ await openHintsSection ( user ) ;
7288
7389 const hintCards = getHintCards ( ) ;
7490 const hintTextField = within ( hintCards [ 1 ] ) . getByRole ( 'textbox' ) ;
@@ -92,6 +108,7 @@ describe('HintsEditor', () => {
92108 { hint : 'Third hint' , order : 3 } ,
93109 ] ,
94110 } ) ;
111+ await openHintsSection ( user ) ;
95112
96113 await user . click ( screen . getByRole ( 'button' , { name : HintsEditor . $trs . newHintBtnLabel } ) ) ;
97114
@@ -114,6 +131,7 @@ describe('HintsEditor', () => {
114131 ] ,
115132 openHintIdx : 0 ,
116133 } ) ;
134+ await openHintsSection ( user ) ;
117135
118136 const hintCards = getHintCards ( ) ;
119137 await user . click ( hintCards [ 1 ] ) ;
@@ -131,6 +149,7 @@ describe('HintsEditor', () => {
131149 ] ,
132150 openHintIdx : 1 ,
133151 } ) ;
152+ await openHintsSection ( user ) ;
134153
135154 await clickToolbarAction ( {
136155 action : AssessmentItemToolbarActions . MOVE_ITEM_UP ,
@@ -156,6 +175,7 @@ describe('HintsEditor', () => {
156175 ] ,
157176 openHintIdx : 0 ,
158177 } ) ;
178+ await openHintsSection ( user ) ;
159179
160180 await clickToolbarAction ( {
161181 action : AssessmentItemToolbarActions . MOVE_ITEM_UP ,
@@ -176,6 +196,7 @@ describe('HintsEditor', () => {
176196 ] ,
177197 openHintIdx : 0 ,
178198 } ) ;
199+ await openHintsSection ( user ) ;
179200
180201 await clickToolbarAction ( {
181202 action : AssessmentItemToolbarActions . MOVE_ITEM_DOWN ,
@@ -201,6 +222,7 @@ describe('HintsEditor', () => {
201222 ] ,
202223 openHintIdx : 1 ,
203224 } ) ;
225+ await openHintsSection ( user ) ;
204226
205227 await clickToolbarAction ( {
206228 action : AssessmentItemToolbarActions . MOVE_ITEM_DOWN ,
@@ -221,6 +243,7 @@ describe('HintsEditor', () => {
221243 ] ,
222244 openHintIdx : 0 ,
223245 } ) ;
246+ await openHintsSection ( user ) ;
224247
225248 await clickToolbarAction ( {
226249 action : AssessmentItemToolbarActions . DELETE_ITEM ,
@@ -242,6 +265,7 @@ describe('HintsEditor', () => {
242265 ] ,
243266 openHintIdx : 1 ,
244267 } ) ;
268+ await openHintsSection ( user ) ;
245269
246270 await clickToolbarAction ( {
247271 action : AssessmentItemToolbarActions . DELETE_ITEM ,
@@ -252,4 +276,26 @@ describe('HintsEditor', () => {
252276 expect ( emitted ( ) . open ) . toHaveLength ( 1 ) ;
253277 expect ( emitted ( ) . open [ 0 ] [ 0 ] ) . toBe ( 0 ) ;
254278 } ) ;
279+
280+ it ( 'toggles the hints section open and closed when clicking the header button' , async ( ) => {
281+ const user = userEvent . setup ( ) ;
282+ renderComponent ( {
283+ hints : [ { hint : 'First hint' , order : 1 } ] ,
284+ } ) ;
285+
286+ // The header button acts as an accordion trigger with correct initial attributes
287+ const headerButton = screen . getByRole ( 'button' , { name : HintsEditor . $trs . hintsLabel } ) ;
288+ expect ( headerButton ) . toHaveAttribute ( 'aria-expanded' , 'false' ) ;
289+ expect ( screen . queryByTestId ( 'hint' ) ) . not . toBeInTheDocument ( ) ;
290+
291+ // Click to open the section
292+ await user . click ( headerButton ) ;
293+ expect ( headerButton ) . toHaveAttribute ( 'aria-expanded' , 'true' ) ;
294+ expect ( screen . getByTestId ( 'hint' ) ) . toBeInTheDocument ( ) ;
295+
296+ // Click to close the section
297+ await user . click ( headerButton ) ;
298+ expect ( headerButton ) . toHaveAttribute ( 'aria-expanded' , 'false' ) ;
299+ expect ( screen . queryByTestId ( 'hint' ) ) . not . toBeInTheDocument ( ) ;
300+ } ) ;
255301} ) ;
0 commit comments