1 import React from "react"
2 import { describe, expect, test, vi } from "vitest"
3 import { render } from "@testing-library/react"
4
5 // mock components
6 vi.mock("@/components/EditDate", () => ({
7 EditDate: ({ date }: { date: string }) => (
8 <div data-testid="edit-date">{date}</div>
9 ),
10 }))
11
12 import { EditButton } from "../../EditButton"
13
14 describe("render", () => {
15 test("renders edit button", () => {
16 const { container } = render(<EditButton filePath="/test.md" />)
17 expect(container).toBeInTheDocument()
18 const editButton = container.querySelector("[data-testid='edit-button']")
19 expect(editButton).toBeInTheDocument()
20 expect(editButton).toHaveTextContent("Edit this page")
21 expect(editButton).toHaveAttribute(
22 "href",
23 "https://github.com/medusajs/medusa/edit/develop/test.md"
24 )
25 })
26
27 test("renders edit button with edit date", () => {
28 const { container } = render(
29 <EditButton filePath="/test.md" editDate="2021-01-01" />
30 )
31 expect(container).toBeInTheDocument()
32 const editDate = container.querySelector("[data-testid='edit-date']")
33 expect(editDate).toBeInTheDocument()
34 expect(editDate).toHaveTextContent("2021-01-01")
35 })
36 })