Skip to content

Commit 68c384a

Browse files
talissoncostaclaude
andcommitted
test(e2e): add multivariate toggle and change request E2E tests
- Add test for toggling multivariate features via edit modal - Add test for creating and publishing change requests with multivariate features - Add waitForElementVisible before clicking #features-link for reliable navigation - Fix duplicate ID issue in EnvironmentNavbar (scheduling-link vs change-requests-link) - Use Selector().nth(0) for precise element selection in change request list 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 4409923 commit 68c384a

File tree

3 files changed

+122
-8
lines changed

3 files changed

+122
-8
lines changed

frontend/e2e/tests/flag-tests.ts

Lines changed: 120 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
import {
22
byId,
33
click,
4+
clickByText,
45
closeModal,
6+
createEnvironment,
57
createFeature,
68
createRemoteConfig,
79
deleteFeature,
810
editRemoteConfig,
11+
gotoFeatures,
912
log,
1013
login,
1114
parseTryItResults,
15+
setText,
1216
toggleFeature,
1317
waitForElementVisible,
14-
} from '../helpers.cafe';
15-
import { t } from 'testcafe';
16-
import { E2E_USER, PASSWORD } from '../config';
18+
} from '../helpers.cafe'
19+
import { t, Selector } from 'testcafe'
20+
import { E2E_USER, PASSWORD } from '../config'
1721

