1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

test: playground with dependencies (#4936)

This commit is contained in:
Mateusz Kwasniewski 2023-10-06 09:19:25 +02:00 committed by GitHub
parent b3112b1709
commit bed26a938c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 175 additions and 0 deletions

View File

@ -0,0 +1,95 @@
import { screen } from '@testing-library/react';
import { render } from 'utils/testRenderer';
import React from 'react';
import { FeatureDetails } from './FeatureDetails';
import { PlaygroundFeatureSchema, PlaygroundRequestSchema } from 'openapi';
const testCases = [
{
name: 'Feature has unsatisfied parent dependency and feature environment is disabled',
feature: {
hasUnsatisfiedDependency: true,
isEnabledInCurrentEnvironment: false,
} as PlaygroundFeatureSchema,
expectedText1: 'This feature toggle is False in development because',
expectedText2:
'parent dependency is not satisfied and the environment is disabled',
},
{
name: 'Feature has unsatisfied parent dependency',
feature: {
hasUnsatisfiedDependency: true,
isEnabledInCurrentEnvironment: true,
} as PlaygroundFeatureSchema,
expectedText1: 'This feature toggle is False in development because',
expectedText2: 'parent dependency is not satisfied',
},
{
name: 'Feature environment is disabled',
feature: {
hasUnsatisfiedDependency: false,
isEnabledInCurrentEnvironment: false,
} as PlaygroundFeatureSchema,
expectedText1: 'This feature toggle is False in development because',
expectedText2: 'the environment is disabled',
},
{
name: 'Feature environment is enabled',
feature: {
isEnabled: true,
} as PlaygroundFeatureSchema,
expectedText1: 'This feature toggle is True in development because',
expectedText2: 'at least one strategy is True',
},
{
name: 'Feature has only custom strategies',
feature: {
isEnabledInCurrentEnvironment: true,
strategies: {
data: [{ name: 'custom' }],
},
} as PlaygroundFeatureSchema,
expectedText1: 'This feature toggle is Unknown in development because',
expectedText2: 'no strategies could be fully evaluated',
},
{
name: 'Feature has some custom strategies',
feature: {
isEnabledInCurrentEnvironment: true,
strategies: {
data: [{ name: 'custom' }, { name: 'default' }],
},
} as PlaygroundFeatureSchema,
expectedText1: 'This feature toggle is Unknown in development because',
expectedText2: 'not all strategies could be fully evaluated',
},
{
name: 'Feature has all strategies evaluating to false',
feature: {
isEnabledInCurrentEnvironment: true,
strategies: {
data: [{ name: 'default' }],
},
} as PlaygroundFeatureSchema,
expectedText1: 'This feature toggle is False in development because',
expectedText2:
'all strategies are either False or could not be fully evaluated',
},
];
testCases.forEach(({ name, feature, expectedText1, expectedText2 }) => {
test(name, async () => {
render(
<FeatureDetails
feature={feature}
input={
{ environment: 'development' } as PlaygroundRequestSchema
}
onClose={() => {}}
/>,
);
await screen.findByText(expectedText1);
await screen.findByText(expectedText2);
});
});

View File

@ -0,0 +1,80 @@
import { screen } from '@testing-library/react';
import { render } from 'utils/testRenderer';
import React from 'react';
import { PlaygroundFeatureSchema, PlaygroundRequestSchema } from 'openapi';
import { PlaygroundResultFeatureStrategyList } from './PlaygroundResultFeatureStrategyList';
const testCases = [
{
name: 'Environment not enabled and parent dependency not satisfied',
feature: {
strategies: {
result: true,
data: [
{
name: 'default',
parameters: {},
result: { enabled: true, evaluationStatus: 'complete' },
},
],
},
isEnabledInCurrentEnvironment: false,
hasUnsatisfiedDependency: true,
} as PlaygroundFeatureSchema,
expectedText:
'If environment was enabled and parent dependencies were satisfied, then this feature toggle would be TRUE with strategies evaluated like so:',
},
{
name: 'Environment enabled and parent dependency not satisfied',
feature: {
strategies: {
result: true,
data: [
{
name: 'default',
parameters: {},
result: { enabled: true, evaluationStatus: 'complete' },
},
],
},
isEnabledInCurrentEnvironment: true,
hasUnsatisfiedDependency: true,
} as PlaygroundFeatureSchema,
expectedText:
'If parent dependencies were satisfied, then this feature toggle would be TRUE with strategies evaluated like so:',
},
{
name: 'Environment not enabled and parent dependency satisfied',
feature: {
strategies: {
result: true,
data: [
{
name: 'default',
parameters: {},
result: { enabled: true, evaluationStatus: 'complete' },
},
],
},
isEnabledInCurrentEnvironment: false,
hasUnsatisfiedDependency: false,
} as PlaygroundFeatureSchema,
expectedText:
'If environment was enabled, then this feature toggle would be TRUE with strategies evaluated like so:',
},
];
testCases.forEach(({ name, feature, expectedText }) => {
test(name, async () => {
render(
<PlaygroundResultFeatureStrategyList
feature={feature}
input={
{ environment: 'development' } as PlaygroundRequestSchema
}
/>,
);
await screen.findByText(expectedText);
});
});