@@ -71,27 +71,25 @@ describe('FestivalsPage 테스트', () => {
7171 // Given: AI 추천 데이터가 있을 때
7272 mockLocationState = { requestData : mockRequestData } ;
7373
74- const { container } = render (
74+ render (
7575 < TestWrapper initialEntries = { initialEntriesWithAI } >
7676 < FestivalsPage />
7777 </ TestWrapper > ,
7878 ) ;
7979
80- // Suspense가 끝나고 섹션이 나타날 때까지 기다림
81- await waitFor ( ( ) => {
82- const sections = container . querySelectorAll ( 'section' ) ;
83- expect ( sections . length ) . toBeGreaterThanOrEqual ( 2 ) ;
84- } ) ;
80+ // Suspense fallbacks가 아닌 실제 섹션 제목이 나타날 때까지 대기
81+ await screen . findByRole ( 'heading' , { name : '맞춤 AI Pick 축제' } ) ;
82+ await screen . findByRole ( 'heading' , { name : '지역의 축제' } ) ;
8583
86- const sections = container . querySelectorAll ( 'section' ) ;
87- const [ aiPickSection , festivalsSection ] = sections ;
84+ const aiPickHeading = screen . getByRole ( 'heading' , { name : '맞춤 AI Pick 축제' } ) ;
85+ const aiPickSection = aiPickHeading . closest ( 'section' ) ;
86+ const festivalsHeading = screen . getByRole ( 'heading' , { name : '지역의 축제' } ) ;
87+ const festivalsSection = festivalsHeading . closest ( 'section' ) ;
8888
89- // AI Pick 첫 카드 스냅샷
90- const aiGrid = aiPickSection . querySelector ( '.grid' ) ;
89+ const aiGrid = aiPickSection ?. querySelector ( '.grid' ) ;
9190 expect ( aiGrid ?. children [ 0 ] ) . toMatchSnapshot ( 'ai-pick-first-card' ) ;
9291
93- // Festivals 첫 카드 스냅샷
94- const festivalsGrid = festivalsSection . querySelector ( '.grid' ) ;
92+ const festivalsGrid = festivalsSection ?. querySelector ( '.grid' ) ;
9593 expect ( festivalsGrid ?. children [ 0 ] ) . toMatchSnapshot ( 'festivals-first-card' ) ;
9694 } ) ;
9795
@@ -105,16 +103,12 @@ describe('FestivalsPage 테스트', () => {
105103 </ TestWrapper > ,
106104 ) ;
107105
108- // Suspense가 끝나고 섹션이 나타날 때까지 기다림
109- await waitFor ( ( ) => {
110- const sections = container . querySelectorAll ( 'section' ) ;
111- expect ( sections . length ) . toBeGreaterThanOrEqual ( 1 ) ;
112- } ) ;
106+ // 실제 섹션 제목 로드까지 대기
107+ await screen . findByRole ( 'heading' , { name : '지역의 축제' } ) ;
113108
114109 const sections = container . querySelectorAll ( 'section' ) ;
115110 const [ festivalsSection ] = sections ;
116111
117- // Festivals 첫 카드 스냅샷
118112 const festivalsGrid = festivalsSection . querySelector ( '.grid' ) ;
119113 expect ( festivalsGrid ?. children [ 0 ] ) . toMatchSnapshot ( 'festivals-only-first-card' ) ;
120114 } ) ;
@@ -175,7 +169,7 @@ describe('FestivalsPage 테스트', () => {
175169
176170 // Then: 일반 Festivals 섹션이 로드될 때까지 기다림
177171 await waitFor ( ( ) => {
178- expect ( screen . getByRole ( 'heading' , { name : 'Festivals ' } ) ) . toBeInTheDocument ( ) ;
172+ expect ( screen . getByRole ( 'heading' , { name : '지역의 축제 ' } ) ) . toBeInTheDocument ( ) ;
179173 } ) ;
180174
181175 // AI Pick 제목이 없어야 함
@@ -201,11 +195,12 @@ describe('FestivalsPage 테스트', () => {
201195
202196 // Then: 에러가 발생하지 않고 일반 Festivals 섹션은 표시되어야 한다
203197 await waitFor ( ( ) => {
204- expect ( screen . getByRole ( 'heading' , { name : 'Festivals' } ) ) . toBeInTheDocument ( ) ;
198+ expect ( screen . getByRole ( 'heading' , { name : '지역의 축제' } ) ) . toBeInTheDocument ( ) ;
199+ // AI Pick 섹션은 표시되지 않아야 함
200+ expect (
201+ screen . queryByRole ( 'heading' , { name : '맞춤 AI Pick 축제' } ) ,
202+ ) . not . toBeInTheDocument ( ) ;
205203 } ) ;
206-
207- // AI Pick 섹션은 표시되지 않아야 함
208- expect ( screen . queryByRole ( 'heading' , { name : '맞춤 AI Pick 축제' } ) ) . not . toBeInTheDocument ( ) ;
209204 } ) ;
210205 } ) ;
211206} ) ;
@@ -228,7 +223,7 @@ describe('축제 목록 섹션', () => {
228223 } ) ;
229224
230225 // "Festivals" 섹션을 기준으로 범위를 한정해 중복 매치를 방지한다
231- const festivalsHeading = await screen . findByRole ( 'heading' , { name : 'Festivals ' } ) ;
226+ const festivalsHeading = await screen . findByRole ( 'heading' , { name : '지역의 축제 ' } ) ;
232227 const festivalsSection = festivalsHeading . closest ( 'section' ) ;
233228 expect ( festivalsSection ) . toBeTruthy ( ) ;
234229
@@ -291,7 +286,7 @@ test('로딩 상태가 올바르게 표시된다', async () => {
291286 } ) ;
292287} ) ;
293288
294- test ( 'API 에러 상태가 올바르게 처리된다 (ErrorBoundary가 null을 렌더링 )' , async ( ) => {
289+ test ( 'API 에러 상태가 올바르게 처리된다 (ErrorBoundary가 렌더링되므로 해당 섹션 텍스트가 나타나지 않는다 )' , async ( ) => {
295290 // Given: API 호출이 실패할 때
296291 const getFestivalsMock = await import ( '@/apis/festivals/getFestivals' ) ;
297292 vi . mocked ( getFestivalsMock . default ) . mockRejectedValueOnce ( new Error ( 'API Error' ) ) ;
@@ -302,8 +297,8 @@ test('API 에러 상태가 올바르게 처리된다 (ErrorBoundary가 null을
302297 </ TestWrapper > ,
303298 ) ;
304299
305- // Then: ErrorBoundary가 null을 렌더링하므로 해당 섹션 텍스트가 나타나지 않는다
300+ // Then: ErrorBoundary가 렌더링되므로 해당 섹션 텍스트가 나타나지 않는다
306301 await waitFor ( ( ) => {
307- expect ( screen . queryByText ( 'Festivals ' ) ) . not . toBeInTheDocument ( ) ;
302+ expect ( screen . queryByText ( '지역의 축제 ' ) ) . not . toBeInTheDocument ( ) ;
308303 } ) ;
309304} ) ;
0 commit comments