@@ -3,6 +3,15 @@ import userEvent from "@testing-library/user-event";
33import { describe , it , expect , vi , beforeEach , afterEach } from "vitest" ;
44import ContentExtractor from "@/components/content-extractor" ;
55
6+ function mockText ( markdown : string , meta : Record < string , string > = { } ) {
7+ const entries = Object . entries ( meta ) . filter ( ( [ , v ] ) => v != null ) ;
8+ if ( entries . length === 0 ) return markdown ;
9+ const lines = [ "---" ] ;
10+ for ( const [ k , v ] of entries ) lines . push ( `${ k } : "${ v } "` ) ;
11+ lines . push ( "---" ) ;
12+ return `${ lines . join ( "\n" ) } \n\n${ markdown } ` ;
13+ }
14+
615describe ( "improve-ui spec tests" , ( ) => {
716 beforeEach ( ( ) => {
817 vi . resetAllMocks ( ) ;
@@ -18,10 +27,7 @@ describe("improve-ui spec tests", () => {
1827 const user = userEvent . setup ( ) ;
1928 global . fetch = vi . fn ( ) . mockResolvedValue ( {
2029 ok : true ,
21- json : async ( ) => ( {
22- markdown : "# 긴 콘텐츠\n\n" + "본문 내용이 매우 길어집니다.\n\n" . repeat ( 20 ) ,
23- type : "webpage" ,
24- } ) ,
30+ text : async ( ) => mockText ( "# 긴 콘텐츠\n\n" + "본문 내용이 매우 길어집니다.\n\n" . repeat ( 20 ) ) ,
2531 } as Response ) ;
2632
2733 const { container } = render ( < ContentExtractor /> ) ;
@@ -34,7 +40,6 @@ describe("improve-ui spec tests", () => {
3440 expect ( screen . getByText ( / 긴 콘 텐 츠 / ) ) . toBeInTheDocument ( ) ;
3541 } ) ;
3642
37- // prose 클래스를 가진 컨테이너를 직접 찾아서 확인
3843 const proseContainer = container . querySelector ( ".prose" ) ;
3944 expect ( proseContainer ) . toBeTruthy ( ) ;
4045
@@ -52,12 +57,10 @@ describe("improve-ui spec tests", () => {
5257 const user = userEvent . setup ( ) ;
5358 global . fetch = vi . fn ( ) . mockResolvedValue ( {
5459 ok : true ,
55- json : async ( ) => ( {
56- markdown : "## 자막\n\n" + "자막 내용이 매우 길어집니다.\n\n" . repeat ( 20 ) ,
57- type : "youtube" ,
58- title : "테스트 영상" ,
59- channel : "테스트 채널" ,
60- } ) ,
60+ text : async ( ) => mockText (
61+ "## 자막\n\n" + "자막 내용이 매우 길어집니다.\n\n" . repeat ( 20 ) ,
62+ { title : "테스트 영상" , author : "테스트 채널" , site : "YouTube" }
63+ ) ,
6164 } as Response ) ;
6265
6366 const { container } = render ( < ContentExtractor /> ) ;
@@ -70,7 +73,6 @@ describe("improve-ui spec tests", () => {
7073 expect ( screen . getByText ( "테스트 영상" ) ) . toBeInTheDocument ( ) ;
7174 } ) ;
7275
73- // prose 클래스를 가진 컨테이너를 직접 찾아서 확인
7476 const proseContainer = container . querySelector ( ".prose" ) ;
7577 expect ( proseContainer ) . toBeTruthy ( ) ;
7678
@@ -88,10 +90,7 @@ describe("improve-ui spec tests", () => {
8890 const user = userEvent . setup ( ) ;
8991 global . fetch = vi . fn ( ) . mockResolvedValue ( {
9092 ok : true ,
91- json : async ( ) => ( {
92- markdown : "# 테스트\n\n본문 내용" ,
93- type : "webpage" ,
94- } ) ,
93+ text : async ( ) => mockText ( "# 테스트\n\n본문 내용" ) ,
9594 } as Response ) ;
9695
9796 const { container } = render ( < ContentExtractor /> ) ;
@@ -122,12 +121,10 @@ describe("improve-ui spec tests", () => {
122121 const user = userEvent . setup ( ) ;
123122 global . fetch = vi . fn ( ) . mockResolvedValue ( {
124123 ok : true ,
125- json : async ( ) => ( {
126- markdown : "## 자막\n\n자막 내용" ,
127- type : "youtube" ,
128- title : "테스트 영상" ,
129- channel : "테스트 채널" ,
130- } ) ,
124+ text : async ( ) => mockText (
125+ "## 자막\n\n자막 내용" ,
126+ { title : "테스트 영상" , author : "테스트 채널" , site : "YouTube" }
127+ ) ,
131128 } as Response ) ;
132129
133130 const { container } = render ( < ContentExtractor /> ) ;
@@ -160,20 +157,11 @@ describe("improve-ui spec tests", () => {
160157 it ( "콘텐츠 영역에 max-w-2xl 이상의 클래스가 적용되어 있다" , ( ) => {
161158 const { container } = render ( < ContentExtractor /> ) ;
162159
163- // max-w-2xl(672px) 이상: max-w-2xl, max-w-3xl, max-w-4xl, max-w-5xl, max-w-6xl, max-w-7xl, max-w-full, max-w-screen-*
164160 const wideContainerClasses = [
165- "max-w-2xl" ,
166- "max-w-3xl" ,
167- "max-w-4xl" ,
168- "max-w-5xl" ,
169- "max-w-6xl" ,
170- "max-w-7xl" ,
171- "max-w-full" ,
172- "max-w-screen-sm" ,
173- "max-w-screen-md" ,
174- "max-w-screen-lg" ,
175- "max-w-screen-xl" ,
176- "max-w-screen-2xl" ,
161+ "max-w-2xl" , "max-w-3xl" , "max-w-4xl" , "max-w-5xl" ,
162+ "max-w-6xl" , "max-w-7xl" , "max-w-full" ,
163+ "max-w-screen-sm" , "max-w-screen-md" , "max-w-screen-lg" ,
164+ "max-w-screen-xl" , "max-w-screen-2xl" ,
177165 ] ;
178166
179167 const hasWideContainer = wideContainerClasses . some ( ( cls ) =>
@@ -190,10 +178,7 @@ describe("improve-ui spec tests", () => {
190178 const user = userEvent . setup ( ) ;
191179 global . fetch = vi . fn ( ) . mockResolvedValue ( {
192180 ok : true ,
193- json : async ( ) => ( {
194- markdown : "~~취소선 텍스트~~" ,
195- type : "webpage" ,
196- } ) ,
181+ text : async ( ) => mockText ( "~~취소선 텍스트~~" ) ,
197182 } as Response ) ;
198183
199184 const { container } = render ( < ContentExtractor /> ) ;
@@ -203,11 +188,9 @@ describe("improve-ui spec tests", () => {
203188 await user . click ( screen . getByRole ( "button" , { name : "가져오기" } ) ) ;
204189
205190 await waitFor ( ( ) => {
206- // 마크다운이 렌더링될 때까지 대기
207191 expect ( container . querySelector ( ".prose" ) ) . toBeInTheDocument ( ) ;
208192 } ) ;
209193
210- // 충분한 시간 후 del 요소 확인
211194 await waitFor ( ( ) => {
212195 const delElement = container . querySelector ( "del" ) ;
213196 expect ( delElement ) . toBeInTheDocument ( ) ;
@@ -222,10 +205,7 @@ describe("improve-ui spec tests", () => {
222205 const user = userEvent . setup ( ) ;
223206 global . fetch = vi . fn ( ) . mockResolvedValue ( {
224207 ok : true ,
225- json : async ( ) => ( {
226- markdown : "| 헤더1 | 헤더2 |\n|---|---|\n| 값1 | 값2 |" ,
227- type : "webpage" ,
228- } ) ,
208+ text : async ( ) => mockText ( "| 헤더1 | 헤더2 |\n|---|---|\n| 값1 | 값2 |" ) ,
229209 } as Response ) ;
230210
231211 const { container } = render ( < ContentExtractor /> ) ;
@@ -248,10 +228,7 @@ describe("improve-ui spec tests", () => {
248228 const user = userEvent . setup ( ) ;
249229 global . fetch = vi . fn ( ) . mockResolvedValue ( {
250230 ok : true ,
251- json : async ( ) => ( {
252- markdown : "- [x] 완료\n- [ ] 미완료" ,
253- type : "webpage" ,
254- } ) ,
231+ text : async ( ) => mockText ( "- [x] 완료\n- [ ] 미완료" ) ,
255232 } as Response ) ;
256233
257234 const { container } = render ( < ContentExtractor /> ) ;
@@ -278,10 +255,7 @@ describe("improve-ui spec tests", () => {
278255 const user = userEvent . setup ( ) ;
279256 global . fetch = vi . fn ( ) . mockResolvedValue ( {
280257 ok : true ,
281- json : async ( ) => ( {
282- markdown : "```javascript\nconst x = 1;\n```" ,
283- type : "webpage" ,
284- } ) ,
258+ text : async ( ) => mockText ( "```javascript\nconst x = 1;\n```" ) ,
285259 } as Response ) ;
286260
287261 const { container } = render ( < ContentExtractor /> ) ;
@@ -303,10 +277,7 @@ describe("improve-ui spec tests", () => {
303277 const user = userEvent . setup ( ) ;
304278 global . fetch = vi . fn ( ) . mockResolvedValue ( {
305279 ok : true ,
306- json : async ( ) => ( {
307- markdown : "방문하세요 https://example.com 여기에" ,
308- type : "webpage" ,
309- } ) ,
280+ text : async ( ) => mockText ( "방문하세요 https://example.com 여기에" ) ,
310281 } as Response ) ;
311282
312283 const { container } = render ( < ContentExtractor /> ) ;
@@ -328,10 +299,7 @@ describe("improve-ui spec tests", () => {
328299 const user = userEvent . setup ( ) ;
329300 global . fetch = vi . fn ( ) . mockResolvedValue ( {
330301 ok : true ,
331- json : async ( ) => ( {
332- markdown : "```\nplain text code\n```" ,
333- type : "webpage" ,
334- } ) ,
302+ text : async ( ) => mockText ( "```\nplain text code\n```" ) ,
335303 } as Response ) ;
336304
337305 const { container } = render ( < ContentExtractor /> ) ;
@@ -345,11 +313,9 @@ describe("improve-ui spec tests", () => {
345313 expect ( codeElement ) . toBeInTheDocument ( ) ;
346314 } ) ;
347315
348- // hljs- 클래스가 없어야 함 (rehype-highlight 적용 시 붙는 클래스)
349316 const highlightedCode = container . querySelector ( "code[class*='hljs']" ) ;
350317 expect ( highlightedCode ) . not . toBeInTheDocument ( ) ;
351318
352- // language- 클래스가 없어야 함
353319 const languageCode = container . querySelector ( "code[class*='language-']" ) ;
354320 expect ( languageCode ) . not . toBeInTheDocument ( ) ;
355321 } ) ;
0 commit comments