1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01: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(
screen.getByText('Updating feature variants to:'),
).toBeInTheDocument();
await screen.findByText('Setting strategy variants to:');
});
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',
},
);
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 () => {
@ -327,5 +325,5 @@ test('Displays feature strategy variants table when existing strategy does not h
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 { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Route, Routes } from 'react-router-dom';
const server = testServerSetup();
@ -33,9 +34,18 @@ const setupApi = () => {
environments: [
{
name: environmentName,
strategies: [
{
...strategy,
variants: [
{
name: 'current_variant',
weight: 1000,
stickiness: 'default',
weightType: 'variable' as const,
},
],
title: 'current_title',
parameters: {
...strategy.parameters,
@ -53,32 +63,48 @@ beforeEach(setupApi);
test('Editing strategy before change request is applied diffs against current strategy', async () => {
render(
<StrategyChange
featureName={feature}
environmentName={environmentName}
projectId={projectId}
changeRequestState='Approved'
change={{
action: 'updateStrategy',
id: 1,
payload: {
...strategy,
title: 'change_request_title',
parameters: {
...strategy.parameters,
rollout: changeRequestRollout,
},
snapshot: {
...strategy,
title: 'snapshot_title',
parameters: {
...strategy.parameters,
rollout: snapshotRollout,
},
},
},
}}
/>,
<Routes>
<Route
path='/projects/:projectId'
element={
<StrategyChange
featureName={feature}
environmentName={environmentName}
projectId={projectId}
changeRequestState='Approved'
change={{
action: 'updateStrategy',
id: 1,
payload: {
...strategy,
variants: [
{
name: 'change_variant',
weight: 1000,
stickiness: 'default',
weightType: 'variable' as const,
},
],
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:');
@ -89,37 +115,65 @@ test('Editing strategy before change request is applied diffs against current st
const viewDiff = await screen.findByText('View Diff');
await userEvent.hover(viewDiff);
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 () => {
render(
<StrategyChange
featureName='my_feature'
environmentName='production'
projectId='default'
changeRequestState='Applied'
change={{
action: 'updateStrategy',
id: 1,
payload: {
...strategy,
title: 'change_request_title',
parameters: {
...strategy.parameters,
rollout: changeRequestRollout,
},
snapshot: {
...strategy,
title: 'snapshot_title',
parameters: {
...strategy.parameters,
rollout: snapshotRollout,
},
},
},
}}
/>,
<Routes>
<Route
path='/projects/:projectId'
element={
<StrategyChange
featureName='my_feature'
environmentName='production'
projectId='default'
changeRequestState='Applied'
change={{
action: 'updateStrategy',
id: 1,
payload: {
...strategy,
title: 'change_request_title',
parameters: {
...strategy.parameters,
rollout: changeRequestRollout,
},
variants: [
{
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:');
@ -131,24 +185,37 @@ test('Editing strategy after change request is applied diffs against the snapsho
await userEvent.hover(viewDiff);
await screen.findByText(`- parameters.rollout: "${snapshotRollout}"`);
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 () => {
render(
<StrategyChange
featureName={feature}
environmentName={environmentName}
projectId={projectId}
changeRequestState='Approved'
change={{
action: 'deleteStrategy',
id: 1,
payload: {
id: strategy.id,
name: strategy.name,
},
}}
/>,
<Routes>
<Route
path='/projects/:projectId'
element={
<StrategyChange
featureName={feature}
environmentName={environmentName}
projectId={projectId}
changeRequestState='Approved'
change={{
action: 'deleteStrategy',
id: 1,
payload: {
id: strategy.id,
name: strategy.name,
},
}}
/>
}
/>
</Routes>,
{ route: `/projects/${projectId}` },
);
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');
await userEvent.hover(viewDiff);
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 () => {
render(
<StrategyChange
featureName={feature}
environmentName={environmentName}
projectId={projectId}
changeRequestState='Applied'
change={{
action: 'deleteStrategy',
id: 1,
payload: {
id: strategy.id,
// name is gone
snapshot: {
...strategy,
title: 'snapshot_title',
parameters: {
...strategy.parameters,
rollout: snapshotRollout,
},
},
},
}}
/>,
<Routes>
<Route
path='/projects/:projectId'
element={
<StrategyChange
featureName={feature}
environmentName={environmentName}
projectId={projectId}
changeRequestState='Applied'
change={{
action: 'deleteStrategy',
id: 1,
payload: {
id: strategy.id,
// name is gone
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('- 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');
await userEvent.hover(viewDiff);
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={
<StyledBox>
<StyledTypography>
Updating feature variants to:
Updating strategy variants to:
</StyledTypography>
<EnvironmentVariantsTable
variants={change.payload.variants || []}
@ -330,7 +330,7 @@ export const StrategyChange: FC<{
change.payload.variants.length > 0 && (
<StyledBox>
<StyledTypography>
Updating feature variants to:
Setting strategy variants to:
</StyledTypography>
<EnvironmentVariantsTable
variants={change.payload.variants}