import { test, expect } from "@playwright/test"
import {
  colorForGuestId,
  generateGuestDisplayName,
  isReadableCursorColor,
} from "../lib/drive/guest-editor-identity"
import {
  isRichTextFile,
  sidecarPathForSource,
} from "../lib/drive/richtext-formats"

test.describe("rich text editor helpers", () => {
  test("guest display name uses adjective and animal", () => {
    const name = generateGuestDisplayName()
    const parts = name.split(" ")
    expect(parts.length).toBe(2)
    expect(parts[0]?.length).toBeGreaterThan(0)
    expect(parts[1]?.length).toBeGreaterThan(0)
  })

  test("guest color is stable for same id", () => {
    const a = colorForGuestId("guest-abc")
    const b = colorForGuestId("guest-abc")
    expect(a).toBe(b)
  })

  test("cursor colors are readable with white label text", () => {
    for (let i = 0; i < 20; i++) {
      expect(isReadableCursorColor(colorForGuestId(`guest-${i}`))).toBe(true)
    }
  })

  test("word formats route to rich text", () => {
    expect(isRichTextFile({ name: "rapport.docx" })).toBe(true)
    expect(isRichTextFile({ name: "budget.xlsx" })).toBe(false)
  })

  test("sidecar path preserves folder and basename", () => {
    expect(sidecarPathForSource("/docs/rapport.docx")).toBe("/docs/rapport.ultidoc.json")
  })
})
