Skip to content

Commit

Permalink
test: strategy variant tests in CRs (#8873)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Nov 27, 2024
1 parent eaca09b commit 303711a
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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:');
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand All @@ -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:');
Expand All @@ -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:');
Expand All @@ -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:');
Expand All @@ -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:');
Expand All @@ -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');
});
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const UpdateStrategy: FC<{
show={
<StyledBox>
<StyledTypography>
Updating feature variants to:
Updating strategy variants to:
</StyledTypography>
<EnvironmentVariantsTable
variants={change.payload.variants || []}
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 303711a

Please sign in to comment.