Skip to content

Commit 3f7745a

Browse files
Test: add unit test for issue 4751 (#4751)
1 parent 41f8164 commit 3f7745a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/unit/modules/ResizeTable.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,39 @@ describe("ResizeTable module", () => {
100100
// Clean up
101101
redrawSpy.mockRestore();
102102
});
103+
104+
it('should determine whether to redraw table or not using latest visibility state from batched IntersectionObserver entries', () => {
105+
let observedElements = [];
106+
let observerCallback;
107+
let redrawTableCalled = false;
108+
109+
// mock intersectionObserver
110+
global.IntersectionObserver = jest.fn((callback) => {
111+
observerCallback = callback;
112+
return {
113+
observe: jest.fn((el) => observedElements.push(el)),
114+
unobserve: jest.fn(),
115+
disconnect: jest.fn()
116+
};
117+
});
118+
119+
// mock redrawTable
120+
resizeTableMod.redrawTable = function() {
121+
redrawTableCalled = true;
122+
};
123+
124+
resizeTableMod.initializeVisibilityObserver();
125+
126+
// reproduce IntersectionObserver being called when table rendered for the first time
127+
observerCallback([
128+
{ target: tabulator.element, isIntersecting: true },
129+
]);
130+
131+
observerCallback([
132+
{ target: tabulator.element, isIntersecting: false },
133+
{ target: tabulator.element, isIntersecting: true },
134+
]);
135+
136+
expect(redrawTableCalled).toBe(true);
137+
});
103138
});

0 commit comments

Comments
 (0)