|
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/Link", () => ({ |
|
7
|
Link: ({ |
|
8
|
children, |
|
9
|
href, |
|
10
|
className, |
|
11
|
...props |
|
12
|
}: { |
|
13
|
children: React.ReactNode |
|
14
|
href: string |
|
15
|
className?: string |
|
16
|
[key: string]: unknown |
|
17
|
}) => ( |
|
18
|
<a |
|
19
|
href={href} |
|
20
|
className={className} |
|
21
|
data-testid="source-code-link" |
|
22
|
{...props} |
|
23
|
> |
|
24
|
{children} |
|
25
|
</a> |
|
26
|
), |
|
27
|
})) |
|
28
|
|
|
29
|
vi.mock("@/components/Badge", () => ({ |
|
30
|
Badge: ({ children }: { children: React.ReactNode }) => ( |
|
31
|
<div data-testid="source-code-badge">{children}</div> |
|
32
|
), |
|
33
|
})) |
|
34
|
|
|
35
|
vi.mock("@/components/Icons/Github", () => ({ |
|
36
|
GithubIcon: () => <svg data-testid="github-icon" />, |
|
37
|
})) |
|
38
|
|
|
39
|
import { SourceCodeLink } from "../index" |
|
40
|
|
|
41
|
describe("rendering", () => { |
|
42
|
test("renders source code link", () => { |
|
43
|
const { container } = render( |
|
44
|
<SourceCodeLink link="https://github.com/medusajs/medusa" /> |
|
45
|
) |
|
46
|
const link = container.querySelector("[data-testid='source-code-link']") |
|
47
|
expect(link).toBeInTheDocument() |
|
48
|
expect(link).toHaveAttribute("href", "https://github.com/medusajs/medusa") |
|
49
|
const badge = container.querySelector("[data-testid='source-code-badge']") |
|
50
|
expect(badge).toBeInTheDocument() |
|
51
|
expect(badge).toHaveTextContent("Source Code") |
|
52
|
}) |
|
53
|
|
|
54
|
test("renders source code link with text", () => { |
|
55
|
const { container } = render( |
|
56
|
<SourceCodeLink |
|
57
|
link="https://github.com/medusajs/medusa" |
|
58
|
text="Custom Text" |
|
59
|
/> |
|
60
|
) |
|
61
|
const badge = container.querySelector("[data-testid='source-code-badge']") |
|
62
|
expect(badge).toBeInTheDocument() |
|
63
|
expect(badge).toHaveTextContent("Custom Text") |
|
64
|
}) |
|
65
|
|
|
66
|
test("renders source code link with icon", () => { |
|
67
|
const { container } = render( |
|
68
|
<SourceCodeLink |
|
69
|
link="https://github.com/medusajs/medusa" |
|
70
|
icon={<span data-testid="custom-icon">Custom Icon</span>} |
|
71
|
/> |
|
72
|
) |
|
73
|
const icon = container.querySelector("[data-testid='custom-icon']") |
|
74
|
expect(icon).toBeInTheDocument() |
|
75
|
}) |
|
76
|
|
|
77
|
test("renders source code link with custom className", () => { |
|
78
|
const { container } = render( |
|
79
|
<SourceCodeLink |
|
80
|
link="https://github.com/medusajs/medusa" |
|
81
|
className="custom-class" |
|
82
|
/> |
|
83
|
) |
|
84
|
const link = container.querySelector("[data-testid='source-code-link']") |
|
85
|
expect(link).toHaveClass("custom-class") |
|
86
|
}) |
|
87
|
}) |