You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
2 years ago
|
import { getNameInitial } from "../clients";
|
||
5 years ago
|
|
||
|
describe("getClientInitials", () => {
|
||
|
it("returns substring if one name provided", () => {
|
||
2 years ago
|
expect(getNameInitial("Alan")).toBe("A");
|
||
5 years ago
|
});
|
||
|
|
||
|
it("returns initials", () => {
|
||
2 years ago
|
expect(getNameInitial("John Doe")).toBe("J");
|
||
5 years ago
|
});
|
||
|
|
||
|
it("returns correct initials if many names provided", () => {
|
||
2 years ago
|
expect(getNameInitial("John Alan Doe")).toBe("J");
|
||
5 years ago
|
});
|
||
|
|
||
|
it("returns single initial if 1 letter provided", () => {
|
||
2 years ago
|
expect(getNameInitial("z")).toBe("Z");
|
||
5 years ago
|
});
|
||
|
|
||
|
it("trims trailing whitespace", () => {
|
||
2 years ago
|
expect(getNameInitial(" q ")).toBe("Q");
|
||
5 years ago
|
});
|
||
|
|
||
|
it('returns "?" if falsey value provided', () => {
|
||
2 years ago
|
expect(getNameInitial("")).toBe("?");
|
||
|
expect(getNameInitial(undefined)).toBe("?");
|
||
|
expect(getNameInitial(null)).toBe("?");
|
||
5 years ago
|
});
|
||
2 years ago
|
|
||
|
it('returns "?" when value is blank', () => {
|
||
2 years ago
|
expect(getNameInitial(" ")).toBe("?");
|
||
|
});
|
||
|
|
||
|
it("works with multibyte strings", () => {
|
||
|
expect(getNameInitial("😀")).toBe("😀");
|
||
|
// but doesn't work with emoji ZWJ sequences
|
||
|
expect(getNameInitial("👨👩👦")).toBe("👨");
|
||
2 years ago
|
});
|
||
5 years ago
|
});
|