Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix flaky oscillating resize test #1373

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/table/__integ__/resizable-columns-misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const prepareCoordinate = (num: number) => Math.round(num);

declare global {
interface Window {
__tableResizes__: ResizeObserverEntry[];
__tableResizes__: number;
}
}

Expand Down Expand Up @@ -50,21 +50,17 @@ class ResizableColumnsPage extends BasePageObject {

async installObserver(selector: string) {
await this.browser.execute(selector => {
window.__tableResizes__ = [];
window.__tableResizes__ = 0;
const target = document.querySelector(selector)!;
const observer = new ResizeObserver(entries => {
window.__tableResizes__.push(...entries);
window.__tableResizes__ += entries.length;
});
observer.observe(target);
}, selector);
}

flushObservations() {
return this.browser.execute(() => {
const resizes = window.__tableResizes__;
window.__tableResizes__ = [];
return resizes;
});
getObservations() {
return this.browser.execute(() => window.__tableResizes__);
}
}

Expand All @@ -83,7 +79,7 @@ test(
})
);

test(
test.each([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20])(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running the test 20 times to ensure it is stable. I will remove it before merging.

'should not have oscillating size when the last column has the minimal width',
useBrowser(async browser => {
const page = new ResizableColumnsPage(browser);
Expand All @@ -92,11 +88,11 @@ test(
await page.installObserver(wrapper.find('table').toSelector());
await page.click('#shrink-container');
await page.waitForJsTimers();
// flush observations from the container resize
await expect(page.flushObservations()).resolves.not.toEqual([]);
// expected 1 observation after creating observer and 1 caused by container shrink
await expect(page.getObservations()).resolves.toBe(2);
await page.waitForJsTimers();
// ensure there are no ongoing resizes after we flushed the expected ones above
await expect(page.flushObservations()).resolves.toEqual([]);
// ensure there are no more observations added after the expected 2
await expect(page.getObservations()).resolves.toBe(2);
})
);

Expand Down
Loading