File size: 1,312 Bytes
689359a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { render, screen } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import { afterEach, vi } from "vitest"

import { TranscriptPreview } from "./transcript-preview"

afterEach(() => {
  vi.restoreAllMocks()
})

it("opens the full transcript when the preview is truncated", async () => {
  vi.spyOn(HTMLElement.prototype, "clientHeight", "get").mockReturnValue(96)
  vi.spyOn(HTMLElement.prototype, "scrollHeight", "get").mockReturnValue(144)
  const user = userEvent.setup()

  render(<TranscriptPreview text="A long transcript that continues beyond the preview." clipTitle="Launch clip" />)

  await user.click(await screen.findByRole("button", { name: "See more" }))

  expect(screen.getByRole("dialog")).toBeInTheDocument()
  expect(screen.getByRole("heading", { name: "Full transcript" })).toBeInTheDocument()
  expect(screen.getByText("Transcript for Launch clip")).toBeInTheDocument()
})

it("does not show a modal action when the whole transcript fits", () => {
  vi.spyOn(HTMLElement.prototype, "clientHeight", "get").mockReturnValue(96)
  vi.spyOn(HTMLElement.prototype, "scrollHeight", "get").mockReturnValue(96)

  render(<TranscriptPreview text="A short transcript." />)

  expect(screen.queryByRole("button", { name: "See more" })).not.toBeInTheDocument()
})