|
1
|
import React from "react" |
|
2
|
import { beforeEach, describe, expect, test, vi } from "vitest" |
|
3
|
import { cleanup, render } from "@testing-library/react" |
|
4
|
|
|
5
|
// mock hooks |
|
6
|
const mockUseArea = vi.fn(() => ({ |
|
7
|
area: "store", |
|
8
|
})) |
|
9
|
|
|
10
|
// mock components |
|
11
|
vi.mock("@/providers/area", () => ({ |
|
12
|
useArea: () => mockUseArea(), |
|
13
|
})) |
|
14
|
|
|
15
|
import DownloadFull from ".." |
|
16
|
|
|
17
|
beforeEach(() => { |
|
18
|
cleanup() |
|
19
|
vi.clearAllMocks() |
|
20
|
}) |
|
21
|
|
|
22
|
describe("render", () => { |
|
23
|
test("render download link for store area", () => { |
|
24
|
const { getByTestId } = render(<DownloadFull />) |
|
25
|
const link = getByTestId("download-full-link") |
|
26
|
expect(link).toBeInTheDocument() |
|
27
|
expect(link).toHaveAttribute("href", "/download/store") |
|
28
|
expect(link).toHaveAttribute("download") |
|
29
|
expect(link).toHaveAttribute("target", "_blank") |
|
30
|
}) |
|
31
|
|
|
32
|
test("render download link for admin area", () => { |
|
33
|
mockUseArea.mockReturnValue({ area: "admin" }) |
|
34
|
const { getByTestId } = render(<DownloadFull />) |
|
35
|
const link = getByTestId("download-full-link") |
|
36
|
expect(link).toBeInTheDocument() |
|
37
|
expect(link).toHaveAttribute("href", "/download/admin") |
|
38
|
expect(link).toHaveAttribute("download") |
|
39
|
expect(link).toHaveAttribute("target", "_blank") |
|
40
|
}) |
|
41
|
}) |