forked from coracle/flotilla
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import {describe, expect, it} from "vitest"
|
|
import {parseContentTextParts} from "../src/lib/content-text"
|
|
|
|
describe("parseContentTextParts", () => {
|
|
it("parses room references as relay_url'room_id", () => {
|
|
const parts = parseContentTextParts("Join wss://relay.example.com'general now")
|
|
|
|
expect(parts).toHaveLength(3)
|
|
expect(parts[0]).toEqual({type: "text", value: "Join "})
|
|
expect(parts[1]).toMatchObject({
|
|
type: "room",
|
|
value: "wss://relay.example.com'general",
|
|
h: "general",
|
|
})
|
|
expect(parts[2]).toEqual({type: "text", value: " now"})
|
|
})
|
|
|
|
it("parses relay urls as relay parts", () => {
|
|
const parts = parseContentTextParts("Try wss://relay.example.com")
|
|
|
|
expect(parts).toHaveLength(2)
|
|
expect(parts[0]).toEqual({type: "text", value: "Try "})
|
|
expect(parts[1]).toMatchObject({
|
|
type: "relay",
|
|
value: "wss://relay.example.com",
|
|
})
|
|
})
|
|
|
|
it("keeps trailing punctuation outside links", () => {
|
|
const parts = parseContentTextParts("See wss://relay.example.com'chat), thanks")
|
|
|
|
expect(parts).toHaveLength(3)
|
|
expect(parts[0]).toEqual({type: "text", value: "See "})
|
|
expect(parts[1]).toMatchObject({
|
|
type: "room",
|
|
value: "wss://relay.example.com'chat",
|
|
h: "chat",
|
|
})
|
|
expect(parts[2]).toEqual({type: "text", value: "), thanks"})
|
|
})
|
|
|
|
it("leaves non-relay urls as plain text", () => {
|
|
const parts = parseContentTextParts("https://example.com/path")
|
|
|
|
expect(parts).toEqual([{type: "text", value: "https://example.com/path"}])
|
|
})
|
|
}) |