1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-19 01:17:18 +02:00
unleash.unleash/frontend/src/component/segments/SegmentTable/SegmentTable.test.tsx
Fredrik Strand Oseberg f220f216d6
Fix/legal values deletion (#4564)
This PR fixes a bug reported from a customer where deleting a legal
value that was used in a strategy constraint would make it impossible to
edit the constraint.

[The bug was introduced
here](https://github.com/Unleash/unleash/pull/4473)

The core of the problem introduced was that the values used to calculate
illegal values was based on changing state. On the first render it would
display correct state as it would match the legal values coming from the
context definition with the legal values currently used in the
constraint as values. However, when you triggered the onClick method for
the checkboxes the state would be changed because we would remove the
illegal values from the valueset and only insert current legal values in
the state. This would trigger a re-render of the component, and now the
data used to identify the illegal values would no longer be correct,
because the bad values had been cleaned from the state. This would cause
the UI for constraints to display incorrectly.

Changed the flow to now give you a warning if you have illegal values,
and that if you make changes and save the strategy these values will be
removed from the constraint:

<img width="726" alt="Skjermbilde 2023-08-25 kl 08 56 02"
src="https://github.com/Unleash/unleash/assets/16081982/78e9875d-d864-4e21-bfb7-a530247a07eb">

Also amended this to apply to the single legal value constraints.

<img width="721" alt="Skjermbilde 2023-08-25 kl 08 57 40"
src="https://github.com/Unleash/unleash/assets/16081982/237a11d0-5c05-445c-9e99-b79cab0bff94">
2023-08-25 10:44:00 +02:00

43 lines
1.2 KiB
TypeScript

import { render } from '../../../utils/testRenderer';
import { screen } from '@testing-library/react';
import { SegmentTable } from './SegmentTable';
import { testServerRoute, testServerSetup } from '../../../utils/testServer';
import { UIProviderContainer } from '../../providers/UIProvider/UIProviderContainer';
const server = testServerSetup();
const setupRoutes = () => {
testServerRoute(server, 'api/admin/segments', {
segments: [
{
id: 2,
name: 'test2',
description: '',
usedInProjects: 3,
usedInFeatures: 2,
constraints: [],
createdBy: 'admin',
createdAt: '2023-05-24T06:23:07.797Z',
},
],
});
testServerRoute(server, '/api/admin/ui-config', {
flags: {
SE: true,
},
});
};
test('should show the count of projects and features used in', async () => {
setupRoutes();
render(
<UIProviderContainer>
<SegmentTable />
</UIProviderContainer>
);
await screen.findByText('2 feature toggles');
await screen.findByText('3 projects');
});