1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-26 01:17:00 +02:00

test: variant edit corner cases (#5998)

This commit is contained in:
Mateusz Kwasniewski 2024-01-23 10:38:31 +01:00 committed by GitHub
parent 0b1d565dad
commit 48ef88b4fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 2 deletions

View File

@ -1,5 +1,5 @@
import { formatAddStrategyApiCode } from 'component/feature/FeatureStrategy/FeatureStrategyCreate/FeatureStrategyCreate';
import { screen, fireEvent } from '@testing-library/react';
import { screen, fireEvent, waitFor } from '@testing-library/react';
import { render } from 'utils/testRenderer';
import { Route, Routes } from 'react-router-dom';
@ -185,6 +185,20 @@ describe('NewFeatureStrategyCreate', () => {
});
expect(screen.getByText(expectedVariantName)).toBeInTheDocument();
const generalSettingsEl = screen.getByText('General');
fireEvent.click(generalSettingsEl);
await waitFor(() => {
const codeSnippet = document.querySelector('pre')?.innerHTML;
const variantNameMatches = (
codeSnippet!.match(new RegExp(expectedVariantName, 'g')) || []
).length;
const metaDataMatches = (codeSnippet!.match(/isValid/g) || [])
.length;
expect(variantNameMatches).toBe(1);
expect(metaDataMatches).toBe(0);
});
});
test('should change variant name after changing tab', async () => {

View File

@ -87,6 +87,7 @@ export const setupUiConfigEndpoint = () => {
flags: {
newStrategyConfiguration: true,
},
unleashUrl: 'example.com',
});
};

View File

@ -18,6 +18,7 @@ import {
setupStrategyEndpoint,
setupUiConfigEndpoint,
} from '../NewFeatureStrategyCreate/featureStrategyFormTestSetup';
import userEvent from '@testing-library/user-event';
const featureName = 'my-new-feature';
const variantName = 'Blue';
@ -123,7 +124,8 @@ describe('NewFeatureStrategyEdit', () => {
});
test('should change general settings', async () => {
const { expectedGroupId, expectedSliderValue } = setupComponent();
const { expectedGroupId, expectedSliderValue, wrapper } =
setupComponent();
await waitFor(() => {
expect(screen.getByText('Gradual rollout')).toBeInTheDocument();
@ -134,12 +136,23 @@ describe('NewFeatureStrategyEdit', () => {
expect(slider).toHaveValue('50');
expect(groupIdInput).toHaveValue(featureName);
const defaultStickiness = await screen.findByText('default');
userEvent.click(defaultStickiness);
const randomStickiness = await screen.findByText('random');
userEvent.click(randomStickiness);
fireEvent.change(slider, { target: { value: expectedSliderValue } });
fireEvent.change(groupIdInput, { target: { value: expectedGroupId } });
expect(slider).toHaveValue(expectedSliderValue);
expect(groupIdInput).toHaveValue(expectedGroupId);
await waitFor(() => {
const codeSnippet = document.querySelector('pre')?.innerHTML;
const count = (codeSnippet!.match(/random/g) || []).length;
// strategy stickiness and variant stickiness
expect(count).toBe(2);
});
});
test('should not change variant names', async () => {