1- // __tests__/Attendance.test.tsx
2-
31import { render , screen , waitFor , fireEvent } from "@testing-library/react" ;
42import Attendance from "@/components/student-record/category/Attendance" ;
53import axios from "axios" ;
@@ -20,7 +18,6 @@ jest.mock("@/store/selected-date-store", () => ({
2018
2119describe ( "Attendance Component" , ( ) => {
2220 beforeEach ( ( ) => {
23- // store mock 설정
2421 ( useStudentFilterStore as unknown as jest . Mock ) . mockReturnValue ( {
2522 grade : 1 ,
2623 classNumber : 2 ,
@@ -40,8 +37,8 @@ describe("Attendance Component", () => {
4037 jest . clearAllMocks ( ) ;
4138 } ) ;
4239
43- it ( "출결 데이터를 불러오는 동안 로딩 메시지를 보여준다" , async ( ) => {
44- ( axios . get as jest . Mock ) . mockImplementation ( ( ) => new Promise ( ( ) => { } ) ) ; // 무한 대기
40+ it ( "출결 데이터를 불러오는 동안 로딩 메시지를 보여준다" , ( ) => {
41+ ( axios . get as jest . Mock ) . mockImplementation ( ( ) => new Promise ( ( ) => { } ) ) ;
4542
4643 render ( < Attendance /> ) ;
4744 expect ( screen . getByText ( "출결 통계 데이터를 불러오는 중..." ) ) . toBeInTheDocument ( ) ;
@@ -58,7 +55,6 @@ describe("Attendance Component", () => {
5855 } ) ;
5956
6057 it ( "출결 통계를 정상적으로 렌더링한다" , async ( ) => {
61- // summary
6258 ( axios . get as jest . Mock ) . mockImplementation ( ( url : string ) => {
6359 if ( url . includes ( "/summary" ) ) {
6460 return Promise . resolve ( {
@@ -88,11 +84,9 @@ describe("Attendance Component", () => {
8884 } ) ;
8985
9086 render ( < Attendance /> ) ;
91- await waitFor ( ( ) => {
92- expect ( screen . getByText ( "출석" ) ) . toBeInTheDocument ( ) ;
93- expect ( screen . getByText ( "20" ) ) . toBeInTheDocument ( ) ;
94- expect ( screen . getByDisplayValue ( "피드백 내용" ) ) . toBeInTheDocument ( ) ;
95- } ) ;
87+ expect ( await screen . findByText ( "출석" ) ) . toBeInTheDocument ( ) ;
88+ expect ( screen . getByText ( "20" ) ) . toBeInTheDocument ( ) ;
89+ expect ( screen . getByDisplayValue ( "피드백 내용" ) ) . toBeInTheDocument ( ) ;
9690 } ) ;
9791
9892 it ( "피드백이 없을 때 새 피드백을 저장한다 (POST)" , async ( ) => {
@@ -133,11 +127,15 @@ describe("Attendance Component", () => {
133127 } ) ;
134128
135129 render ( < Attendance /> ) ;
136- await waitFor ( ( ) => screen . getByText ( "저장" ) ) ;
130+
131+ const editButton = await screen . findByText ( "수정" ) ;
132+ fireEvent . click ( editButton ) ;
137133
138134 const textarea = screen . getByRole ( "textbox" ) ;
139135 fireEvent . change ( textarea , { target : { value : "새로운 피드백입니다." } } ) ;
140- fireEvent . click ( screen . getByText ( "저장" ) ) ;
136+
137+ const saveButton = screen . getByText ( "저장" ) ;
138+ fireEvent . click ( saveButton ) ;
141139
142140 await waitFor ( ( ) => {
143141 expect ( axios . post ) . toHaveBeenCalled ( ) ;
@@ -177,11 +175,15 @@ describe("Attendance Component", () => {
177175 ( axios . put as jest . Mock ) . mockResolvedValue ( { } ) ;
178176
179177 render ( < Attendance /> ) ;
180- await waitFor ( ( ) => screen . getByText ( "저장" ) ) ;
178+
179+ const editButton = await screen . findByText ( "수정" ) ;
180+ fireEvent . click ( editButton ) ;
181181
182182 const textarea = screen . getByRole ( "textbox" ) ;
183183 fireEvent . change ( textarea , { target : { value : "수정된 피드백" } } ) ;
184- fireEvent . click ( screen . getByText ( "저장" ) ) ;
184+
185+ const saveButton = screen . getByText ( "저장" ) ;
186+ fireEvent . click ( saveButton ) ;
185187
186188 await waitFor ( ( ) => {
187189 expect ( axios . put ) . toHaveBeenCalled ( ) ;
0 commit comments