Skip to content

Commit 303711a

Browse files
authored
test: strategy variant tests in CRs (#8873)
1 parent eaca09b commit 303711a

File tree

3 files changed

+183
-96
lines changed

3 files changed

+183
-96
lines changed

frontend/src/component/changeRequest/ChangeRequest/ChangeRequest.test.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,7 @@ test('Displays feature strategy variants table when addStrategy action with vari
269269
},
270270
);
271271

272-
expect(
273-
screen.getByText('Updating feature variants to:'),
274-
).toBeInTheDocument();
272+
await screen.findByText('Setting strategy variants to:');
275273
});
276274

277275
test('Displays feature strategy variants table when there is a change in the variants array', async () => {
@@ -299,7 +297,7 @@ test('Displays feature strategy variants table when there is a change in the var
299297
route: '/projects/default/change-requests/27',
300298
},
301299
);
302-
await screen.findByText('Updating feature variants to:');
300+
await screen.findByText('Updating strategy variants to:');
303301
});
304302

305303
test('Displays feature strategy variants table when existing strategy does not have variants and change does', async () => {
@@ -327,5 +325,5 @@ test('Displays feature strategy variants table when existing strategy does not h
327325
route: '/projects/default/change-requests/27',
328326
},
329327
);
330-
await screen.findByText('Updating feature variants to:');
328+
await screen.findByText('Updating strategy variants to:');
331329
});

frontend/src/component/changeRequest/ChangeRequest/Changes/Change/StrategyChange.test.tsx

Lines changed: 178 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { StrategyChange } from './StrategyChange';
33
import { testServerRoute, testServerSetup } from 'utils/testServer';
44
import { screen } from '@testing-library/react';
55
import userEvent from '@testing-library/user-event';
6+
import { Route, Routes } from 'react-router-dom';
67

78
const server = testServerSetup();
89

