1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/component/project/Project/ProjectEnterpriseSettingsForm/validate-feature-naming.test.ts
andreas-unleash c1f8929ddf
fix: separate project and project enterprise settings forms (#4911)
Separates ProjectForm and ProjectEnterpriseSettings forms

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
Co-authored-by: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com>
2023-10-04 10:42:02 +03:00

61 lines
1.9 KiB
TypeScript

import { validateFeatureNamingExample } from './ProjectEnterpriseSettingsForm';
describe('validateFeatureNaming', () => {
test.each(['+', 'valid regex$'])(
`if the featureNamingPatternError prop is present, it's always valid: %s`,
(pattern) => {
const result = validateFeatureNamingExample({
pattern,
example: 'aohutnasoehutns',
featureNamingPatternError: 'error',
});
expect(result.state).toBe('valid');
},
);
test(`if the pattern is empty, the example is always valid`, () => {
const result = validateFeatureNamingExample({
pattern: '',
example: 'aohutnasoehutns',
featureNamingPatternError: undefined,
});
expect(result.state).toBe('valid');
});
test(`if the example is empty, the it's always valid`, () => {
const result = validateFeatureNamingExample({
pattern: '^dx-[a-z]{1,5}$',
example: '',
featureNamingPatternError: undefined,
});
expect(result.state).toBe('valid');
});
test.each([
['valid', 'dx-logs'],
['invalid', 'axe-battles'],
])(
`if example is %s, the state should be be the same`,
(state, example) => {
const result = validateFeatureNamingExample({
pattern: '^dx-[a-z]{1,5}$',
example,
featureNamingPatternError: undefined,
});
expect(result.state).toBe(state);
},
);
test('the pattern gets an implicit leading ^ and trailing $ added', () => {
const result = validateFeatureNamingExample({
pattern: '[a-z]+',
example: 'not.valid',
featureNamingPatternError: undefined,
});
expect(result.state).toBe('invalid');
});
});