Skip to content

Commit 372fdb6

Browse files
authored
Merge pull request #254 from Progi1984/boProductsCreateTabDetailsPage
`boProductsCreateTabDetailsPage` : Fixed features
2 parents 3a33e14 + 2033701 commit 372fdb6

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/interfaces/BO/catalog/products/create/tabDetails.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export interface BOProductsCreateTabDetailsPageInterface extends BOBasePagePageI
1212
addNewFile(page: Page, productData: FakerProduct): Promise<void>;
1313
clickOnManageAllFiles(page: Page): Promise<Page>;
1414
clickonManageFeatures(page: Page): Promise<Page>;
15+
countFeatures(page: Page): Promise<number>;
1516
deleteCustomizations(page: Page, productData: FakerProduct): Promise<void>;
16-
deleteFeatures(page: Page, productFeatures: ProductFeatures[]): Promise<void>;
17+
deleteFeatures(page: Page, numFeatures: number): Promise<void>;
1718
deleteFiles(page: Page, productData: FakerProduct): Promise<void>;
1819
getErrorMessageInReferencesForm(page: Page, inputNumber: number): Promise<string>;
1920
getNoFileAttachedMessage(page: Page): Promise<string>;

src/versions/develop/pages/BO/catalog/products/create/tabDetails.ts

+26-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class DetailsTab extends BOBasePage implements BOProductsCreateTabDetailsPageInt
3636

3737
private readonly tableFeatures: string;
3838

39-
private readonly tableFeaturesRow: (nthChild: number) => string;
39+
private readonly tableFeaturesRow: string;
40+
41+
private readonly tableFeaturesRowNth: (nthChild: number) => string;
4042

4143
private readonly tableFeaturesCellAction: (nthChild: number) => string;
4244

@@ -131,8 +133,9 @@ class DetailsTab extends BOBasePage implements BOProductsCreateTabDetailsPageInt
131133
this.deleteFeatureModal = '#modal-confirm-delete-feature-value';
132134
this.confirmDeleteFeatureButton = `${this.deleteFeatureModal} div.modal-footer button.btn-confirm-submit`;
133135
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`;
136139
this.tableFeaturesBtnDelete = (nthChild: number) => `${this.tableFeaturesCellAction(nthChild)} button`;
137140
this.manageFeaturesLink = 'div.product-features-controls + div > a';
138141
// Attached files section
@@ -177,7 +180,14 @@ class DetailsTab extends BOBasePage implements BOProductsCreateTabDetailsPageInt
177180
await this.waitForSelectorAndClick(page, this.detailsTabLink);
178181
await this.setValue(page, this.productReferenceInput, productData.reference);
179182
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+
}
181191
}
182192

183193
/**
@@ -273,8 +283,18 @@ class DetailsTab extends BOBasePage implements BOProductsCreateTabDetailsPageInt
273283
* @param productFeatures {ProductFeatures[]} Data to delete feature
274284
* @returns {Promise<void>}
275285
*/
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++) {
278298
// Why tr:nth-child(2) : It's one-based selector and the first row is hidden ?
279299
await this.waitForSelectorAndClick(page, this.tableFeaturesBtnDelete(2));
280300
await this.waitForSelectorAndClick(page, this.confirmDeleteFeatureButton);

0 commit comments

Comments
 (0)