From 303711abebde3ee5515da53cf7a850b287c7422b Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Wed, 27 Nov 2024 16:19:56 +0100 Subject: [PATCH] test: strategy variant tests in CRs (#8873) --- .../ChangeRequest/ChangeRequest.test.tsx | 8 +- .../Changes/Change/StrategyChange.test.tsx | 267 ++++++++++++------ .../Changes/Change/StrategyChange.tsx | 4 +- 3 files changed, 183 insertions(+), 96 deletions(-) diff --git a/frontend/src/component/changeRequest/ChangeRequest/ChangeRequest.test.tsx b/frontend/src/component/changeRequest/ChangeRequest/ChangeRequest.test.tsx index 6a5618417610..86b041a61d83 100644 --- a/frontend/src/component/changeRequest/ChangeRequest/ChangeRequest.test.tsx +++ b/frontend/src/component/changeRequest/ChangeRequest/ChangeRequest.test.tsx @@ -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:'); }); diff --git a/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/StrategyChange.test.tsx b/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/StrategyChange.test.tsx index 90c7f8a4565f..8a7b94383913 100644 --- a/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/StrategyChange.test.tsx +++ b/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/StrategyChange.test.tsx @@ -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( - , + + + } + /> + , + { 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( - , + + + } + /> + , + { 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( - , + + + } + /> + , + { 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( - , + + + } + /> + , + { 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'); }); diff --git a/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/StrategyChange.tsx b/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/StrategyChange.tsx index 491987040268..47637a3aa970 100644 --- a/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/StrategyChange.tsx +++ b/frontend/src/component/changeRequest/ChangeRequest/Changes/Change/StrategyChange.tsx @@ -255,7 +255,7 @@ const UpdateStrategy: FC<{ show={ - Updating feature variants to: + Updating strategy variants to: 0 && ( - Updating feature variants to: + Setting strategy variants to: