@@ -36,7 +36,9 @@ class DetailsTab extends BOBasePage implements BOProductsCreateTabDetailsPageInt
36
36
37
37
private readonly tableFeatures : string ;
38
38
39
- private readonly tableFeaturesRow : ( nthChild : number ) => string ;
39
+ private readonly tableFeaturesRow : string ;
40
+
41
+ private readonly tableFeaturesRowNth : ( nthChild : number ) => string ;
40
42
41
43
private readonly tableFeaturesCellAction : ( nthChild : number ) => string ;
42
44
@@ -131,8 +133,9 @@ class DetailsTab extends BOBasePage implements BOProductsCreateTabDetailsPageInt
131
133
this . deleteFeatureModal = '#modal-confirm-delete-feature-value' ;
132
134
this . confirmDeleteFeatureButton = `${ this . deleteFeatureModal } div.modal-footer button.btn-confirm-submit` ;
133
135
this . tableFeatures = '#product_details_features_feature_collection tbody' ;
134
- this . tableFeaturesRow = ( nthChild : number ) => `${ this . tableFeatures } tr:nth-child(${ nthChild } )` ;
135
- this . tableFeaturesCellAction = ( nthChild : number ) => `${ this . tableFeaturesRow ( nthChild ) } td.feature-actions` ;
136
+ this . tableFeaturesRow = `${ this . tableFeatures } tr` ;
137
+ this . tableFeaturesRowNth = ( nthChild : number ) => `${ this . tableFeaturesRow } :nth-child(${ nthChild } )` ;
138
+ this . tableFeaturesCellAction = ( nthChild : number ) => `${ this . tableFeaturesRowNth ( nthChild ) } td.feature-actions` ;
136
139
this . tableFeaturesBtnDelete = ( nthChild : number ) => `${ this . tableFeaturesCellAction ( nthChild ) } button` ;
137
140
this . manageFeaturesLink = 'div.product-features-controls + div > a' ;
138
141
// Attached files section
@@ -177,7 +180,14 @@ class DetailsTab extends BOBasePage implements BOProductsCreateTabDetailsPageInt
177
180
await this . waitForSelectorAndClick ( page , this . detailsTabLink ) ;
178
181
await this . setValue ( page , this . productReferenceInput , productData . reference ) ;
179
182
await this . setCondition ( page , productData ) ;
180
- await this . setFeature ( page , productData . features ) ;
183
+ if ( productData . features . length > 0 ) {
184
+ const numFeatures = await this . countFeatures ( page ) ;
185
+
186
+ if ( numFeatures ) {
187
+ await this . deleteFeatures ( page , numFeatures ) ;
188
+ }
189
+ await this . setFeature ( page , productData . features ) ;
190
+ }
181
191
}
182
192
183
193
/**
@@ -273,8 +283,18 @@ class DetailsTab extends BOBasePage implements BOProductsCreateTabDetailsPageInt
273
283
* @param productFeatures {ProductFeatures[]} Data to delete feature
274
284
* @returns {Promise<void> }
275
285
*/
276
- async deleteFeatures ( page : Page , productFeatures : ProductFeatures [ ] ) : Promise < void > {
277
- for ( let i : number = 0 ; i < productFeatures . length ; i ++ ) {
286
+ async countFeatures ( page : Page ) : Promise < number > {
287
+ return ( await page . locator ( this . tableFeaturesRow ) . count ( ) ) - 1 ;
288
+ }
289
+
290
+ /**
291
+ * Delete all features
292
+ * @param page {Page} Browser tab
293
+ * @param productFeatures {ProductFeatures[]} Data to delete feature
294
+ * @returns {Promise<void> }
295
+ */
296
+ async deleteFeatures ( page : Page , numFeatures : number ) : Promise < void > {
297
+ for ( let i : number = 0 ; i < numFeatures ; i ++ ) {
278
298
// Why tr:nth-child(2) : It's one-based selector and the first row is hidden ?
279
299
await this . waitForSelectorAndClick ( page , this . tableFeaturesBtnDelete ( 2 ) ) ;
280
300
await this . waitForSelectorAndClick ( page , this . confirmDeleteFeatureButton ) ;
0 commit comments