11import { expect , userEvent , waitFor , within } from '@storybook/test' ;
2- import { http , HttpResponse } from 'msw' ;
32
43import ContentPicker from '../../ContentPicker' ;
5- import { mockRootFolder } from '../../../content-explorer/stories/__mocks__/mockRootFolder' ;
64import { SLEEP_TIMEOUT } from '../../../../utils/storybook' ;
7- import { DEFAULT_HOSTNAME_API } from '../../../../constants' ;
85
96export const basic = {
107 play : async ( { canvasElement } ) => {
@@ -28,14 +25,10 @@ export const selectedEmptyState = {
2825 expect ( canvas . getByText ( "You haven't selected any items yet." ) ) . toBeInTheDocument ( ) ;
2926 } ) ;
3027 } ,
31- parameters : {
32- msw : {
33- handlers : [
34- http . get ( `${ DEFAULT_HOSTNAME_API } /2.0/folders/*` , ( ) => {
35- return HttpResponse . json ( mockRootFolder ) ;
36- } ) ,
37- ] ,
38- } ,
28+ args : {
29+ features : global . FEATURE_FLAGS ,
30+ rootFolderId : '69083462919' ,
31+ token : global . TOKEN ,
3932 } ,
4033} ;
4134
@@ -53,14 +46,10 @@ export const emptyFolder = {
5346 } ,
5447 ) ;
5548 } ,
56- parameters : {
57- msw : {
58- handlers : [
59- http . get ( `${ DEFAULT_HOSTNAME_API } /2.0/folders/*` , ( ) => {
60- return HttpResponse . json ( mockRootFolder ) ;
61- } ) ,
62- ] ,
63- } ,
49+ args : {
50+ features : global . FEATURE_FLAGS ,
51+ rootFolderId : '69083462919' ,
52+ token : global . TOKEN ,
6453 } ,
6554} ;
6655
@@ -83,14 +72,10 @@ export const emptySelectionMode = {
8372 } ,
8473 ) ;
8574 } ,
86- parameters : {
87- msw : {
88- handlers : [
89- http . get ( `${ DEFAULT_HOSTNAME_API } /2.0/folders/*` , ( ) => {
90- return HttpResponse . json ( mockRootFolder ) ;
91- } ) ,
92- ] ,
93- } ,
75+ args : {
76+ features : global . FEATURE_FLAGS ,
77+ rootFolderId : '69083462919' ,
78+ token : global . TOKEN ,
9479 } ,
9580} ;
9681
@@ -108,41 +93,40 @@ export const withError = {
10893 } ,
10994 ) ;
11095 } ,
111- parameters : {
112- msw : {
113- handlers : [
114- http . get ( `${ DEFAULT_HOSTNAME_API } /2.0/folders/*` , ( ) => {
115- return HttpResponse . error ( ) ;
116- } ) ,
117- ] ,
118- } ,
96+ args : {
97+ features : global . FEATURE_FLAGS ,
98+ rootFolderId : 'invalid-folder-id' , // Force error state
99+ token : global . TOKEN ,
119100 } ,
120101} ;
121102
122103export const hitSelectionLimit = {
123- args : { maxSelectable : 2 } ,
104+ args : {
105+ features : global . FEATURE_FLAGS ,
106+ rootFolderId : '69083462919' ,
107+ token : global . TOKEN ,
108+ maxSelectable : 2 ,
109+ } ,
124110 play : async ( { canvasElement } ) => {
125111 const canvas = within ( canvasElement ) ;
126112
127- // Wait for items to load
113+ // Wait for items to load and select first item
128114 await waitFor ( ( ) => {
129- expect ( canvas . getByText ( 'Sample File.pdf' ) ) . toBeInTheDocument ( ) ;
130- expect ( canvas . getByText ( 'Sample Folder' ) ) . toBeInTheDocument ( ) ;
131- expect ( canvas . getByText ( 'Another File.docx' ) ) . toBeInTheDocument ( ) ;
115+ const items = canvas . getAllByRole ( 'row' ) ;
116+ expect ( items . length ) . toBeGreaterThan ( 1 ) ; // Header row + at least one item
132117 } ) ;
133118
134- // Select first item
135- const fileRow = canvas . getByRole ( 'row' , { name : / S a m p l e F i l e \. p d f / i } ) ;
136- await userEvent . click ( fileRow ) ;
119+ const items = canvas . getAllByRole ( 'row' ) ;
120+ await userEvent . click ( items [ 1 ] ) ; // Select first item after header
121+
137122 await waitFor ( ( ) => {
138123 expect ( canvas . getByText ( '1 Selected' ) ) . toBeInTheDocument ( ) ;
139124 const chooseButton = canvas . getByLabelText ( 'Choose' ) ;
140125 expect ( chooseButton ) . toBeEnabled ( ) ;
141126 } ) ;
142127
143128 // Select second item to hit limit
144- const folderRow = canvas . getByRole ( 'row' , { name : / S a m p l e F o l d e r / i } ) ;
145- await userEvent . click ( folderRow ) ;
129+ await userEvent . click ( items [ 2 ] ) ; // Select second item
146130 await waitFor ( ( ) => {
147131 expect ( canvas . getByText ( '2 Selected' ) ) . toBeInTheDocument ( ) ;
148132 expect ( canvas . getByText ( '(max)' ) ) . toBeInTheDocument ( ) ;
@@ -151,159 +135,63 @@ export const hitSelectionLimit = {
151135 } ) ;
152136
153137 // Try to select beyond limit
154- const docRow = canvas . getByRole ( 'row' , { name : / A n o t h e r F i l e \. d o c x / i } ) ;
155- await userEvent . click ( docRow ) ;
156-
157- // Verify selection hasn't changed and max indicator is shown
158- await waitFor ( ( ) => {
159- expect ( canvas . getByText ( '2 Selected' ) ) . toBeInTheDocument ( ) ;
160- expect ( canvas . getByText ( '(max)' ) ) . toBeInTheDocument ( ) ;
161- const chooseButton = canvas . getByLabelText ( 'Choose' ) ;
162- expect ( chooseButton ) . toBeEnabled ( ) ;
163- } ) ;
164- } ,
165- parameters : {
166- msw : {
167- handlers : [
168- http . get ( `${ DEFAULT_HOSTNAME_API } /2.0/folders/*` , ( ) => {
169- return HttpResponse . json ( {
170- id : '0' ,
171- name : 'Root' ,
172- permissions : {
173- can_upload : true ,
174- can_rename : true ,
175- can_delete : true ,
176- } ,
177- path_collection : {
178- total_count : 0 ,
179- entries : [ ] ,
180- } ,
181- item_collection : {
182- total_count : 3 ,
183- entries : [
184- {
185- id : '1' ,
186- name : 'Doc 1.pdf' ,
187- type : 'file' ,
188- permissions : {
189- can_rename : true ,
190- can_delete : true ,
191- can_share : true ,
192- } ,
193- } ,
194- {
195- id : '2' ,
196- name : 'Doc 2.pdf' ,
197- type : 'file' ,
198- permissions : {
199- can_rename : true ,
200- can_delete : true ,
201- can_share : true ,
202- } ,
203- } ,
204- {
205- id : '3' ,
206- name : 'Doc 3.pdf' ,
207- type : 'file' ,
208- permissions : {
209- can_rename : true ,
210- can_delete : true ,
211- can_share : true ,
212- } ,
213- } ,
214- ] ,
215- } ,
216- } ) ;
217- } ) ,
218- ] ,
219- } ,
138+ if ( items . length > 3 ) {
139+ await userEvent . click ( items [ 3 ] ) ; // Try to select third item
140+ await waitFor ( ( ) => {
141+ expect ( canvas . getByText ( '2 Selected' ) ) . toBeInTheDocument ( ) ;
142+ expect ( canvas . getByText ( '(max)' ) ) . toBeInTheDocument ( ) ;
143+ const chooseButton = canvas . getByLabelText ( 'Choose' ) ;
144+ expect ( chooseButton ) . toBeEnabled ( ) ;
145+ } ) ;
146+ }
220147 } ,
221148} ;
222149
223150export const singleSelectWithItems = {
224151 args : {
152+ features : global . FEATURE_FLAGS ,
153+ rootFolderId : '69083462919' ,
154+ token : global . TOKEN ,
225155 maxSelectable : 1 ,
226156 } ,
227157 play : async ( { canvasElement } ) => {
228158 const canvas = within ( canvasElement ) ;
229159
230160 // Wait for items to load
231161 await waitFor ( ( ) => {
232- expect ( canvas . getByText ( 'Sample File.pdf' ) ) . toBeInTheDocument ( ) ;
233- expect ( canvas . getByText ( 'Sample Folder' ) ) . toBeInTheDocument ( ) ;
234- expect ( canvas . getByText ( 'Another File.docx' ) ) . toBeInTheDocument ( ) ;
162+ const items = canvas . getAllByRole ( 'row' ) ;
163+ expect ( items . length ) . toBeGreaterThan ( 1 ) ; // Header row + at least one item
235164 } ) ;
236165
237- // Select first file
238- const fileRow = canvas . getByRole ( 'row' , { name : / S a m p l e F i l e \. p d f / i } ) ;
239- await userEvent . click ( fileRow ) ;
240- await waitFor ( ( ) => {
241- expect ( canvas . getByText ( '1 Selected' ) ) . toBeInTheDocument ( ) ;
242- const chooseButton = canvas . getByLabelText ( 'Choose' ) ;
243- expect ( chooseButton ) . toBeEnabled ( ) ;
244- } ) ;
166+ const items = canvas . getAllByRole ( 'row' ) ;
245167
246- // Select another file (should replace previous selection)
247- const docRow = canvas . getByRole ( 'row' , { name : / A n o t h e r F i l e \. d o c x / i } ) ;
248- await userEvent . click ( docRow ) ;
168+ // Select first item
169+ await userEvent . click ( items [ 1 ] ) ; // Select first item after header
249170 await waitFor ( ( ) => {
250171 expect ( canvas . getByText ( '1 Selected' ) ) . toBeInTheDocument ( ) ;
251172 const chooseButton = canvas . getByLabelText ( 'Choose' ) ;
252173 expect ( chooseButton ) . toBeEnabled ( ) ;
253174 } ) ;
254175
255- // Select folder (should replace file selection)
256- const folderRow = canvas . getByRole ( 'row' , { name : / S a m p l e F o l d e r / i } ) ;
257- await userEvent . click ( folderRow ) ;
258- await waitFor ( ( ) => {
259- expect ( canvas . getByText ( '1 Selected' ) ) . toBeInTheDocument ( ) ;
260- const chooseButton = canvas . getByLabelText ( 'Choose' ) ;
261- expect ( chooseButton ) . toBeEnabled ( ) ;
262- } ) ;
263- } ,
264- parameters : {
265- msw : {
266- handlers : [
267- http . get ( `${ DEFAULT_HOSTNAME_API } /2.0/folders/*` , ( ) => {
268- return HttpResponse . json ( {
269- id : '0' ,
270- name : 'Root' ,
271- type : 'folder' ,
272- size : 0 ,
273- parent : null ,
274- path_collection : { total_count : 0 , entries : [ ] } ,
275- item_collection : {
276- total_count : 3 ,
277- entries : [
278- {
279- id : '1' ,
280- name : 'Sample File.pdf' ,
281- type : 'file' ,
282- size : 1024 ,
283- permissions : { can_delete : true , can_rename : true , can_share : true } ,
284- } ,
285- {
286- id : '2' ,
287- name : 'Sample Folder' ,
288- type : 'folder' ,
289- size : 0 ,
290- permissions : { can_delete : true , can_rename : true , can_share : true } ,
291- } ,
292- {
293- id : '3' ,
294- name : 'Another File.docx' ,
295- type : 'file' ,
296- size : 2048 ,
297- permissions : { can_delete : true , can_rename : true , can_share : true } ,
298- } ,
299- ] ,
300- offset : 0 ,
301- limit : 100 ,
302- } ,
303- } ) ;
304- } ) ,
305- ] ,
306- } ,
176+ // Select second item (should replace previous selection)
177+ if ( items . length > 2 ) {
178+ await userEvent . click ( items [ 2 ] ) ;
179+ await waitFor ( ( ) => {
180+ expect ( canvas . getByText ( '1 Selected' ) ) . toBeInTheDocument ( ) ;
181+ const chooseButton = canvas . getByLabelText ( 'Choose' ) ;
182+ expect ( chooseButton ) . toBeEnabled ( ) ;
183+ } ) ;
184+ }
185+
186+ // Select third item (should replace previous selection)
187+ if ( items . length > 3 ) {
188+ await userEvent . click ( items [ 3 ] ) ;
189+ await waitFor ( ( ) => {
190+ expect ( canvas . getByText ( '1 Selected' ) ) . toBeInTheDocument ( ) ;
191+ const chooseButton = canvas . getByLabelText ( 'Choose' ) ;
192+ expect ( chooseButton ) . toBeEnabled ( ) ;
193+ } ) ;
194+ }
307195 } ,
308196} ;
309197
@@ -312,16 +200,7 @@ export default {
312200 component : ContentPicker ,
313201 args : {
314202 features : global . FEATURE_FLAGS ,
315- rootFolderId : global . FOLDER_ID ,
203+ rootFolderId : '69083462919' ,
316204 token : global . TOKEN ,
317205 } ,
318- parameters : {
319- msw : {
320- handlers : [
321- http . get ( `${ DEFAULT_HOSTNAME_API } /2.0/folders/*` , ( ) => {
322- return HttpResponse . json ( mockRootFolder ) ;
323- } ) ,
324- ] ,
325- } ,
326- } ,
327206} ;
0 commit comments