@@ -82,16 +82,56 @@ describe("CollectionImportButton", () => {
8282 expect ( screen . getByLabelText ( "Force full re-import" ) ) . toBeInTheDocument ( ) ;
8383 } ) ;
8484
85- it ( "renders usage documentation for both import options " , async ( ) => {
85+ it ( "shows compact summary by default; detailed docs are hidden " , async ( ) => {
8686 const user = userEvent . setup ( ) ;
8787 renderButton ( ) ;
8888 await expandPanel ( user ) ;
89+ expect (
90+ screen . getByText ( / q u e u e i m p o r t p i c k s u p n e w a n d c h a n g e d i t e m s / i)
91+ ) . toBeInTheDocument ( ) ;
92+ expect (
93+ screen . queryByText ( / s c h e d u l e s a b a c k g r o u n d i m p o r t j o b / i)
94+ ) . not . toBeInTheDocument ( ) ;
95+ expect (
96+ screen . queryByText ( / t h e i m p o r t j o b r e - p r o c e s s e s e v e r y i t e m / i)
97+ ) . not . toBeInTheDocument ( ) ;
98+ } ) ;
99+
100+ it ( "clicking 'More details' reveals the detailed docs" , async ( ) => {
101+ const user = userEvent . setup ( ) ;
102+ renderButton ( ) ;
103+ await expandPanel ( user ) ;
104+
105+ const toggle = screen . getByRole ( "button" , { name : "More details" } ) ;
106+ expect ( toggle ) . toHaveAttribute ( "aria-expanded" , "false" ) ;
107+
108+ await user . click ( toggle ) ;
109+
89110 expect (
90111 screen . getByText ( / s c h e d u l e s a b a c k g r o u n d i m p o r t j o b / i)
91112 ) . toBeInTheDocument ( ) ;
92113 expect (
93114 screen . getByText ( / t h e i m p o r t j o b r e - p r o c e s s e s e v e r y i t e m / i)
94115 ) . toBeInTheDocument ( ) ;
116+ expect (
117+ screen . getByRole ( "button" , { name : "Less details" } )
118+ ) . toHaveAttribute ( "aria-expanded" , "true" ) ;
119+ } ) ;
120+
121+ it ( "clicking 'Less details' hides the detailed docs again" , async ( ) => {
122+ const user = userEvent . setup ( ) ;
123+ renderButton ( ) ;
124+ await expandPanel ( user ) ;
125+
126+ await user . click ( screen . getByRole ( "button" , { name : "More details" } ) ) ;
127+ expect (
128+ screen . getByText ( / s c h e d u l e s a b a c k g r o u n d i m p o r t j o b / i)
129+ ) . toBeInTheDocument ( ) ;
130+
131+ await user . click ( screen . getByRole ( "button" , { name : "Less details" } ) ) ;
132+ expect (
133+ screen . queryByText ( / s c h e d u l e s a b a c k g r o u n d i m p o r t j o b / i)
134+ ) . not . toBeInTheDocument ( ) ;
95135 } ) ;
96136
97137 it ( "checkbox toggles force state" , async ( ) => {
@@ -106,6 +146,43 @@ describe("CollectionImportButton", () => {
106146 expect ( checkbox ) . not . toBeChecked ( ) ;
107147 } ) ;
108148
149+ it ( "button text changes to 'Queue Full Re-import' when force is checked" , async ( ) => {
150+ const user = userEvent . setup ( ) ;
151+ renderButton ( ) ;
152+ await expandPanel ( user ) ;
153+
154+ expect (
155+ screen . getByRole ( "button" , { name : "Queue Import" } )
156+ ) . toBeInTheDocument ( ) ;
157+
158+ await user . click ( screen . getByRole ( "checkbox" ) ) ;
159+
160+ expect (
161+ screen . getByRole ( "button" , { name : "Queue Full Re-import" } )
162+ ) . toBeInTheDocument ( ) ;
163+ expect (
164+ screen . queryByRole ( "button" , { name : "Queue Import" } )
165+ ) . not . toBeInTheDocument ( ) ;
166+ } ) ;
167+
168+ it ( "button uses btn-warning class when force is checked" , async ( ) => {
169+ const user = userEvent . setup ( ) ;
170+ renderButton ( ) ;
171+ await expandPanel ( user ) ;
172+
173+ const button = screen . getByRole ( "button" , { name : "Queue Import" } ) ;
174+ expect ( button ) . toHaveClass ( "btn-default" ) ;
175+ expect ( button ) . not . toHaveClass ( "btn-warning" ) ;
176+
177+ await user . click ( screen . getByRole ( "checkbox" ) ) ;
178+
179+ const forceButton = screen . getByRole ( "button" , {
180+ name : "Queue Full Re-import" ,
181+ } ) ;
182+ expect ( forceButton ) . toHaveClass ( "btn-warning" ) ;
183+ expect ( forceButton ) . not . toHaveClass ( "btn-default" ) ;
184+ } ) ;
185+
109186 it ( "button triggers import with correct args (force=false)" , async ( ) => {
110187 const user = userEvent . setup ( ) ;
111188 const { importCollection } = renderButton ( ) ;
@@ -121,18 +198,39 @@ describe("CollectionImportButton", () => {
121198 await expandPanel ( user ) ;
122199 const checkbox = screen . getByRole ( "checkbox" ) ;
123200 await user . click ( checkbox ) ;
124- const button = screen . getByRole ( "button" , { name : "Queue Import" } ) ;
201+ const button = screen . getByRole ( "button" , {
202+ name : "Queue Full Re-import" ,
203+ } ) ;
125204 await user . click ( button ) ;
126205 expect ( importCollection ) . toHaveBeenCalledWith ( 42 , true ) ;
127206 } ) ;
128207
129- it ( "shows success feedback with alert-success styling after import" , async ( ) => {
208+ it ( "shows success feedback for regular import" , async ( ) => {
130209 const user = userEvent . setup ( ) ;
131210 renderButton ( ) ;
132211 await expandPanel ( user ) ;
133212 await user . click ( screen . getByRole ( "button" , { name : "Queue Import" } ) ) ;
134213 await waitFor ( ( ) => {
135- const feedback = screen . getByText ( "Import task queued." ) ;
214+ const feedback = screen . getByText (
215+ / i m p o r t t a s k q u e u e d \. n e w a n d u p d a t e d i t e m s w i l l a p p e a r / i
216+ ) ;
217+ expect ( feedback ) . toBeInTheDocument ( ) ;
218+ expect ( feedback ) . toHaveClass ( "alert" , "alert-success" ) ;
219+ } ) ;
220+ } ) ;
221+
222+ it ( "shows success feedback for force re-import" , async ( ) => {
223+ const user = userEvent . setup ( ) ;
224+ renderButton ( ) ;
225+ await expandPanel ( user ) ;
226+ await user . click ( screen . getByRole ( "checkbox" ) ) ;
227+ await user . click (
228+ screen . getByRole ( "button" , { name : "Queue Full Re-import" } )
229+ ) ;
230+ await waitFor ( ( ) => {
231+ const feedback = screen . getByText (
232+ / f u l l r e - i m p o r t t a s k q u e u e d \. a l l i t e m s w i l l b e r e - p r o c e s s e d / i
233+ ) ;
136234 expect ( feedback ) . toBeInTheDocument ( ) ;
137235 expect ( feedback ) . toHaveClass ( "alert" , "alert-success" ) ;
138236 } ) ;
@@ -162,9 +260,13 @@ describe("CollectionImportButton", () => {
162260 await user . click ( checkbox ) ;
163261 expect ( checkbox ) . toBeChecked ( ) ;
164262
165- await user . click ( screen . getByRole ( "button" , { name : "Queue Import" } ) ) ;
263+ await user . click (
264+ screen . getByRole ( "button" , { name : "Queue Full Re-import" } )
265+ ) ;
166266 await waitFor ( ( ) => {
167- expect ( screen . getByText ( "Import task queued." ) ) . toBeInTheDocument ( ) ;
267+ expect (
268+ screen . getByText ( / f u l l r e - i m p o r t t a s k q u e u e d / i)
269+ ) . toBeInTheDocument ( ) ;
168270 } ) ;
169271
170272 const nextCollection : CollectionData = {
@@ -183,7 +285,9 @@ describe("CollectionImportButton", () => {
183285
184286 await waitFor ( ( ) => {
185287 expect ( screen . getByRole ( "checkbox" ) ) . not . toBeChecked ( ) ;
186- expect ( screen . queryByText ( "Import task queued." ) ) . not . toBeInTheDocument ( ) ;
288+ expect (
289+ screen . queryByText ( / f u l l r e - i m p o r t t a s k q u e u e d / i)
290+ ) . not . toBeInTheDocument ( ) ;
187291 } ) ;
188292 } ) ;
189293
@@ -216,4 +320,31 @@ describe("CollectionImportButton", () => {
216320 ) . toBeEnabled ( ) ;
217321 } ) ;
218322 } ) ;
323+
324+ it ( "shows 'Queuing Full Re-import...' while importing with force" , async ( ) => {
325+ const user = userEvent . setup ( ) ;
326+ let resolveImport : ( ) => void ;
327+ const pendingImport = new Promise < void > ( ( resolve ) => {
328+ resolveImport = resolve ;
329+ } ) ;
330+ const mockImport = jest . fn ( ) . mockReturnValue ( pendingImport ) ;
331+ renderButton ( { importCollection : mockImport } ) ;
332+ await expandPanel ( user ) ;
333+
334+ await user . click ( screen . getByRole ( "checkbox" ) ) ;
335+ await user . click (
336+ screen . getByRole ( "button" , { name : "Queue Full Re-import" } )
337+ ) ;
338+
339+ expect (
340+ screen . getByRole ( "button" , { name : "Queuing Full Re-import..." } )
341+ ) . toBeDisabled ( ) ;
342+
343+ resolveImport ( ) ;
344+ await waitFor ( ( ) => {
345+ expect (
346+ screen . getByRole ( "button" , { name : "Queue Full Re-import" } )
347+ ) . toBeEnabled ( ) ;
348+ } ) ;
349+ } ) ;
219350} ) ;
0 commit comments