* now bookingFields identifier supports - and _ characters but no special characters * fix: unit test --------- Co-authored-by: Amit Sharma <74371312+Amit91848@users.noreply.github.com> Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
43 lines
2.0 KiB
TypeScript
43 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { getValidRhfFieldName } from "./getValidRhfFieldName";
|
|
|
|
describe("getValidRhfFieldName", () => {
|
|
it("should not convert to lowercase", () => {
|
|
expect(getValidRhfFieldName("Hello")).toEqual("Hello");
|
|
expect(getValidRhfFieldName("HELLO")).toEqual("HELLO");
|
|
});
|
|
|
|
it("should convert spaces and any other special character to -", () => {
|
|
expect(getValidRhfFieldName("hello there")).toEqual("hello-there");
|
|
expect(getValidRhfFieldName("hello$there")).toEqual("hello-there");
|
|
expect(getValidRhfFieldName("$hello$there")).toEqual("-hello-there");
|
|
expect(getValidRhfFieldName("$hello.there")).toEqual("-hello-there");
|
|
});
|
|
|
|
// So that user can freely add spaces and any other character iteratively and it get's converted to - and he can add more characters.
|
|
// We don't really care about a hyphen in the end
|
|
it("should not remove dashes from start and end.", () => {
|
|
expect(getValidRhfFieldName("hello-there-")).toEqual("hello-there-");
|
|
expect(getValidRhfFieldName("-hello-there")).toEqual("-hello-there");
|
|
expect(getValidRhfFieldName("$hello-there-")).toEqual("-hello-there-");
|
|
});
|
|
|
|
it("should not remove underscore from start and end.", () => {
|
|
expect(getValidRhfFieldName("hello-there_")).toEqual("hello-there_");
|
|
expect(getValidRhfFieldName("_hello-there_")).toEqual("_hello-there_");
|
|
expect(getValidRhfFieldName("$hello-there_")).toEqual("-hello-there_");
|
|
});
|
|
|
|
it("should remove unicode and emoji characters", () => {
|
|
expect(getValidRhfFieldName("Hello 📚🕯️®️ There")).toEqual("Hello---------There");
|
|
expect(getValidRhfFieldName("📚🕯️®️")).toEqual("-------");
|
|
});
|
|
|
|
it("should keep numbers as is", () => {
|
|
expect(getValidRhfFieldName("hellothere123")).toEqual("hellothere123");
|
|
expect(getValidRhfFieldName("321hello there123")).toEqual("321hello-there123");
|
|
expect(getValidRhfFieldName("hello$there")).toEqual("hello-there");
|
|
});
|
|
});
|