1822
export default async function () {
1923
log('Login')
2024
await login(E2E_USER, PASSWORD)
2125
await click('#project-select-0')
2226

23-
log('Create Features')
27+
log('Go to features')
28+
await waitForElementVisible('#features-link')
2429
await click('#features-link')
2530

2631
await createRemoteConfig(0, 'header_size', 'big')
@@ -55,7 +60,7 @@ export default async function () {
5560
await t.expect(json.header_enabled.enabled).eql(true)
5661

5762
log('Update feature')
58-
await editRemoteConfig(1,12)
63+
await editRemoteConfig(1, 12)
5964

6065
log('Try it again')
6166
await t.wait(500)
@@ -65,10 +70,10 @@ export default async function () {
6570
await t.expect(json.header_size.value).eql(12)
6671

6772
log('Change feature value to boolean')
68-
await editRemoteConfig(1,false)
73+
await editRemoteConfig(1, false)
6974

7075
log('Try it again 2')
71-
await t.wait(500)
76+
await t.wait(2000)
7277
await click('#try-it-btn')
7378
await t.wait(500)
7479
json = await parseTryItResults()
@@ -81,7 +86,115 @@ export default async function () {
8186
await waitForElementVisible(byId('switch-environment-production-active'))
8287
await waitForElementVisible(byId('feature-switch-0-off'))
8388

89+
log('Switch back to Development environment')
90+
await click(byId('switch-environment-development'))
91+
await waitForElementVisible(byId('switch-environment-development-active'))
92+
8493
log('Clear down features')
8594
await deleteFeature(1, 'header_size')
8695
await deleteFeature(0, 'header_enabled')
96+
await deleteFeature(0, 'mv_flag')
97+
98+
log('Create multivariate feature for toggle test')
99+
await createRemoteConfig(
100+
0,
101+
'mv_toggle_test',
102+
'control',
103+
'MV toggle test',
104+
false,
105+
[
106+
{ value: 'variant_a', weight: 50 },
107+
{ value: 'variant_b', weight: 50 },
108+
],
109+
)
110+
111+
log('Toggle multivariate feature via edit modal')
112+
await gotoFeatures()
113+
await click(byId('feature-switch-0-on'))
114+
await waitForElementVisible('#create-feature-modal')
115+
await click(byId('toggle-feature-button'))
116+
await click(byId('update-feature-btn'))
117+
await closeModal()
118+
await waitForElementVisible(byId('feature-switch-0-off'))
119+
120+
log('Multivariate toggle test passed')
121+
await deleteFeature(0, 'mv_toggle_test')
122+
123+
// Test: Feature Change Request with multivariate feature in isolated environment
124+
log('Create new environment for feature change request test')
125+
await click('#create-env-link')
126+
await createEnvironment('CR Test Env')
127+
128+
log('Enable feature change requests in environment settings')
129+
await waitForElementVisible('#env-settings-link')
130+
await click('#env-settings-link')
131+
132+
// Check if 4_EYES feature is available (plan-based)
133+
const hasFeatureChangeRequests = await Selector(
134+
'[data-test="js-feature-change-requests"]',
135+
).exists
136+
if (!hasFeatureChangeRequests) {
137+
log('Skipping change request test - 4_EYES feature not available')
138+
await click('#features-link')
139+
return
140+
}
141+
142+
await click('[data-test="js-feature-change-requests"]')
143+
await waitForElementVisible('[name="env-name"]')
144+
145+
log('Create multivariate feature for change request test')
146+
await click('#features-link')
147+
await createRemoteConfig(0, 'cr_mv_feature', 'control', null, false, [
148+
{ value: 'variant_a', weight: 50 },
149+
{ value: 'variant_b', weight: 50 },
150+
])
151+
152+
log('Edit multivariate feature to create change request')
153+
await gotoFeatures()
154+
await click(byId('feature-item-0'))
155+
await waitForElementVisible('#create-feature-modal')
156+
await setText(byId('featureValue'), 'updated_value')
157+
await click(byId('update-feature-btn'))
158+
159+
log('Fill change request modal')
160+
await waitForElementVisible('input[placeholder="My Change Request"]')
161+
await setText('input[placeholder="My Change Request"]', 'Test CR')
162+
await click('#confirm-cancel-plan')
163+
164+
log('Close the feature modal')
165+
await closeModal()
166+
167+
log('Navigate to change requests')
168+
await waitForElementVisible(byId('feature-item-0'))
169+
await click('#change-requests-link')
170+
await waitForElementVisible(byId('change-requests-page'))
171+
172+
log('Wait for change request list to load')
173+
await t.wait(2000)
174+
175+
log('Click on the change request')
176+
// Click on the first list item which should be our change request
177+
await t.click(Selector('.list-item.clickable').nth(0))
178+
179+
log('Wait for change request detail page to load')
180+
await t.wait(2000)
181+
182+
log('Publish the change request')
183+
await clickByText('Publish Change', 'button')
184+
await t.wait(500)
185+
await clickByText('OK', 'button')
186+
187+
log('Verify change was published - go back to features')
188+
await t.wait(1000)
189+
await click('#features-link')
190+
await waitForElementVisible(byId('feature-item-0'))
191+
192+
log('Verify the updated value')
193+
await click(byId('feature-item-0'))
194+
await waitForElementVisible('#create-feature-modal')
195+
const featureValue = await Selector(byId('featureValue')).value
196+
await t.expect(featureValue).eql('updated_value')
197+
await closeModal()
198+
199+
log('Change request test passed')
87200
}

frontend/web/components/navigation/navbars/EnvironmentNavbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const EnvironmentNavbar: FC<EnvironmentNavType> = ({
7979
Features
8080
</SidebarLink>
8181
<SidebarLink
82-
id='change-requests-link'
82+
id='scheduling-link'
8383
icon='timer'
8484
to={`/project/${projectId}/environment/${environmentId}/scheduled-changes/`}
8585
>

frontend/web/components/pages/EnvironmentSettingsPage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ const EnvironmentSettingsPage: React.FC = () => {
591591
)}
592592
<FormGroup className='mt-4'>
593593
<ChangeRequestsSetting
594+
data-test='js-feature-change-requests'
594595
feature='4_EYES'
595596
isLoading={saveDisabled}
596597
value={currentEnv?.minimum_change_request_approvals}

0 commit comments

Comments
 (0)