11const modifyCatalogueCategory = (
22 values : {
33 editCatalogueCategoryName ?: string ;
4+ actionsIndex ?: number ;
45 name : string ;
56 newFormFields ?: {
67 name : string ;
@@ -13,10 +14,15 @@ const modifyCatalogueCategory = (
1314 } ,
1415 ignoreChecks ?: boolean
1516) => {
16- if ( values . editCatalogueCategoryName ) {
17- cy . findByRole ( 'button' , {
18- name : `actions ${ values . editCatalogueCategoryName } catalogue category button` ,
19- } ) . click ( ) ;
17+ if (
18+ values . editCatalogueCategoryName &&
19+ typeof values . actionsIndex === 'number'
20+ ) {
21+ cy . findAllByRole ( 'button' , {
22+ name : 'Card Actions' ,
23+ } )
24+ . eq ( values . actionsIndex )
25+ . click ( ) ;
2026
2127 cy . findByRole ( 'menuitem' , {
2228 name : `edit ${ values . editCatalogueCategoryName } catalogue category button` ,
@@ -92,7 +98,10 @@ const modifyCatalogueCategory = (
9298 }
9399
94100 cy . findByRole ( 'button' , { name : 'Save' } ) . click ( ) ;
95- if ( values . editCatalogueCategoryName )
101+ if (
102+ values . editCatalogueCategoryName &&
103+ typeof values . actionsIndex === 'number'
104+ )
96105 cy . findByRole ( 'button' , { name : 'Close' } ) . click ( ) ;
97106 if ( ! ignoreChecks ) {
98107 cy . findByText ( values . name ) . should ( 'exist' ) ;
@@ -116,10 +125,12 @@ const modifyCatalogueCategory = (
116125 }
117126} ;
118127
119- const deleteCatalogueCategory = ( name : string ) => {
120- cy . findByRole ( 'button' , {
121- name : `actions ${ name } catalogue category button` ,
122- } ) . click ( ) ;
128+ const deleteCatalogueCategory = ( name : string , actionsIndex : number ) => {
129+ cy . findAllByRole ( 'button' , {
130+ name : 'Card Actions' ,
131+ } )
132+ . eq ( actionsIndex )
133+ . click ( ) ;
123134
124135 cy . findByRole ( 'menuitem' , {
125136 name : `delete ${ name } catalogue category button` ,
@@ -128,10 +139,15 @@ const deleteCatalogueCategory = (name: string) => {
128139 cy . findByRole ( 'button' , { name : 'Continue' } ) . click ( ) ;
129140} ;
130141
131- export const duplicateCatalogueCategory = ( name : string ) => {
132- cy . findByRole ( 'button' , {
133- name : `actions ${ name } catalogue category button` ,
134- } ) . click ( ) ;
142+ export const duplicateCatalogueCategory = (
143+ name : string ,
144+ actionsIndex : number
145+ ) => {
146+ cy . findAllByRole ( 'button' , {
147+ name : 'Card Actions' ,
148+ } )
149+ . eq ( actionsIndex )
150+ . click ( ) ;
135151
136152 cy . findByRole ( 'menuitem' , {
137153 name : `duplicate ${ name } catalogue category button` ,
@@ -141,9 +157,11 @@ export const duplicateCatalogueCategory = (name: string) => {
141157 cy . findByText ( `${ name } _copy_1` ) . should ( 'exist' ) ;
142158} ;
143159
144- const copyToCatalogueCategory = ( values : { checkedCategories : string [ ] } ) => {
160+ const copyToCatalogueCategory = ( values : {
161+ checkedCategories : { name : string ; index : number } [ ] ;
162+ } ) => {
145163 for ( let i = 0 ; i < values . checkedCategories . length ; i ++ ) {
146- cy . findByLabelText ( ` ${ values . checkedCategories [ i ] } checkbox` ) . click ( ) ;
164+ cy . findAllByRole ( 'checkbox' , { name : 'Toggle select card' } ) . eq ( i ) . click ( ) ;
147165 }
148166 cy . findByRole ( 'button' , { name : 'Copy to' } ) . click ( ) ;
149167 cy . findByRole ( 'button' , { name : 'navigate to catalogue home' } ) . click ( ) ;
@@ -153,14 +171,17 @@ const copyToCatalogueCategory = (values: { checkedCategories: string[] }) => {
153171 cy . findByRole ( 'button' , { name : 'navigate to catalogue home' } ) . click ( ) ;
154172
155173 for ( let i = 0 ; i < values . checkedCategories . length ; i ++ ) {
156- cy . findByText ( `${ values . checkedCategories [ i ] } ` ) . should ( 'exist' ) ;
157- deleteCatalogueCategory ( `${ values . checkedCategories [ i ] } ` ) ;
174+ cy . findByText ( `${ values . checkedCategories [ i ] . name } ` ) . should ( 'exist' ) ;
175+ deleteCatalogueCategory (
176+ `${ values . checkedCategories [ i ] . name } ` ,
177+ values . checkedCategories [ i ] . index
178+ ) ;
158179 }
159180} ;
160181
161182const moveToCatalogueCategory = ( values : { checkedCategories : string [ ] } ) => {
162183 for ( let i = 0 ; i < values . checkedCategories . length ; i ++ ) {
163- cy . findByLabelText ( ` ${ values . checkedCategories [ i ] } checkbox` ) . click ( ) ;
184+ cy . findAllByRole ( 'checkbox' , { name : 'Toggle select card' } ) . eq ( i ) . click ( ) ;
164185 }
165186 cy . findByRole ( 'button' , { name : 'Move to' } ) . click ( ) ;
166187 cy . findByRole ( 'button' , { name : 'navigate to catalogue home' } ) . click ( ) ;
@@ -224,27 +245,32 @@ export const editCatalogueCategories = () => {
224245 cy . findByRole ( 'button' , { name : 'navigate to catalogue home' } ) . click ( ) ;
225246 modifyCatalogueCategory ( {
226247 editCatalogueCategoryName : 'Lenses' ,
248+ actionsIndex : 0 ,
227249 name : 'Lenses 2' ,
228250 } ) ;
229251
230252 cy . findByText ( 'Lenses 2' ) . click ( ) ;
231253
232254 modifyCatalogueCategory ( {
233255 editCatalogueCategoryName : 'Spherical Lenses' ,
256+ actionsIndex : 0 ,
234257 name : 'Spherical Lenses 2' ,
235258 } ) ;
236259} ;
237260
238261export const duplicateCatalogueCategories = ( ) => {
239262 cy . findByRole ( 'button' , { name : 'navigate to catalogue home' } ) . click ( ) ;
240- duplicateCatalogueCategory ( 'Lenses 2' ) ;
263+ duplicateCatalogueCategory ( 'Lenses 2' , 0 ) ;
241264 cy . findByText ( 'Lenses 2' ) . click ( ) ;
242- duplicateCatalogueCategory ( 'Spherical Lenses 2' ) ;
265+ duplicateCatalogueCategory ( 'Spherical Lenses 2' , 0 ) ;
243266} ;
244267
245268export const copyToCatalogueCategories = ( ) => {
246269 copyToCatalogueCategory ( {
247- checkedCategories : [ 'Spherical Lenses 2' , 'Spherical Lenses 2_copy_1' ] ,
270+ checkedCategories : [
271+ { name : 'Spherical Lenses 2' , index : 2 } ,
272+ { name : 'Spherical Lenses 2_copy_1' , index : 2 } ,
273+ ] ,
248274 } ) ;
249275} ;
250276
@@ -258,8 +284,8 @@ export const moveToCatalogueCategories = () => {
258284
259285export const deleteCatalogueCategories = ( ) => {
260286 cy . findByRole ( 'button' , { name : 'navigate to catalogue home' } ) . click ( ) ;
261- deleteCatalogueCategory ( 'Spherical Lenses 2' ) ;
262- deleteCatalogueCategory ( 'Spherical Lenses 2_copy_1' ) ;
263- deleteCatalogueCategory ( 'Lenses 2' ) ;
264- deleteCatalogueCategory ( 'Lenses 2_copy_1' ) ;
287+ deleteCatalogueCategory ( 'Lenses 2' , 0 ) ;
288+ deleteCatalogueCategory ( 'Spherical Lenses 2' , 0 ) ;
289+ deleteCatalogueCategory ( 'Lenses 2_copy_1' , 0 ) ;
290+ deleteCatalogueCategory ( 'Spherical Lenses 2_copy_1' , 0 ) ;
265291} ;
0 commit comments