11import { describe , it , expect , beforeEach , vi } from "vitest"
22import { renderHook , act } from "@testing-library/react"
33import { usePerformerSeatSelection } from "../usePerformerSeatSelection"
4- import { Seat , Section , SEAT_STATUS } from "@/entities/booking/model/types"
4+ import { Seat , Section , SeatStatus , SEAT_STATUS } from "@/entities/booking/model/types"
55
6- const makeSeat = ( seatNumber : string , section : Section = "A" , status = SEAT_STATUS . AVAILABLE ) : Seat => ( {
6+ const makeSeat = ( seatNumber : string , section : Section = "A" , status : SeatStatus = SEAT_STATUS . AVAILABLE ) : Seat => ( {
77 seatNumber,
88 status,
99 section,
@@ -13,6 +13,28 @@ beforeEach(() => {
1313 vi . clearAllMocks ( )
1414} )
1515
16+ describe ( "usePerformerSeatSelection - 초기 상태" , ( ) => {
17+ it ( "selectedSection의 초기값은 null이다" , ( ) => {
18+ const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 0 ) )
19+ expect ( result . current . selectedSection ) . toBeNull ( )
20+ } )
21+
22+ it ( "selectedSeats의 초기값은 빈 배열이다" , ( ) => {
23+ const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 0 ) )
24+ expect ( result . current . selectedSeats ) . toHaveLength ( 0 )
25+ } )
26+
27+ it ( "isComplete의 초기값은 false다" , ( ) => {
28+ const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 0 ) )
29+ expect ( result . current . isComplete ) . toBe ( false )
30+ } )
31+
32+ it ( "canBook의 초기값은 false다" , ( ) => {
33+ const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 0 ) )
34+ expect ( result . current . canBook ) . toBe ( false )
35+ } )
36+ } )
37+
1638describe ( "usePerformerSeatSelection - maxSelectableSeats" , ( ) => {
1739 it ( "existingSeatsCount가 0이면 최대 3석 선택 가능하다" , ( ) => {
1840 const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 0 ) )
@@ -189,6 +211,65 @@ describe("usePerformerSeatSelection - canBook", () => {
189211 } )
190212} )
191213
214+ describe ( "usePerformerSeatSelection - canSelectSeat" , ( ) => {
215+ it ( "AVAILABLE 좌석은 선택 가능하다" , ( ) => {
216+ const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 0 ) )
217+ expect ( result . current . canSelectSeat ( makeSeat ( "1" , "A" , SEAT_STATUS . AVAILABLE ) ) ) . toBe ( true )
218+ } )
219+
220+ it ( "OCCUPIED 좌석은 선택 불가하다" , ( ) => {
221+ const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 0 ) )
222+ expect ( result . current . canSelectSeat ( makeSeat ( "1" , "A" , SEAT_STATUS . OCCUPIED ) ) ) . toBe ( false )
223+ } )
224+
225+ it ( "SELECTED 좌석은 선택 불가하다" , ( ) => {
226+ const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 0 ) )
227+ expect ( result . current . canSelectSeat ( makeSeat ( "1" , "A" , SEAT_STATUS . SELECTED ) ) ) . toBe ( false )
228+ } )
229+ } )
230+
231+ describe ( "usePerformerSeatSelection - isSeatSelected 엣지 케이스" , ( ) => {
232+ it ( "같은 번호지만 다른 섹션의 좌석은 선택된 것으로 보지 않는다" , ( ) => {
233+ const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 0 ) )
234+
235+ act ( ( ) => { result . current . selectSeat ( makeSeat ( "1" , "A" ) ) } )
236+
237+ expect ( result . current . isSeatSelected ( makeSeat ( "1" , "B" ) ) ) . toBe ( false )
238+ } )
239+ } )
240+
241+ describe ( "usePerformerSeatSelection - maxSelectableSeats = 0 경계 동작" , ( ) => {
242+ it ( "existingSeatsCount가 3일 때 좌석 선택 시도해도 canBook은 false다" , ( ) => {
243+ const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 3 ) )
244+
245+ act ( ( ) => { result . current . selectSeat ( makeSeat ( "1" ) ) } )
246+
247+ expect ( result . current . canBook ) . toBe ( false )
248+ } )
249+
250+ it ( "섹션과 좌석이 있어도 existingSeatsCount가 3이면 isComplete는 false다" , ( ) => {
251+ const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 3 ) )
252+
253+ act ( ( ) => { result . current . setSelectedSection ( "A" ) } )
254+ act ( ( ) => { result . current . selectSeat ( makeSeat ( "1" ) ) } )
255+
256+ expect ( result . current . isComplete ) . toBe ( false )
257+ } )
258+ } )
259+
260+ describe ( "usePerformerSeatSelection - 섹션 null 변경" , ( ) => {
261+ it ( "섹션을 null로 변경하면 선택 좌석이 초기화된다" , ( ) => {
262+ const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 0 ) )
263+
264+ act ( ( ) => { result . current . setSelectedSection ( "A" ) } )
265+ act ( ( ) => { result . current . selectSeat ( makeSeat ( "1" ) ) } )
266+ act ( ( ) => { result . current . setSelectedSection ( null ) } )
267+
268+ expect ( result . current . selectedSection ) . toBeNull ( )
269+ expect ( result . current . selectedSeats ) . toHaveLength ( 0 )
270+ } )
271+ } )
272+
192273describe ( "usePerformerSeatSelection - removeOccupiedSeat" , ( ) => {
193274 it ( "지정한 섹션과 번호의 좌석을 선택 목록에서 제거한다" , ( ) => {
194275 const { result } = renderHook ( ( ) => usePerformerSeatSelection ( 0 ) )
0 commit comments