1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-04 11:17:02 +02:00

test: strategy variant tests in CRs (#8873)

This commit is contained in:
Mateusz Kwasniewski 2024-11-27 16:19:56 +01:00 committed by GitHub
parent eaca09b35a
commit 303711abeb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 183 additions and 96 deletions

View File

@ -269,9 +269,7 @@ test('Displays feature strategy variants table when addStrategy action with vari
}, },
); );
expect( await screen.findByText('Setting strategy variants to:');
screen.getByText('Updating feature variants to:'),
).toBeInTheDocument();
}); });
test('Displays feature strategy variants table when there is a change in the variants array', async () => { 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
route: '/projects/default/change-requests/27', route: '/projects/default/change-requests/27',
}, },
); );
await screen.findByText('Updating feature variants to:'); await screen.findByText('Updating strategy variants to:');
}); });
test('Displays feature strategy variants table when existing strategy does not have variants and change does', async () => { 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
route: '/projects/default/change-requests/27', route: '/projects/default/change-requests/27',
}, },
); );
await screen.findByText('Updating feature variants to:'); await screen.findByText('Updating strategy variants to:');
}); });

View File

@ -3,6 +3,7 @@ import { StrategyChange } from './StrategyChange';
import { testServerRoute, testServerSetup } from 'utils/testServer'; import { testServerRoute, testServerSetup } from 'utils/testServer';
import { screen } from '@testing-library/react'; import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event'; import userEvent from '@testing-library/user-event';
import { Route, Routes } from 'react-router-dom';
const server = testServerSetup(); const server = testServerSetup();
@ -33,9 +34,18 @@ const setupApi = () => {
environments: [ environments: [
{ {
name: environmentName, name: environmentName,
strategies: [ strategies: [
{ {
...strategy, ...strategy,
variants: [
{
name: 'current_variant',
weight: 1000,
stickiness: 'default',
weightType: 'variable' as const,
},
],
title: 'current_title', title: 'current_title',
parameters: { parameters: {
...strategy.parameters, ...strategy.parameters,
@ -53,6 +63,10 @@ beforeEach(setupApi);
test('Editing strategy before change request is applied diffs against current strategy', async () => { test('Editing strategy before change request is applied diffs against current strategy', async () => {
render( render(
<Routes>
<Route
path='/projects/:projectId'
element={
<StrategyChange <StrategyChange
featureName={feature} featureName={feature}
environmentName={environmentName} environmentName={environmentName}
@ -63,6 +77,14 @@ test('Editing strategy before change request is applied diffs against current st
id: 1, id: 1,
payload: { payload: {
...strategy, ...strategy,
variants: [
{
name: 'change_variant',
weight: 1000,
stickiness: 'default',
weightType: 'variable' as const,
},
],
title: 'change_request_title', title: 'change_request_title',
parameters: { parameters: {
...strategy.parameters, ...strategy.parameters,
@ -78,7 +100,11 @@ test('Editing strategy before change request is applied diffs against current st
}, },
}, },
}} }}
/>, />
}
/>
</Routes>,
{ route: `/projects/${projectId}` },
); );
await screen.findByText('Editing strategy:'); await screen.findByText('Editing strategy:');
@ -89,11 +115,19 @@ test('Editing strategy before change request is applied diffs against current st
const viewDiff = await screen.findByText('View Diff'); const viewDiff = await screen.findByText('View Diff');
await userEvent.hover(viewDiff); await userEvent.hover(viewDiff);
await screen.findByText(`- parameters.rollout: "${currentRollout}"`); await screen.findByText(`- parameters.rollout: "${currentRollout}"`);
await screen.findByText(`+ parameters.rollout: "${changeRequestRollout}"`); await screen.findByText('- variants.0.name: "current_variant"');
await screen.findByText('+ variants.0.name: "change_variant"');
await screen.findByText('Updating strategy variants to:');
await screen.findByText('change_variant');
}); });
test('Editing strategy after change request is applied diffs against the snapshot', async () => { test('Editing strategy after change request is applied diffs against the snapshot', async () => {
render( render(
<Routes>
<Route
path='/projects/:projectId'
element={
<StrategyChange <StrategyChange
featureName='my_feature' featureName='my_feature'
environmentName='production' environmentName='production'
@ -109,8 +143,24 @@ test('Editing strategy after change request is applied diffs against the snapsho
...strategy.parameters, ...strategy.parameters,
rollout: changeRequestRollout, rollout: changeRequestRollout,
}, },
variants: [
{
name: 'change_variant',
weight: 1000,
stickiness: 'default',
weightType: 'variable' as const,
},
],
snapshot: { snapshot: {
...strategy, ...strategy,
variants: [
{
name: 'snapshot_variant',
weight: 1000,
stickiness: 'default',
weightType: 'variable' as const,
},
],
title: 'snapshot_title', title: 'snapshot_title',
parameters: { parameters: {
...strategy.parameters, ...strategy.parameters,
@ -119,7 +169,11 @@ test('Editing strategy after change request is applied diffs against the snapsho
}, },
}, },
}} }}
/>, />
}
/>
</Routes>,
{ route: `/projects/${projectId}` },
); );
await screen.findByText('Editing strategy:'); await screen.findByText('Editing strategy:');
@ -131,10 +185,19 @@ test('Editing strategy after change request is applied diffs against the snapsho
await userEvent.hover(viewDiff); await userEvent.hover(viewDiff);
await screen.findByText(`- parameters.rollout: "${snapshotRollout}"`); await screen.findByText(`- parameters.rollout: "${snapshotRollout}"`);
await screen.findByText(`+ parameters.rollout: "${changeRequestRollout}"`); await screen.findByText(`+ parameters.rollout: "${changeRequestRollout}"`);
await screen.findByText('- variants.0.name: "snapshot_variant"');
await screen.findByText('+ variants.0.name: "change_variant"');
await screen.findByText('Updating strategy variants to:');
await screen.findByText('change_variant');
}); });
test('Deleting strategy before change request is applied diffs against current strategy', async () => { test('Deleting strategy before change request is applied diffs against current strategy', async () => {
render( render(
<Routes>
<Route
path='/projects/:projectId'
element={
<StrategyChange <StrategyChange
featureName={feature} featureName={feature}
environmentName={environmentName} environmentName={environmentName}
@ -148,7 +211,11 @@ test('Deleting strategy before change request is applied diffs against current s
name: strategy.name, name: strategy.name,
}, },
}} }}
/>, />
}
/>
</Routes>,
{ route: `/projects/${projectId}` },
); );
await screen.findByText('- Deleting strategy:'); await screen.findByText('- Deleting strategy:');
@ -158,10 +225,17 @@ test('Deleting strategy before change request is applied diffs against current s
const viewDiff = await screen.findByText('View Diff'); const viewDiff = await screen.findByText('View Diff');
await userEvent.hover(viewDiff); await userEvent.hover(viewDiff);
await screen.findByText('- constraints (deleted)'); await screen.findByText('- constraints (deleted)');
await screen.findByText('Deleting strategy variants:');
await screen.findByText('current_variant');
}); });
test('Deleting strategy after change request is applied diffs against the snapshot', async () => { test('Deleting strategy after change request is applied diffs against the snapshot', async () => {
render( render(
<Routes>
<Route
path='/projects/:projectId'
element={
<StrategyChange <StrategyChange
featureName={feature} featureName={feature}
environmentName={environmentName} environmentName={environmentName}
@ -175,6 +249,14 @@ test('Deleting strategy after change request is applied diffs against the snapsh
// name is gone // name is gone
snapshot: { snapshot: {
...strategy, ...strategy,
variants: [
{
name: 'snapshot_variant',
weight: 1000,
stickiness: 'default',
weightType: 'variable' as const,
},
],
title: 'snapshot_title', title: 'snapshot_title',
parameters: { parameters: {
...strategy.parameters, ...strategy.parameters,
@ -183,7 +265,11 @@ test('Deleting strategy after change request is applied diffs against the snapsh
}, },
}, },
}} }}
/>, />
}
/>
</Routes>,
{ route: `/projects/${projectId}` },
); );
await screen.findByText('- Deleting strategy:'); await screen.findByText('- Deleting strategy:');
@ -194,4 +280,7 @@ test('Deleting strategy after change request is applied diffs against the snapsh
const viewDiff = await screen.findByText('View Diff'); const viewDiff = await screen.findByText('View Diff');
await userEvent.hover(viewDiff); await userEvent.hover(viewDiff);
await screen.findByText('- constraints (deleted)'); await screen.findByText('- constraints (deleted)');
await screen.findByText('Deleting strategy variants:');
await screen.findByText('snapshot_variant');
}); });

View File

@ -255,7 +255,7 @@ const UpdateStrategy: FC<{
show={ show={
<StyledBox> <StyledBox>
<StyledTypography> <StyledTypography>
Updating feature variants to: Updating strategy variants to:
</StyledTypography> </StyledTypography>
<EnvironmentVariantsTable <EnvironmentVariantsTable
variants={change.payload.variants || []} variants={change.payload.variants || []}
@ -330,7 +330,7 @@ export const StrategyChange: FC<{
change.payload.variants.length > 0 && ( change.payload.variants.length > 0 && (
<StyledBox> <StyledBox>
<StyledTypography> <StyledTypography>
Updating feature variants to: Setting strategy variants to:
</StyledTypography> </StyledTypography>
<EnvironmentVariantsTable <EnvironmentVariantsTable
variants={change.payload.variants} variants={change.payload.variants}