Skip to content

Commit

Permalink
refactor: added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Oct 31, 2024
1 parent b2b2f62 commit 18bea34
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/course-unit/xblock-container-iframe/tests/hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ describe('useIFrameBehavior', () => {
expect(result.current.hasLoaded).toBe(false);
});

it('scrolls to previous position on video fullscreen exit', () => {
const mockWindowTopOffset = 100;

(useKeyedState as jest.Mock).mockImplementation((key) => {
if (key === stateKeys.windowTopOffset) {
return [mockWindowTopOffset, setWindowTopOffset];
}
return [null, jest.fn()];
});

renderHook(() => useIFrameBehavior({ id, iframeUrl }));

const message = {
data: {
type: messageTypes.videoFullScreen,
payload: { open: false },
},
};

act(() => {
window.dispatchEvent(new MessageEvent('message', message));
});

expect(window.scrollTo).toHaveBeenCalledWith(0, mockWindowTopOffset);
});

it('handles resize message correctly', () => {
renderHook(() => useIFrameBehavior({ id, iframeUrl }));

Expand Down

0 comments on commit 18bea34

Please sign in to comment.