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,32 +63,48 @@ 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(
<StrategyChange <Routes>
featureName={feature} <Route
environmentName={environmentName} path='/projects/:projectId'
projectId={projectId} element={
changeRequestState='Approved' <StrategyChange
change={{ featureName={feature}
action: 'updateStrategy', environmentName={environmentName}
id: 1, projectId={projectId}
payload: { changeRequestState='Approved'
...strategy, change={{
title: 'change_request_title', action: 'updateStrategy',
parameters: { id: 1,
...strategy.parameters, payload: {
rollout: changeRequestRollout, ...strategy,
}, variants: [
snapshot: { {
...strategy, name: 'change_variant',
title: 'snapshot_title', weight: 1000,
parameters: { stickiness: 'default',
...strategy.parameters, weightType: 'variable' as const,
rollout: snapshotRollout, },
}, ],
}, title: 'change_request_title',
}, parameters: {
}} ...strategy.parameters,
/>, rollout: changeRequestRollout,
},
snapshot: {
...strategy,
title: 'snapshot_title',
parameters: {
...strategy.parameters,
rollout: snapshotRollout,
},
},
},
}}
/>
}
/>
</Routes>,
{ route: `/projects/${projectId}` },
); );
await screen.findByText('Editing strategy:'); await screen.findByText('Editing strategy:');
@ -89,37 +115,65 @@ 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(
<StrategyChange <Routes>
featureName='my_feature' <Route
environmentName='production' path='/projects/:projectId'
projectId='default' element={
changeRequestState='Applied' <StrategyChange
change={{ featureName='my_feature'
action: 'updateStrategy', environmentName='production'
id: 1, projectId='default'
payload: { changeRequestState='Applied'
...strategy, change={{
title: 'change_request_title', action: 'updateStrategy',
parameters: { id: 1,
...strategy.parameters, payload: {
rollout: changeRequestRollout, ...strategy,
}, title: 'change_request_title',
snapshot: { parameters: {
...strategy, ...strategy.parameters,
title: 'snapshot_title', rollout: changeRequestRollout,
parameters: { },
...strategy.parameters, variants: [
rollout: snapshotRollout, {
}, name: 'change_variant',
}, weight: 1000,
}, stickiness: 'default',
}} weightType: 'variable' as const,
/>, },
],
snapshot: {
...strategy,
variants: [
{
name: 'snapshot_variant',
weight: 1000,
stickiness: 'default',
weightType: 'variable' as const,
},
],
title: 'snapshot_title',
parameters: {
...strategy.parameters,
rollout: snapshotRollout,
},
},
},
}}
/>
}
/>
</Routes>,
{ route: `/projects/${projectId}` },
); );
await screen.findByText('Editing strategy:'); await screen.findByText('Editing strategy:');
@ -131,24 +185,37 @@ 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(
<StrategyChange <Routes>
featureName={feature} <Route
environmentName={environmentName} path='/projects/:projectId'
projectId={projectId} element={
changeRequestState='Approved' <StrategyChange
change={{ featureName={feature}
action: 'deleteStrategy', environmentName={environmentName}
id: 1, projectId={projectId}
payload: { changeRequestState='Approved'
id: strategy.id, change={{
name: strategy.name, action: 'deleteStrategy',
}, id: 1,
}} payload: {
/>, id: strategy.id,
name: strategy.name,
},
}}
/>
}
/>
</Routes>,
{ route: `/projects/${projectId}` },
); );
await screen.findByText('- Deleting strategy:'); await screen.findByText('- Deleting strategy:');
@ -158,32 +225,51 @@ 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(
<StrategyChange <Routes>
featureName={feature} <Route
environmentName={environmentName} path='/projects/:projectId'
projectId={projectId} element={
changeRequestState='Applied' <StrategyChange
change={{ featureName={feature}
action: 'deleteStrategy', environmentName={environmentName}
id: 1, projectId={projectId}
payload: { changeRequestState='Applied'
id: strategy.id, change={{
// name is gone action: 'deleteStrategy',
snapshot: { id: 1,
...strategy, payload: {
title: 'snapshot_title', id: strategy.id,
parameters: { // name is gone
...strategy.parameters, snapshot: {
rollout: snapshotRollout, ...strategy,
}, variants: [
}, {
}, name: 'snapshot_variant',
}} weight: 1000,
/>, stickiness: 'default',
weightType: 'variable' as const,
},
],
title: 'snapshot_title',
parameters: {
...strategy.parameters,
rollout: snapshotRollout,
},
},
},
}}
/>
}
/>
</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}