Skip to content

Commit 8405560

Browse files
committed
test: add test coverage
1 parent 3f6f509 commit 8405560

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/generic/hooks/tests/hooks.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ describe('useIframeBehavior', () => {
122122
expect(setWindowTopOffset).toHaveBeenCalledWith(window.scrollY);
123123
});
124124

125+
it('handles xblockScroll message correctly', () => {
126+
document.body.innerHTML = '<div id="window" top: 25px;"><div id="xblock-iframe" style="position: absolute; top: 50px;"></div></div>';
127+
renderHook(() => useIframeBehavior({ id, iframeUrl, iframeRef }));
128+
129+
const message = {
130+
type: iframeMessageTypes.xblockScroll,
131+
data: { offset: 100 },
132+
};
133+
134+
act(() => {
135+
window.dispatchEvent(new MessageEvent('message', message));
136+
});
137+
138+
expect(window.scrollY).toBe(100
139+
+ (document.getElementById('xblock-iframe') as HTMLElement).offsetTop
140+
+ (document.getElementById('xblock-iframe')?.parentElement as HTMLElement).offsetTop);
141+
});
142+
125143
it('handles offset message correctly', () => {
126144
document.body.innerHTML = '<div id="unit-iframe" style="position: absolute; top: 50px;"></div>';
127145
renderHook(() => useIframeBehavior({ id, iframeUrl, iframeRef }));

0 commit comments

Comments
 (0)