Skip to content

Commit 6f45f7b

Browse files
authored
test: harden ci waits (#30)
1 parent 4e7bf42 commit 6f45f7b

3 files changed

Lines changed: 28 additions & 12 deletions

File tree

tests/components/diagram-preview.test.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ describe('DiagramPreview', () => {
7171
expect(screen.getByTestId('preview-board')).toBeInTheDocument();
7272
});
7373

74-
expect(updateViewport).toHaveBeenCalled();
74+
await waitFor(() => {
75+
expect(updateViewport).toHaveBeenCalled();
76+
});
7577
});
7678

7779
it('shows a fallback when mermaid parsing fails', async () => {
@@ -120,10 +122,12 @@ describe('DiagramPreview', () => {
120122
expect(value).toContain('1240');
121123
});
122124

123-
expect(updateViewport).toHaveBeenCalledWith(
124-
mockBoard,
125-
expect.any(Array),
126-
expect.any(Number),
127-
);
125+
await waitFor(() => {
126+
expect(updateViewport).toHaveBeenCalledWith(
127+
mockBoard,
128+
expect.any(Array),
129+
expect.any(Number),
130+
);
131+
});
128132
});
129133
});

tests/e2e/grid-background.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ test.describe('Grid Background E2E Tests', () => {
211211
await page.reload();
212212
await waitForBoard(page);
213213

214-
const canvas = await getCanvas(page);
215-
const content = await canvas.innerHTML();
216-
expect(content).toContain('circle');
214+
await expect
215+
.poll(async () => (await getCanvas(page)).innerHTML(), { timeout: 10000 })
216+
.toContain('circle');
217217
});
218218

219219
test('should persist grid density setting', async ({ page }) => {

tests/e2e/utils.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ async function waitForBoardShell(page: Page): Promise<void> {
4141
await dismissOverlays(page);
4242
}
4343

44+
async function waitForToolbar(page: Page): Promise<void> {
45+
await expect(page.getByRole('button', { name: 'Select' }).first()).toBeVisible({
46+
timeout: 30000,
47+
});
48+
}
49+
4450
export async function waitForMainBoard(page: Page): Promise<void> {
4551
let lastError: unknown;
4652

@@ -186,6 +192,8 @@ export async function selectTool(page: Page, toolName: string): Promise<boolean>
186192
await page.waitForTimeout(100);
187193
}
188194

195+
await waitForToolbar(page);
196+
189197
const directToolLabels: Record<string, string> = {
190198
arrow: 'Arrow',
191199
select: 'Select',
@@ -230,9 +238,10 @@ export async function selectTool(page: Page, toolName: string): Promise<boolean>
230238
if (toolName in shapeToolLabels) {
231239
const dropdownButton = page
232240
.getByTestId('shapes-dropdown-trigger')
241+
.or(page.getByRole('button', { name: 'Shapes' }))
233242
.first();
234243

235-
if (!(await dropdownButton.isVisible({ timeout: 3000 }).catch(() => false))) {
244+
if (!(await dropdownButton.isVisible({ timeout: 10000 }).catch(() => false))) {
236245
return false;
237246
}
238247

@@ -264,15 +273,18 @@ export async function getElementCount(page: Page): Promise<number> {
264273
return page.evaluate(() => {
265274
const boardRoot = document.querySelector('[data-board="true"]');
266275
const count = boardRoot?.getAttribute('data-element-count');
276+
const renderedElementCount = document.querySelectorAll(
277+
'.board-wrapper [plait-data-id]',
278+
).length;
267279

268280
if (count !== null && count !== undefined) {
269281
const parsed = Number.parseInt(count, 10);
270282
if (!Number.isNaN(parsed)) {
271-
return parsed;
283+
return Math.max(parsed, renderedElementCount);
272284
}
273285
}
274286

275-
return document.querySelectorAll('.board-wrapper [plait-data-id]').length;
287+
return renderedElementCount;
276288
});
277289
}
278290

0 commit comments

Comments
 (0)