mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-04 01:18:20 +02:00
test: variant edit corner cases (#5998)
This commit is contained in:
parent
0b1d565dad
commit
48ef88b4fa
@ -1,5 +1,5 @@
|
|||||||
import { formatAddStrategyApiCode } from 'component/feature/FeatureStrategy/FeatureStrategyCreate/FeatureStrategyCreate';
|
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 { render } from 'utils/testRenderer';
|
||||||
import { Route, Routes } from 'react-router-dom';
|
import { Route, Routes } from 'react-router-dom';
|
||||||
|
|
||||||
@ -185,6 +185,20 @@ describe('NewFeatureStrategyCreate', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(screen.getByText(expectedVariantName)).toBeInTheDocument();
|
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 () => {
|
test('should change variant name after changing tab', async () => {
|
||||||
|
@ -87,6 +87,7 @@ export const setupUiConfigEndpoint = () => {
|
|||||||
flags: {
|
flags: {
|
||||||
newStrategyConfiguration: true,
|
newStrategyConfiguration: true,
|
||||||
},
|
},
|
||||||
|
unleashUrl: 'example.com',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import {
|
|||||||
setupStrategyEndpoint,
|
setupStrategyEndpoint,
|
||||||
setupUiConfigEndpoint,
|
setupUiConfigEndpoint,
|
||||||
} from '../NewFeatureStrategyCreate/featureStrategyFormTestSetup';
|
} from '../NewFeatureStrategyCreate/featureStrategyFormTestSetup';
|
||||||
|
import userEvent from '@testing-library/user-event';
|
||||||
|
|
||||||
const featureName = 'my-new-feature';
|
const featureName = 'my-new-feature';
|
||||||
const variantName = 'Blue';
|
const variantName = 'Blue';
|
||||||
@ -123,7 +124,8 @@ describe('NewFeatureStrategyEdit', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should change general settings', async () => {
|
test('should change general settings', async () => {
|
||||||
const { expectedGroupId, expectedSliderValue } = setupComponent();
|
const { expectedGroupId, expectedSliderValue, wrapper } =
|
||||||
|
setupComponent();
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(screen.getByText('Gradual rollout')).toBeInTheDocument();
|
expect(screen.getByText('Gradual rollout')).toBeInTheDocument();
|
||||||
@ -134,12 +136,23 @@ describe('NewFeatureStrategyEdit', () => {
|
|||||||
|
|
||||||
expect(slider).toHaveValue('50');
|
expect(slider).toHaveValue('50');
|
||||||
expect(groupIdInput).toHaveValue(featureName);
|
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(slider, { target: { value: expectedSliderValue } });
|
||||||
fireEvent.change(groupIdInput, { target: { value: expectedGroupId } });
|
fireEvent.change(groupIdInput, { target: { value: expectedGroupId } });
|
||||||
|
|
||||||
expect(slider).toHaveValue(expectedSliderValue);
|
expect(slider).toHaveValue(expectedSliderValue);
|
||||||
expect(groupIdInput).toHaveValue(expectedGroupId);
|
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 () => {
|
test('should not change variant names', async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user