1- import { act , render , screen } from '@testing-library/react' ;
1+ import { render , screen } from '@testing-library/react' ;
22import { beforeEach , describe , expect , it , vi } from 'vitest' ;
3- import { useTheme } from 'next-themes' ;
43import { GiscusComments } from './GiscusComments' ;
54
65const mockGiscus = vi . fn ( ( _props : Record < string , unknown > ) => (
76 < div data-testid = "giscus-embed" />
87) ) ;
98
10- vi . mock ( 'next-themes' , ( ) => ( {
11- useTheme : vi . fn ( ) ,
12- } ) ) ;
13-
149vi . mock ( '@giscus/react' , ( ) => ( {
1510 default : ( props : unknown ) => mockGiscus ( props ) ,
1611} ) ) ;
@@ -20,30 +15,9 @@ describe('GiscusComments', () => {
2015 mockGiscus . mockClear ( ) ;
2116 } ) ;
2217
23- it ( 'renders section and applies dark theme to iframe when present' , async ( ) => {
24- const postMessage = vi . fn ( ) ;
25-
26- const iframe = document . createElement ( 'iframe' ) ;
27- iframe . className = 'giscus-frame' ;
28- Object . defineProperty ( iframe , 'contentWindow' , {
29- value : {
30- postMessage,
31- } ,
32- configurable : true ,
33- } ) ;
34- document . body . appendChild ( iframe ) ;
35-
36- vi . mocked ( useTheme ) . mockReturnValue ( {
37- theme : 'light' ,
38- resolvedTheme : 'dark' ,
39- } as ReturnType < typeof useTheme > ) ;
40-
18+ it ( 'renders the comment embed with the fixed paper theme' , ( ) => {
4119 render ( < GiscusComments slug = "redis" /> ) ;
4220
43- await act ( async ( ) => {
44- await Promise . resolve ( ) ;
45- } ) ;
46-
4721 expect (
4822 screen . getByRole ( 'heading' , { level : 2 , name : '댓글' } )
4923 ) . toBeInTheDocument ( ) ;
@@ -52,38 +26,8 @@ describe('GiscusComments', () => {
5226 expect . objectContaining ( {
5327 mapping : 'specific' ,
5428 term : 'redis' ,
55- theme : 'dark ' ,
29+ theme : 'light ' ,
5630 } )
5731 ) ;
58- expect ( postMessage ) . toHaveBeenCalledWith (
59- {
60- giscus : {
61- setConfig : {
62- theme : 'dark' ,
63- } ,
64- } ,
65- } ,
66- 'https://giscus.app'
67- ) ;
68-
69- document . body . removeChild ( iframe ) ;
70- } ) ;
71-
72- it ( 'keeps the comment embed mounted when the theme changes' , ( ) => {
73- vi . mocked ( useTheme ) . mockReturnValue ( {
74- theme : 'light' ,
75- resolvedTheme : 'light' ,
76- } as ReturnType < typeof useTheme > ) ;
77-
78- const { rerender } = render ( < GiscusComments slug = "redis" /> ) ;
79- const initialEmbed = screen . getByTestId ( 'giscus-embed' ) ;
80-
81- vi . mocked ( useTheme ) . mockReturnValue ( {
82- theme : 'dark' ,
83- resolvedTheme : 'dark' ,
84- } as ReturnType < typeof useTheme > ) ;
85- rerender ( < GiscusComments slug = "redis" /> ) ;
86-
87- expect ( screen . getByTestId ( 'giscus-embed' ) ) . toBe ( initialEmbed ) ;
8832 } ) ;
8933} ) ;
0 commit comments