11import React from "react" ;
2- import { render , screen } from "@testing-library/react" ;
2+ import { render , screen , waitFor } from "@testing-library/react" ;
3+ import userEvent from "@testing-library/user-event" ;
34import { EbayVideo , EbayVideoSource } from "../index" ;
45
56describe ( "<EbayVideo>" , ( ) => {
7+ const defaultProps = {
8+ thumbnail : "https://ir.ebaystatic.com/cr/v/c1/ebayui/video/v1/iphone-thumbnail.jpg" ,
9+ width : 500 ,
10+ height : 300 ,
11+ a11yPlayText : "Play" ,
12+ errorText : "Error loading" ,
13+ reportText : "Report" ,
14+ } ;
15+
616 beforeEach ( ( ) =>
717 render (
8- < EbayVideo
9- thumbnail = "https://ir.ebaystatic.com/cr/v/c1/ebayui/video/v1/iphone-thumbnail.jpg"
10- width = { 500 }
11- height = { 300 }
12- a11yPlayText = "Play"
13- a11yLoadText = "Loading"
14- errorText = "Error loading"
15- reportText = "Report"
16- >
18+ < EbayVideo { ...defaultProps } >
1719 < EbayVideoSource src = "https://ir.ebaystatic.com/cr/v/c1/ebayui/video/v1/video.mp4" />
1820 </ EbayVideo > ,
1921 ) ,
@@ -30,10 +32,81 @@ describe("<EbayVideo>", () => {
3032 } ) ;
3133
3234 it ( "shows play button" , ( ) => {
33- expect ( screen . getByLabelText ( "Play" ) ) . toBeInTheDocument ( ) ;
35+ const playButtons = screen . getAllByLabelText ( "Play" ) ;
36+ expect ( playButtons . length ) . toBeGreaterThan ( 0 ) ;
3437 } ) ;
3538
3639 it ( "shows loading spinner" , ( ) => {
37- expect ( screen . getByLabelText ( "Loading" ) ) . toBeInTheDocument ( ) ;
40+ const spinner = document . querySelector ( ".shaka-spinner" ) ;
41+ expect ( spinner ) . toBeInTheDocument ( ) ;
42+ } ) ;
43+
44+ it ( "renders initial play button in shaka controls container" , ( ) => {
45+ const playButtonContainer = document . querySelector ( ".shaka-play-button-container" ) ;
46+ expect ( playButtonContainer ) . toBeInTheDocument ( ) ;
47+
48+ const shakaControls = document . querySelector ( ".shaka-controls-container" ) ;
49+ expect ( shakaControls ) . toBeInTheDocument ( ) ;
50+
51+ // Verify play button is inside shaka controls
52+ expect ( shakaControls ?. querySelector ( ".shaka-play-button" ) ) . toBeInTheDocument ( ) ;
53+ } ) ;
54+
55+ it ( "play button has correct icon with width 64" , ( ) => {
56+ const playButtonContainer = document . querySelector ( ".shaka-play-button-container" ) ;
57+ const playButton = playButtonContainer ?. querySelector ( ".shaka-play-button" ) ;
58+ expect ( playButton ) . toBeInTheDocument ( ) ;
59+
60+ const icon = playButton ?. querySelector ( "svg" ) ;
61+ expect ( icon ) . toHaveAttribute ( "width" , "64" ) ;
62+ expect ( icon ) . toHaveClass ( "icon--64-colored" ) ;
63+ } ) ;
64+
65+ it ( "removes initial play button on click" , async ( ) => {
66+ const user = userEvent . setup ( ) ;
67+ const playButtonContainer = document . querySelector ( ".shaka-play-button-container" ) ;
68+ const playButton = playButtonContainer ?. querySelector ( ".shaka-play-button" ) ;
69+ expect ( playButton ) . toBeInTheDocument ( ) ;
70+
71+ await user . click ( playButton ! ) ;
72+
73+ await waitFor ( ( ) => {
74+ const playButtonContainerAfterClick = document . querySelector ( ".shaka-play-button-container" ) ;
75+ // The initial play button should be removed from React tree
76+ expect ( playButtonContainerAfterClick ) . not . toBeInTheDocument ( ) ;
77+ } ) ;
78+ } ) ;
79+
80+ describe ( "autoplay behavior" , ( ) => {
81+ it ( "sets autoplay attribute when autoplay prop is true" , ( ) => {
82+ const { container } = render (
83+ < EbayVideo { ...defaultProps } autoPlay >
84+ < EbayVideoSource src = "https://ir.ebaystatic.com/cr/v/c1/ebayui/video/v1/video.mp4" />
85+ </ EbayVideo > ,
86+ ) ;
87+
88+ const video = container . querySelector ( "video" ) as HTMLVideoElement ;
89+ expect ( video . autoplay ) . toBe ( true ) ;
90+ } ) ;
91+
92+ it ( "triggers play when action prop changes to 'play'" , ( ) => {
93+ const { container, rerender } = render (
94+ < EbayVideo { ...defaultProps } >
95+ < EbayVideoSource src = "https://ir.ebaystatic.com/cr/v/c1/ebayui/video/v1/video.mp4" />
96+ </ EbayVideo > ,
97+ ) ;
98+
99+ const video = container . querySelector ( "video" ) as HTMLVideoElement ;
100+ const playSpy = vi . spyOn ( video , "play" ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
101+
102+ // Change action to 'play'
103+ rerender (
104+ < EbayVideo { ...defaultProps } action = "play" >
105+ < EbayVideoSource src = "https://ir.ebaystatic.com/cr/v/c1/ebayui/video/v1/video.mp4" />
106+ </ EbayVideo > ,
107+ ) ;
108+
109+ expect ( playSpy ) . toHaveBeenCalled ( ) ;
110+ } ) ;
38111 } ) ;
39112} ) ;
0 commit comments