@@ -33,9 +34,18 @@ const setupApi = () => {
3334
environments: [
3435
{
3536
name: environmentName,
37+
3638
strategies: [
3739
{
3840
...strategy,
41+
variants: [
42+
{
43+
name: 'current_variant',
44+
weight: 1000,
45+
stickiness: 'default',
46+
weightType: 'variable' as const,
47+
},
48+
],
3949
title: 'current_title',
4050
parameters: {
4151
...strategy.parameters,
@@ -53,32 +63,48 @@ beforeEach(setupApi);
5363

5464
test('Editing strategy before change request is applied diffs against current strategy', async () => {
5565
render(
56-
<StrategyChange
57-
featureName={feature}
58-
environmentName={environmentName}
59-
projectId={projectId}
60-
changeRequestState='Approved'
61-
change={{
62-
action: 'updateStrategy',
63-
id: 1,
64-
payload: {
65-
...strategy,
66-
title: 'change_request_title',
67-
parameters: {
68-
...strategy.parameters,
69-
rollout: changeRequestRollout,
70-
},
71-
snapshot: {
72-
...strategy,
73-
title: 'snapshot_title',
74-
parameters: {
75-
...strategy.parameters,
76-
rollout: snapshotRollout,
77-
},
78-
},
79-
},
80-
}}
81-
/>,
66+
<Routes>
67+
<Route
68+
path='/projects/:projectId'
69+
element={
70+
<StrategyChange
71+
featureName={feature}
72+
environmentName={environmentName}
73+
projectId={projectId}
74+
changeRequestState='Approved'
75+
change={{
76+
action: 'updateStrategy',
77+
id: 1,
78+
payload: {
79+
...strategy,
80+
variants: [
81+
{
82+
name: 'change_variant',
83+
weight: 1000,
84+
stickiness: 'default',
85+
weightType: 'variable' as const,
86+
},
87+
],
88+
title: 'change_request_title',
89+
parameters: {
90+
...strategy.parameters,
91+
rollout: changeRequestRollout,
92+
},
93+
snapshot: {
94+
...strategy,
95+
title: 'snapshot_title',
96+
parameters: {
97+
...strategy.parameters,
98+
rollout: snapshotRollout,
99+
},
100+
},
101+
},
102+
}}
103+
/>
104+
}
105+
/>
106+
</Routes>,
107+
{ route: `/projects/${projectId}` },
82108
);
83109

84110
await screen.findByText('Editing strategy:');
@@ -89,37 +115,65 @@ test('Editing strategy before change request is applied diffs against current st
89115
const viewDiff = await screen.findByText('View Diff');
90116
await userEvent.hover(viewDiff);
91117
await screen.findByText(`- parameters.rollout: "${currentRollout}"`);
92-
await screen.findByText(`+ parameters.rollout: "${changeRequestRollout}"`);
118+
await screen.findByText('- variants.0.name: "current_variant"');
119+
await screen.findByText('+ variants.0.name: "change_variant"');
120+
121+
await screen.findByText('Updating strategy variants to:');
122+
await screen.findByText('change_variant');
93123
});
94124

95125
test('Editing strategy after change request is applied diffs against the snapshot', async () => {
96126
render(
97-
<StrategyChange
98-
featureName='my_feature'
99-
environmentName='production'
100-
projectId='default'
101-
changeRequestState='Applied'
102-
change={{
103-
action: 'updateStrategy',
104-
id: 1,
105-
payload: {
106-
...strategy,
107-
title: 'change_request_title',
108-
parameters: {
109-
...strategy.parameters,
110-
rollout: changeRequestRollout,
111-
},
112-
snapshot: {
113-
...strategy,
114-
title: 'snapshot_title',
115-
parameters: {
116-
...strategy.parameters,
117-
rollout: snapshotRollout,
118-
},
119-
},
120-
},
121-
}}
122-
/>,
127+
<Routes>
128+
<Route
129+
path='/projects/:projectId'
130+
element={
131+
<StrategyChange
132+
featureName='my_feature'
133+
environmentName='production'
134+
projectId='default'
135+
changeRequestState='Applied'
136+
change={{
137+
action: 'updateStrategy',
138+
id: 1,
139+
payload: {
140+
...strategy,
141+
title: 'change_request_title',
142+
parameters: {
143+
...strategy.parameters,
144+
rollout: changeRequestRollout,
145+
},
146+
variants: [
147+
{
148+
name: 'change_variant',
149+
weight: 1000,
150+
stickiness: 'default',
151+
weightType: 'variable' as const,
152+
},
153+
],
154+
snapshot: {
155+
...strategy,
156+
variants: [
157+
{
158+
name: 'snapshot_variant',
159+
weight: 1000,
160+
stickiness: 'default',
161+
weightType: 'variable' as const,
162+
},
163+
],
164+
title: 'snapshot_title',
165+
parameters: {
166+
...strategy.parameters,
167+
rollout: snapshotRollout,
168+
},
169+
},
170+
},
171+
}}
172+
/>
173+
}
174+
/>
175+
</Routes>,
176+
{ route: `/projects/${projectId}` },
123177
);
124178

125179
await screen.findByText('Editing strategy:');
@@ -131,24 +185,37 @@ test('Editing strategy after change request is applied diffs against the snapsho
131185
await userEvent.hover(viewDiff);
132186
await screen.findByText(`- parameters.rollout: "${snapshotRollout}"`);
133187
await screen.findByText(`+ parameters.rollout: "${changeRequestRollout}"`);
188+
await screen.findByText('- variants.0.name: "snapshot_variant"');
189+
await screen.findByText('+ variants.0.name: "change_variant"');
190+
191+
await screen.findByText('Updating strategy variants to:');
192+
await screen.findByText('change_variant');
134193
});
135194

136195
test('Deleting strategy before change request is applied diffs against current strategy', async () => {
137196
render(
138-
<StrategyChange
139-
featureName={feature}
140-
environmentName={environmentName}
141-
projectId={projectId}
142-
changeRequestState='Approved'
143-
change={{
144-
action: 'deleteStrategy',
145-
id: 1,
146-
payload: {
147-
id: strategy.id,
148-
name: strategy.name,
149-
},
150-
}}
151-
/>,
197+
<Routes>
198+
<Route
199+
path='/projects/:projectId'
200+
element={
201+
<StrategyChange
202+
featureName={feature}
203+
environmentName={environmentName}
204+
projectId={projectId}
205+
changeRequestState='Approved'
206+
change={{
207+
action: 'deleteStrategy',
208+
id: 1,
209+
payload: {
210+
id: strategy.id,
211+
name: strategy.name,
212+
},
213+
}}
214+
/>
215+
}
216+
/>
217+
</Routes>,
218+
{ route: `/projects/${projectId}` },
152219
);
153220

154221
await screen.findByText('- Deleting strategy:');
@@ -158,32 +225,51 @@ test('Deleting strategy before change request is applied diffs against current s
158225
const viewDiff = await screen.findByText('View Diff');
159226
await userEvent.hover(viewDiff);
160227
await screen.findByText('- constraints (deleted)');
228+
229+
await screen.findByText('Deleting strategy variants:');
230+
await screen.findByText('current_variant');
161231
});
162232

163233
test('Deleting strategy after change request is applied diffs against the snapshot', async () => {
164234
render(
165-
<StrategyChange
166-
featureName={feature}
167-
environmentName={environmentName}
168-
projectId={projectId}
169-
changeRequestState='Applied'
170-
change={{
171-
action: 'deleteStrategy',
172-
id: 1,
173-
payload: {
174-
id: strategy.id,
175-
// name is gone
176-
snapshot: {
177-
...strategy,
178-
title: 'snapshot_title',
179-
parameters: {
180-
...strategy.parameters,
181-
rollout: snapshotRollout,
182-
},
183-
},
184-
},
185-
}}
186-
/>,
235+
<Routes>
236+
<Route
237+
path='/projects/:projectId'
238+
element={
239+
<StrategyChange
240+
featureName={feature}
241+
environmentName={environmentName}
242+
projectId={projectId}
243+
changeRequestState='Applied'
244+
change={{
245+
action: 'deleteStrategy',
246+
id: 1,
247+
payload: {
248+
id: strategy.id,
249+
// name is gone
250+
snapshot: {
251+
...strategy,
252+
variants: [
253+
{
254+
name: 'snapshot_variant',
255+
weight: 1000,
256+
stickiness: 'default',
257+
weightType: 'variable' as const,
258+
},
259+
],
260+
title: 'snapshot_title',
261+
parameters: {
262+
...strategy.parameters,
263+
rollout: snapshotRollout,
264+
},
265+
},
266+
},
267+
}}
268+
/>
269+
}
270+
/>
271+
</Routes>,
272+
{ route: `/projects/${projectId}` },
187273
);
188274

189275
await screen.findByText('- Deleting strategy:');
@@ -194,4 +280,7 @@ test('Deleting strategy after change request is applied diffs against the snapsh
194280
const viewDiff = await screen.findByText('View Diff');
195281
await userEvent.hover(viewDiff);
196282
await screen.findByText('- constraints (deleted)');
283+
284+
await screen.findByText('Deleting strategy variants:');
285+
await screen.findByText('snapshot_variant');
197286
});

frontend/src/component/changeRequest/ChangeRequest/Changes/Change/StrategyChange.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ const UpdateStrategy: FC<{
255255
show={
256256
<StyledBox>
257257
<StyledTypography>
258-
Updating feature variants to:
258+
Updating strategy variants to:
259259
</StyledTypography>
260260
<EnvironmentVariantsTable
261261
variants={change.payload.variants || []}
@@ -330,7 +330,7 @@ export const StrategyChange: FC<{
330330
change.payload.variants.length > 0 && (
331331
<StyledBox>
332332
<StyledTypography>
333-
Updating feature variants to:
333+
Setting strategy variants to:
334334
</StyledTypography>
335335
<EnvironmentVariantsTable
336336
variants={change.payload.variants}

0 commit comments

Comments
 (0)