fleet/frontend/utilities/strings/stringUtils.tests.ts
Gabriel Hernandez 9af2a262cb
change delete host modal and move pluralize util (#16918)
changes the delete host modal copy and moves pluralize to live with
other string utils


![image](https://github.com/fleetdm/fleet/assets/1153709/8b596a7e-3535-4d65-a368-5f301921d256)

- [x] Manual QA for all new/changed functionality
2024-02-21 19:01:01 +00:00

47 lines
1.9 KiB
TypeScript

import { enforceFleetSentenceCasing, pluralize } from "./stringUtils";
describe("string utilities", () => {
describe("enforceFleetSentenceCasing utility", () => {
it("fixes a Title Cased String with no ignore words", () => {
expect(enforceFleetSentenceCasing("All Hosts")).toEqual("All hosts");
expect(enforceFleetSentenceCasing("all Hosts")).toEqual("All hosts");
expect(enforceFleetSentenceCasing("all hosts")).toEqual("All hosts");
expect(enforceFleetSentenceCasing("All HosTs ")).toEqual("All hosts");
});
it("fixes a title cased string while ignoring special words in various places ", () => {
expect(enforceFleetSentenceCasing("macOS")).toEqual("macOS");
expect(enforceFleetSentenceCasing("macOS Settings")).toEqual(
"macOS settings"
);
expect(
enforceFleetSentenceCasing("osquery shouldn't be Capitalized")
).toEqual("osquery shouldn't be capitalized");
});
expect(enforceFleetSentenceCasing("fleet uses MySQL")).toEqual(
"Fleet uses MySQL"
);
});
describe("pluralize utility", () => {
it("returns the singular form of a word when count is 1", () => {
expect(pluralize(1, "hero", "es", "")).toEqual("hero");
});
it("returns the plural form of a word when count is not 1", () => {
expect(pluralize(0, "hero", "es", "")).toEqual("heroes");
expect(pluralize(2, "hero", "es", "")).toEqual("heroes");
expect(pluralize(100, "hero", "es", "")).toEqual("heroes");
});
it("returns the singular form of a word when count is 1 and a no custom suffix are provided", () => {
expect(pluralize(1, "hero")).toEqual("hero");
});
it("returns the pluralized form of a word with 's' suffix when count is not 1 and no custom suffix are provided", () => {
expect(pluralize(0, "hero")).toEqual("heros");
expect(pluralize(2, "hero")).toEqual("heros");
expect(pluralize(100, "hero")).toEqual("heros");
});
});
});