import*as helpers from"../helper";import{getEventMeta,track_event}from"../helper";import{onPauseVideo,onPlayingVideo,onEndedVideo}from"../lifter";describe("Lifter LMS",(()=>{describe("onPauseVideo",(()=>{it("calls track_event when video is paused",(()=>{jest.spyOn(helpers,"track_event"),helpers.track_event.mockImplementation((()=>null)),onPauseVideo({detail:{plyr:{currentTime:10,duration:20,source:"https://test.com",provider:"test",config:{id:1}}}}),expect(track_event).toHaveBeenCalledWith("paused",{duration:20,id:1,provider:"test",ts:10,url:"https://test.com"})}))})),describe("onPlayingVideo",(()=>{it("calls track_event when video is playing",(()=>{jest.spyOn(helpers,"track_event"),helpers.track_event.mockImplementation((()=>null)),onPlayingVideo({detail:{plyr:{currentTime:10,duration:20,source:"https://test.com",provider:"test",config:{id:1}}}}),expect(track_event).toHaveBeenCalledWith("paused",{duration:20,id:1,provider:"test",ts:10,url:"https://test.com"}),expect(track_event).toHaveBeenCalledWith("played",{duration:20,id:1,provider:"test",ts:10,url:"https://test.com"})}))})),describe("onStartingVideo",(()=>{it("calls track_event when video is starting",(()=>{jest.spyOn(helpers,"track_event"),helpers.track_event.mockImplementation((()=>null)),onPlayingVideo({detail:{plyr:{currentTime:0,duration:20,source:"https://test.com",provider:"test",config:{id:1}}}}),expect(track_event).toHaveBeenCalledWith("started",{duration:20,id:1,provider:"test",ts:0,url:"https://test.com"})}))})),describe("onEndingVideo",(()=>{it("calls track_event, toggle_mark_complete, do_ajax_completion when video is ending",(()=>{jest.spyOn(helpers,"track_event"),jest.spyOn(helpers,"toggle_mark_complete"),jest.spyOn(helpers,"do_ajax_completion"),helpers.track_event.mockImplementation((()=>null)),helpers.toggle_mark_complete.mockImplementation((()=>null)),helpers.do_ajax_completion.mockImplementation((()=>null)),onEndedVideo({detail:{plyr:{currentTime:20,duration:20,source:"https://test.com",provider:"test",config:{id:1}}}}),expect(track_event).toHaveBeenCalledWith("ended",{duration:20,id:1,provider:"test",ts:20,url:"https://test.com"})}))})),describe("getEventMeta",(()=>{it("transforms event data into event meta",(()=>{expect(getEventMeta({currentTime:10,duration:20,source:"https://test.com",provider:"test",config:{id:1}})).toEqual({duration:20,id:1,provider:"test",ts:10,url:"https://test.com"})}))}))}));