kafka-ui/kafka-ui-react-app/src/lib/__test__/yupExtended.spec.ts
Hrant Abrahamyan 94da2f4e7f
[FE] SR: Display a warning in case of invalid syntax (#2599)
* No warning about filling the invalid data in case of editing the Schema / Producing the Message

* fixed test errors

* pull master

* fixed test problems

* use isJsonObject for validation

* fixed protobuf format bug

* fix setNewSchemaValue()

* test commit

* fix BaseTest

* upd global

* upd global

* upd global

* add local browser VM option

* fix TopicsList column header locator

* fix withStartupTimeout()

* switch e2e to TestNG

* upd pom

* upd page classes

* upd -pl kafka-ui-e2e-checks

* test commit

* Revert "test commit"

This reverts commit 4b505321ac.

* fix workflow module

* upd test -f 'kafka-ui-e2e-checks'

* crt firstCase

* upd QaseUtils

* add -Dsuite

* add -Dsuite

* add -Dsuite

* add -Dsuite

* add isSuiteEnabled

* add isSuiteEnabled

* upd workflow

* upd readMe

* upd readMe

* upd readMe

* upd qaseSetup

* upd qaseSetup

* add schedule

* add schedule

* upd suites

* upd suites

* upd suites

* upd json input

* upd onTestStart

* Revert "fix setNewSchemaValue()"

This reverts commit 67d12d1134.

* resolve conflicts

* upd localWebDriver

* added error message

* added ability to check Valid Enum

* swapped key Serde and Value Serde

* replace 'e' with 'enum', also added test cases

---------

Co-authored-by: VladSenyuta <vlad.senyuta@gmail.com>
Co-authored-by: Vlad Senyuta <66071557+VladSenyuta@users.noreply.github.com>
Co-authored-by: davitbejanyan <dbejanyan@provectus.com>
Co-authored-by: David <58771979+David-DB88@users.noreply.github.com>
Co-authored-by: Roman Zabaluev <rzabaluev@provectus.com>
2023-04-10 15:53:31 +04:00

55 lines
1.4 KiB
TypeScript

import { isValidEnum, isValidJsonObject } from 'lib/yupExtended';
const invalidEnum = `
ennum SchemType {
AVRO = 0;
JSON = 1;
PROTOBUF = 3;
}
`;
const validEnum = `
enum SchemType {
AVRO = 0;
JSON = 1;
PROTOBUF = 3;
}
`;
describe('yup extended', () => {
describe('isValidJsonObject', () => {
it('returns false for no value', () => {
expect(isValidJsonObject()).toBeFalsy();
});
it('returns false for invalid string', () => {
expect(isValidJsonObject('foo: bar')).toBeFalsy();
});
it('returns false on parsing error', () => {
JSON.parse = jest.fn().mockImplementationOnce(() => {
throw new Error();
});
expect(isValidJsonObject('{ "foo": "bar" }')).toBeFalsy();
});
it('returns true for valid JSON object', () => {
expect(isValidJsonObject('{ "foo": "bar" }')).toBeTruthy();
});
});
describe('isValidEnum', () => {
it('returns false for invalid enum', () => {
expect(isValidEnum(invalidEnum)).toBeFalsy();
});
it('returns false for no value', () => {
expect(isValidEnum()).toBeFalsy();
});
it('returns true should trim value', () => {
expect(
isValidEnum(` enum SchemType {AVRO = 0; PROTOBUF = 3;} `)
).toBeTruthy();
});
it('returns true for valid enum', () => {
expect(isValidEnum(validEnum)).toBeTruthy();
});
});
});