mirror of
https://github.com/outline/outline.git
synced 2026-12-06 11:12:32 +03:00
* fix: Correct logic errors in shared utilities * fix: Restore per-column cells in getCellsInRow and convert every attachment url The g flag made the attachment regex skip every second match, and removing duplicate cells broke callers that index getCellsInRow by column. * test: Cover uppercase attachment URLs * revert: Remove uncertain fixes
121 lines
3.0 KiB
TypeScript
121 lines
3.0 KiB
TypeScript
import type { ProsemirrorData } from "../../types";
|
|
import {
|
|
getNameFromEmoji,
|
|
getEmojiFromName,
|
|
loadEmojiData,
|
|
parseReactionShorthand,
|
|
snakeCase,
|
|
} from "./emoji";
|
|
|
|
beforeAll(async () => {
|
|
await loadEmojiData();
|
|
});
|
|
|
|
describe("getNameFromEmoji", () => {
|
|
it("returns the correct shortcode", () => {
|
|
expect(getNameFromEmoji("🤔")).toBe("thinking_face");
|
|
});
|
|
});
|
|
|
|
describe("snakeCase", () => {
|
|
it("converts kebab case to snake case for consecutive segments", () => {
|
|
expect(snakeCase("a-b-c")).toBe("a_b_c");
|
|
expect(snakeCase("thinking-face")).toBe("thinking_face");
|
|
expect(snakeCase("no-dash")).toBe("no_dash");
|
|
});
|
|
});
|
|
|
|
describe("getEmojiFromName", () => {
|
|
it("returns the correct native character", () => {
|
|
expect(getEmojiFromName("thinking_face")).toBe("🤔");
|
|
});
|
|
});
|
|
|
|
describe("parseReactionShorthand", () => {
|
|
const doc = (content: ProsemirrorData[]): ProsemirrorData => ({
|
|
type: "doc",
|
|
content,
|
|
});
|
|
|
|
const paragraph = (content: ProsemirrorData[]): ProsemirrorData => ({
|
|
type: "paragraph",
|
|
content,
|
|
});
|
|
|
|
const text = (value: string): ProsemirrorData => ({
|
|
type: "text",
|
|
text: value,
|
|
});
|
|
|
|
const emoji = (name: string): ProsemirrorData => ({
|
|
type: "emoji",
|
|
attrs: { "data-name": name },
|
|
});
|
|
|
|
it("resolves a '+' followed by an emoji node", () => {
|
|
expect(
|
|
parseReactionShorthand(doc([paragraph([text("+"), emoji("thumbs_up")])]))
|
|
).toBe("👍");
|
|
});
|
|
|
|
it("ignores whitespace between the '+' and the emoji node", () => {
|
|
expect(
|
|
parseReactionShorthand(
|
|
doc([paragraph([text("+"), text(" "), emoji("thinking_face")])])
|
|
)
|
|
).toBe("🤔");
|
|
});
|
|
|
|
it("resolves a custom emoji UUID to its UUID", () => {
|
|
const uuid = "550e8400-e29b-41d4-a716-446655440000";
|
|
expect(
|
|
parseReactionShorthand(doc([paragraph([text("+"), emoji(uuid)])]))
|
|
).toBe(uuid);
|
|
});
|
|
|
|
it("resolves literal '+:shortcode:' text", () => {
|
|
expect(
|
|
parseReactionShorthand(doc([paragraph([text("+:thinking_face:")])]))
|
|
).toBe("🤔");
|
|
});
|
|
|
|
it("returns undefined for an unknown shortcode", () => {
|
|
expect(
|
|
parseReactionShorthand(
|
|
doc([paragraph([text("+"), emoji("not_an_emoji")])])
|
|
)
|
|
).toBeUndefined();
|
|
});
|
|
|
|
it("returns undefined when there is text alongside the emoji", () => {
|
|
expect(
|
|
parseReactionShorthand(
|
|
doc([paragraph([text("+ nice "), emoji("thumbs_up")])])
|
|
)
|
|
).toBeUndefined();
|
|
});
|
|
|
|
it("returns undefined for a regular comment", () => {
|
|
expect(
|
|
parseReactionShorthand(doc([paragraph([text("Looks good to me")])]))
|
|
).toBeUndefined();
|
|
});
|
|
|
|
it("returns undefined when the '+' prefix is missing", () => {
|
|
expect(
|
|
parseReactionShorthand(doc([paragraph([emoji("thumbs_up")])]))
|
|
).toBeUndefined();
|
|
});
|
|
|
|
it("returns undefined for multiple paragraphs", () => {
|
|
expect(
|
|
parseReactionShorthand(
|
|
doc([
|
|
paragraph([text("+"), emoji("thumbs_up")]),
|
|
paragraph([text("more")]),
|
|
])
|
|
)
|
|
).toBeUndefined();
|
|
});
|
|
});
|