Skip to content

Commit 55cc0f7

Browse files
[bugfix]: harden Dreamverse Playwright share+timestamp tests
Address review S1s on PR #1417: - Use Object.defineProperty on Navigator.prototype for share/canShare stubs (direct assignment silently no-ops on Chromium/WebKit where navigator.share is a non-writable accessor). - Replace exact-text 'just now' assertions with the regex pattern\n already used at the third site; avoids minute-boundary flake on\n slow CI runs.
1 parent 576eddc commit 55cc0f7

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

apps/dreamverse/web/e2e/mock-backed-generation.spec.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,24 @@ test.describe('mock-backed generation smoke', () => {
5454

5555
await page.addInitScript(() => {
5656
(window as unknown as { __sharedFiles: unknown }).__sharedFiles = null;
57-
(navigator as unknown as { share: (d: { files?: File[] }) => Promise<void> }).share = async (data) => {
57+
const stub = async (data: { files?: File[] }) => {
5858
const files = Array.isArray(data?.files) ? data.files : [];
5959
(window as unknown as { __sharedFiles: unknown }).__sharedFiles = files.map((f) => ({
6060
name: f.name,
6161
type: f.type,
6262
size: f.size,
6363
}));
6464
};
65+
Object.defineProperty(Navigator.prototype, 'share', {
66+
value: stub,
67+
configurable: true,
68+
writable: true,
69+
});
70+
Object.defineProperty(Navigator.prototype, 'canShare', {
71+
value: (data: { files?: File[] }) => Array.isArray(data?.files),
72+
configurable: true,
73+
writable: true,
74+
});
6575
});
6676

6777
await page.goto('/');
@@ -246,11 +256,11 @@ test.describe('mock-backed generation smoke', () => {
246256
await page.getByRole('button', { name: 'Toggle sidebar' }).click();
247257
await expect(sidebar).toBeInViewport();
248258
await expect(sidebar.getByText('Previous', { exact: true })).toBeVisible({ timeout: 30_000 });
249-
await expect(sidebar.getByText('just now').first()).toBeVisible();
259+
await expect(sidebar.getByText(/^(just now|\d+m ago)$/).first()).toBeVisible();
250260
});
251261

252262
await test.step('clicking the prior session enters viewing mode', async () => {
253-
const priorRow = sidebar.locator('div[role="button"]').filter({ hasText: 'just now' }).first();
263+
const priorRow = sidebar.locator('div[role="button"]').filter({ hasText: /just now|\d+m ago/ }).first();
254264
await priorRow.click();
255265
await expect(sidebar).not.toBeInViewport();
256266
await expect(page.locator('video[autoplay][loop]')).toBeVisible({ timeout: 30_000 });
@@ -287,7 +297,7 @@ test.describe('mock-backed generation smoke', () => {
287297
await page.getByRole('button', { name: 'Toggle sidebar' }).click();
288298
await expect(sidebar).toBeInViewport();
289299
await expect(sidebar.getByText('Previous', { exact: true })).toBeVisible({ timeout: 30_000 });
290-
await expect(sidebar.getByText('just now').first()).toBeVisible();
300+
await expect(sidebar.getByText(/^(just now|\d+m ago)$/).first()).toBeVisible();
291301
});
292302

293303
await test.step('after page reload, the prior project is still in Previous', async () => {

0 commit comments

Comments
 (0)