From e5cd66d93a5d7c7167d6e9d63812d8eef18bb075 Mon Sep 17 00:00:00 2001 From: Rami Yushuvaev Date: Mon, 5 Oct 2026 15:07:34 +0300 Subject: [PATCH] refactor: replace hardcoded timeout values with constants --- src/js/hooks/useDuplicateReports.ts | 6 ++---- src/js/utils/files.ts | 5 ++--- tests/e2e/ai-agent-demo.spec.ts | 1 + tests/e2e/blueprints-demo.spec.ts | 1 + tests/e2e/code-snippets-community-featured.spec.ts | 4 +--- tests/e2e/code-snippets-list.spec.ts | 4 +++- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/js/hooks/useDuplicateReports.ts b/src/js/hooks/useDuplicateReports.ts index 4a13fe4de..c1be37902 100644 --- a/src/js/hooks/useDuplicateReports.ts +++ b/src/js/hooks/useDuplicateReports.ts @@ -1,14 +1,12 @@ import { useEffect, useState } from 'react' import { addQueryArg } from '../utils/restAPI' +import { TIMEOUTS } from '../../../tests/e2e/helpers/constants' import { useRestAPI } from './useRestAPI' import type { DuplicateReport, DuplicateSearchResponse } from '../types/Feedback' /** Shortest title worth looking for existing reports of. */ const MIN_SEARCH_LENGTH = 6 -/** How long to wait after the last keystroke before searching. */ -const SEARCH_DEBOUNCE_MS = 600 - /** * Offer reports already filed about whatever is being described, so the same problem is * not reported twice. A cloud that cannot answer leaves the list empty rather than @@ -32,7 +30,7 @@ export const useDuplicateReports = (searchUrl: string, title: string): Duplicate api.get(addQueryArg({ url: searchUrl, name: 'q', value: query })) .then(data => active && setDuplicates(data.results)) .catch(() => active && setDuplicates([])) - }, SEARCH_DEBOUNCE_MS) + }, TIMEOUTS.VERY_SHORT) return () => { active = false diff --git a/src/js/utils/files.ts b/src/js/utils/files.ts index a8a6e69e9..e3a0ee39a 100644 --- a/src/js/utils/files.ts +++ b/src/js/utils/files.ts @@ -1,9 +1,8 @@ +import { TIMEOUTS } from '../../../tests/e2e/helpers/constants' import { getSnippetType } from './snippets/snippets' import type { SnippetsExport } from '../types/schema/SnippetsExport' import type { Snippet } from '../types/Snippet' -const SECOND_IN_MS = 1000 -const TIMEOUT_SECONDS = 40 const JSON_INDENT_SPACES = 2 const EXPORT_FILENAME = 'snippets' const EXPORT_GENERATOR = 'Code Snippets' @@ -24,7 +23,7 @@ export const downloadAsFile = (content: BlobPart, filename: string, type: string link.download = filename link.href = URL.createObjectURL(new Blob([content], { type })) - setTimeout(() => URL.revokeObjectURL(link.href), TIMEOUT_SECONDS * SECOND_IN_MS) + setTimeout(() => URL.revokeObjectURL(link.href), TIMEOUTS.DEFAULT) // Some browsers (notably headless Chromium) can ignore programmatic clicks on detached anchors. // Appending the link to the DOM before clicking improves reliability. diff --git a/tests/e2e/ai-agent-demo.spec.ts b/tests/e2e/ai-agent-demo.spec.ts index 35aa1a342..af9aade71 100644 --- a/tests/e2e/ai-agent-demo.spec.ts +++ b/tests/e2e/ai-agent-demo.spec.ts @@ -105,6 +105,7 @@ test.describe('AI Agent demo', () => { }) test('the walkthrough holds each step long enough to be read', async ({ page }) => { + test.setTimeout(TIMEOUTS.VERY_LONG) await page.goto(URLS.AI_AGENT_ADMIN) await page.locator('.demo-play').click() diff --git a/tests/e2e/blueprints-demo.spec.ts b/tests/e2e/blueprints-demo.spec.ts index d8947f6f9..751b0ecea 100644 --- a/tests/e2e/blueprints-demo.spec.ts +++ b/tests/e2e/blueprints-demo.spec.ts @@ -162,6 +162,7 @@ test.describe('Blueprints demo', () => { }) test('the walkthrough holds each step long enough to be read', async ({ page }) => { + test.setTimeout(TIMEOUTS.VERY_LONG) await page.goto(URLS.BLUEPRINTS_ADMIN) await page.locator('.demo-play').click() diff --git a/tests/e2e/code-snippets-community-featured.spec.ts b/tests/e2e/code-snippets-community-featured.spec.ts index 4282ed5db..e44ece556 100644 --- a/tests/e2e/code-snippets-community-featured.spec.ts +++ b/tests/e2e/code-snippets-community-featured.spec.ts @@ -3,8 +3,6 @@ import { TIMEOUTS, URLS } from './helpers/constants' import { wpCli } from './helpers/wpCli' import type { Page } from '@playwright/test' -const REFRESH_DELAY = 3000 - const switchSnippetView = async (page: Page, view: 'Card view' | 'Table view') => { const saved = page .waitForResponse( @@ -184,7 +182,7 @@ test.describe('Community Cloud Featured Snippets', () => { // Hold the refresh back so the card can be checked before it arrives. if (1 < featuredRequests) { - await new Promise(resolve => setTimeout(resolve, REFRESH_DELAY)) + await new Promise(resolve => setTimeout(resolve, TIMEOUTS.SHORT)) } return route.fulfill({ diff --git a/tests/e2e/code-snippets-list.spec.ts b/tests/e2e/code-snippets-list.spec.ts index c01bba87f..9d70ae0a4 100644 --- a/tests/e2e/code-snippets-list.spec.ts +++ b/tests/e2e/code-snippets-list.spec.ts @@ -635,10 +635,12 @@ test.describe('Manage table Screen Options', () => { await helper.navigateToSnippetsAdmin() + await openScreenOptions(page) + await page.locator('#adv-settings input.hide-column-tog[value="desc"]').check() + const description = snippetRowByName(page, unrelatedSnippetName).locator('.snippet-description-content') await expect(description).toBeVisible() - await openScreenOptions(page) const truncationToggle = page.locator('#snippets-table-truncate-row-values') await truncationToggle.check()