Skip to content

Commit f8e894a

Browse files
authored
Merge pull request #175 from Progi1984/boFeatureFlagPage
Migrate `@pages/BO/advancedParameters/featureFlag` from Core
2 parents 21d6c23 + 7b61366 commit f8e894a

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export {default as boDesignEmailThemesPreviewPage} from '@pages/BO/design/emailT
209209
export {default as boDesignPositionsPage} from '@pages/BO/design/positions';
210210
export {default as boDesignPositionsHookModulePage} from '@pages/BO/design/positions/hookModule';
211211
export {default as boEmailPage} from '@pages/BO/advancedParameters/email';
212+
export {default as boFeatureFlagPage} from '@pages/BO/advancedParameters/featureFlag';
212213
export {default as boInformationPage} from '@pages/BO/advancedParameters/information';
213214
export {default as boLanguagesPage} from '@pages/BO/international/languages';
214215
export {default as boLanguagesCreatePage} from '@pages/BO/international/languages/create';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {type BOBasePagePageInterface} from '@interfaces/BO';
2+
import {type Page} from '@playwright/test';
3+
4+
export interface BOFeatureFlagInterface extends BOBasePagePageInterface {
5+
readonly featureFlagAdminAPI: string;
6+
readonly pageTitle: string;
7+
8+
setFeatureFlag(page: Page, featureFlag: string, toEnable?: boolean): Promise<string>;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {type BOFeatureFlagInterface} from '@interfaces/BO/advancedParameters/featureFlag';
2+
3+
/* eslint-disable global-require, @typescript-eslint/no-var-requires */
4+
function requirePage(): BOFeatureFlagInterface {
5+
return require('@versions/develop/pages/BO/advancedParameters/featureFlag');
6+
}
7+
/* eslint-enable global-require, @typescript-eslint/no-var-requires */
8+
9+
export default requirePage();
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import {type BOFeatureFlagInterface} from '@interfaces/BO/advancedParameters/featureFlag';
2+
import BOBasePage from '@pages/BO/BOBasePage';
3+
import {type Page} from '@playwright/test';
4+
5+
/**
6+
* Feature flag page, contains functions that can be used on the page
7+
* @class
8+
* @extends BOBasePage
9+
*/
10+
class BOFeatureFlag extends BOBasePage implements BOFeatureFlagInterface {
11+
public readonly pageTitle: string;
12+
13+
public readonly featureFlagAdminAPI: string;
14+
15+
private readonly featureFlagSwitchButton: (status: string, feature: string, toggle: number) => string;
16+
17+
private readonly submitButton: (status: string) => string;
18+
19+
private readonly alertSuccess: string;
20+
21+
private readonly modalSubmitFeatureFlag: string;
22+
23+
private readonly enableExperimentalFeatureButton: string;
24+
25+
/**
26+
* @constructs
27+
* Setting up texts and selectors to use on import page
28+
*/
29+
constructor() {
30+
super();
31+
32+
this.pageTitle = `New & experimental features • ${global.INSTALL.SHOP_NAME}`;
33+
this.successfulUpdateMessage = 'Update successful';
34+
35+
// Feature Flag
36+
this.featureFlagAdminAPI = 'admin_api';
37+
// Selectors
38+
this.featureFlagSwitchButton = (status: string, feature: string, toggle: number) => `#feature_flag_${
39+
status}_feature_flags_${feature}_enabled_${toggle}`;
40+
this.submitButton = (status: string) => `#feature_flag_${status}_submit`;
41+
this.alertSuccess = 'div.alert.alert-success[role="alert"]';
42+
this.modalSubmitFeatureFlag = '#modal-confirm-submit-feature-flag';
43+
this.enableExperimentalFeatureButton = `${this.modalSubmitFeatureFlag} button.btn-confirm-submit`;
44+
}
45+
46+
/**
47+
* Enable/Disable feature flag
48+
* @param page {Page} Browser tab
49+
* @param featureFlag {string}
50+
* @param toEnable {boolean} True if we need to enable new product page
51+
* @returns {Promise<string>}
52+
*/
53+
async setFeatureFlag(page: Page, featureFlag: string, toEnable: boolean = true): Promise<string> {
54+
let isStable: boolean;
55+
56+
switch (featureFlag) {
57+
case this.featureFlagAdminAPI:
58+
isStable = false;
59+
break;
60+
default:
61+
throw new Error(`The feature flag ${featureFlag} is not defined`);
62+
}
63+
64+
const selector: string = this.featureFlagSwitchButton(isStable ? 'stable' : 'beta', featureFlag, toEnable ? 1 : 0);
65+
66+
const isChecked = await this.isChecked(page, selector);
67+
68+
if (isChecked) {
69+
// Return the successful message to simulate all went good (no need to change the value here)
70+
return this.successfulUpdateMessage;
71+
}
72+
73+
await this.setChecked(page, selector);
74+
await this.waitForSelectorAndClick(page, this.submitButton(isStable ? 'stable' : 'beta'));
75+
// The confirmation modal is only displayed for experimental/beta feature flags
76+
if (toEnable && !isStable) {
77+
await this.waitForVisibleSelector(page, this.modalSubmitFeatureFlag);
78+
await this.clickAndWaitForLoadState(page, this.enableExperimentalFeatureButton);
79+
}
80+
81+
return this.getTextContent(page, this.alertSuccess, true);
82+
}
83+
}
84+
85+
module.exports = new BOFeatureFlag();

0 commit comments

Comments
 (0)