-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-ui.spec.test.tsx
More file actions
138 lines (118 loc) · 4.38 KB
/
Copy pathfix-ui.spec.test.tsx
File metadata and controls
138 lines (118 loc) · 4.38 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { UrlInputSection } from "@/components/url-input-section";
import ContentExtractor from "@/components/content-extractor";
describe("fix-ui spec tests", () => {
beforeEach(() => {
vi.resetAllMocks();
});
// FEEDME-050
describe("FEEDME-050: clear 버튼 표시/숨김 조건", () => {
it("URL 입력창에 텍스트가 있으면 clear 버튼이 표시된다", () => {
render(
<UrlInputSection
url="https://example.com"
loading={false}
error={null}
onUrlChange={vi.fn()}
onErrorClear={vi.fn()}
onFetch={vi.fn()}
/>
);
const clearButton = screen.getByRole("button", { name: "입력 지우기" });
expect(clearButton).toBeInTheDocument();
});
it("URL 입력창이 비어있으면 clear 버튼이 표시되지 않는다", () => {
render(
<UrlInputSection
url=""
loading={false}
error={null}
onUrlChange={vi.fn()}
onErrorClear={vi.fn()}
onFetch={vi.fn()}
/>
);
const clearButton = screen.queryByRole("button", { name: "입력 지우기" });
expect(clearButton).not.toBeInTheDocument();
});
});
// FEEDME-051
describe("FEEDME-051: clear 버튼 클릭 시 URL만 비워지고 프리뷰는 유지된다", () => {
it("clear 버튼 클릭 후 URL이 비워지고 이미 불러온 결과(프리뷰)는 유지된다", async () => {
const user = userEvent.setup();
global.fetch = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({
markdown: "# 테스트 콘텐츠",
title: "테스트 제목",
type: "webpage",
}),
} as Response);
render(<ContentExtractor />);
const input = screen.getByRole("textbox");
await user.type(input, "https://example.com");
await user.click(screen.getByRole("button", { name: "가져오기" }));
await waitFor(() => {
expect(screen.getByRole("button", { name: "복사하기" })).toBeInTheDocument();
});
const clearButton = screen.getByRole("button", { name: "입력 지우기" });
await user.click(clearButton);
expect(input).toHaveValue("");
expect(screen.getByRole("button", { name: "복사하기" })).toBeInTheDocument();
});
});
// FEEDME-052
describe("FEEDME-052: loading 중에는 clear 버튼이 표시되지 않는다", () => {
it("fetch 진행 중(loading=true)에는 clear 버튼이 표시되지 않는다", () => {
render(
<UrlInputSection
url="https://example.com"
loading={true}
error={null}
onUrlChange={vi.fn()}
onErrorClear={vi.fn()}
onFetch={vi.fn()}
/>
);
const clearButton = screen.queryByRole("button", { name: "입력 지우기" });
expect(clearButton).not.toBeInTheDocument();
});
});
// FEEDME-053
describe("FEEDME-053: 에러 상태에서 clear 버튼 클릭 시 URL과 에러 메시지 모두 사라진다", () => {
it("clear 버튼 클릭 시 URL 입력창이 비워지고 에러 메시지도 사라진다", async () => {
const user = userEvent.setup();
const mockOnUrlChange = vi.fn();
const mockOnErrorClear = vi.fn();
const { rerender } = render(
<UrlInputSection
url="https://bad-url.com"
loading={false}
error="잘못된 URL입니다"
onUrlChange={mockOnUrlChange}
onErrorClear={mockOnErrorClear}
onFetch={vi.fn()}
/>
);
expect(screen.getByText("잘못된 URL입니다")).toBeInTheDocument();
const clearButton = screen.getByRole("button", { name: "입력 지우기" });
await user.click(clearButton);
expect(mockOnUrlChange).toHaveBeenCalledWith("");
expect(mockOnErrorClear).toHaveBeenCalled();
rerender(
<UrlInputSection
url=""
loading={false}
error={null}
onUrlChange={mockOnUrlChange}
onErrorClear={mockOnErrorClear}
onFetch={vi.fn()}
/>
);
// 에러 메시지가 사라진다
expect(screen.queryByText("잘못된 URL입니다")).not.toBeInTheDocument();
});
});
});