From a700f0cccca78e08e46b653c17027a5e479bcd47 Mon Sep 17 00:00:00 2001 From: Asmita Paudel <94975243+Asmitapaudel@users.noreply.github.com> Date: Fri, 18 Sep 2026 16:59:45 +0545 Subject: [PATCH] [tests-only][full-ci] test: add tests for opening files with # and ? in new tabs (#12865) test: add tests for opening files with # and ? in new tabs --- .../specs/file-action/fileNavigation.spec.ts | 44 +++++++++++++++++++ web/tests/e2e/steps/ui/resources.ts | 15 ++++++- .../objects/app-files/resource/actions.ts | 36 +++++++++++++++ .../objects/app-files/resource/index.ts | 4 ++ .../objects/app-files/resource/webOffice.ts | 11 ++++- 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 web/tests/e2e/specs/file-action/fileNavigation.spec.ts diff --git a/web/tests/e2e/specs/file-action/fileNavigation.spec.ts b/web/tests/e2e/specs/file-action/fileNavigation.spec.ts new file mode 100644 index 00000000000..b84e2c93a18 --- /dev/null +++ b/web/tests/e2e/specs/file-action/fileNavigation.spec.ts @@ -0,0 +1,44 @@ +import { test } from '../../environment/test' +import * as api from '../../steps/api/api' +import * as ui from '../../steps/ui/index' +import { + createResourceTypes, + verifyTopbarResourceName +} from '../../support/objects/app-files/resource/actions' + +test.describe('Open resources in a new tab', { tag: '@predefined-users' }, () => { + test('opens files with # and ? in their name in a new tab', async () => { + const files: { name: string; type: createResourceTypes; content: string }[] = [ + { name: '#.txt', type: 'txtFile', content: 'file with # in its name' }, + { name: '?.txt', type: 'txtFile', content: 'file with ? in its name' }, + { name: 'a#b.txt', type: 'txtFile', content: 'file with a#b in its name' }, + { name: 'a?b.txt', type: 'txtFile', content: 'file with a?b in its name' }, + { name: 'a#b?c.txt', type: 'txtFile', content: 'file with both # and ? in its name' } + ] + + await api.usersHaveBeenCreated({ stepUser: 'Admin', users: ['Alice'] }) + + await ui.userLogsIn({ stepUser: 'Alice' }) + + await ui.userCreatesResources({ + stepUser: 'Alice', + resources: files + }) + + for (const file of files) { + const newPage = await ui.userOpensResourceInNewTab({ + stepUser: 'Alice', + resource: file.name + }) + + await verifyTopbarResourceName({ + page: newPage, + expectedName: file.name + }) + + await newPage.close() + } + + await ui.userLogsOut({ stepUser: 'Alice' }) + }) +}) diff --git a/web/tests/e2e/steps/ui/resources.ts b/web/tests/e2e/steps/ui/resources.ts index ee30bf66a66..7a412c20571 100644 --- a/web/tests/e2e/steps/ui/resources.ts +++ b/web/tests/e2e/steps/ui/resources.ts @@ -1,4 +1,4 @@ -import { expect } from '@playwright/test' +import { expect, Page } from '@playwright/test' import { objects } from '../../support' import { clickResourceModifier, @@ -1608,3 +1608,16 @@ export async function userDownloadsPreviousVersionOfResource({ const fileInfo = world.filesEnvironment.getFile({ name: resource }) await resourceObject.downloadVersion({ folder: to, files: [fileInfo] }) } + +export async function userOpensResourceInNewTab({ + stepUser, + resource +}: { + stepUser: string + resource: string +}): Promise { + const world = getWorld() + const { page } = world.actorsEnvironment.getActor({ key: stepUser }) + const resourceObject = new objects.applicationFiles.Resource({ page }) + return resourceObject.openResourceInNewTab(resource) +} diff --git a/web/tests/e2e/support/objects/app-files/resource/actions.ts b/web/tests/e2e/support/objects/app-files/resource/actions.ts index f6df83d6ae6..cca93acef18 100644 --- a/web/tests/e2e/support/objects/app-files/resource/actions.ts +++ b/web/tests/e2e/support/objects/app-files/resource/actions.ts @@ -207,6 +207,27 @@ export const clickResource = async ({ } } +export const openResourceInNewTab = async ({ + page, + path +}: { + page: Page + path: string +}): Promise => { + const escapedName = path.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + + const resource = page.locator(util.format(resourceNameSelector, escapedName)) + + const [newPage] = await Promise.all([ + page.context().waitForEvent('page'), + resource.click({ modifiers: ['Control'] }) + ]) + + await newPage.waitForLoadState() + + return newPage +} + export const clickResourceFromBreadcrumb = async ({ page, resource @@ -2772,3 +2793,18 @@ export const duplicateMultipleResources = async ({ } } } + +export interface VerifyTopbarResourceNameArgs { + page: Page + expectedName: string +} + +export const verifyTopbarResourceName = async ({ + page, + expectedName +}: VerifyTopbarResourceNameArgs): Promise => { + const topbarResourceName = page.locator(topbarFilenameSelector) + + await expect(topbarResourceName).toBeVisible() + await expect(topbarResourceName).toHaveAttribute('data-test-resource-name', expectedName) +} diff --git a/web/tests/e2e/support/objects/app-files/resource/index.ts b/web/tests/e2e/support/objects/app-files/resource/index.ts index e869881bbde..0a5655dab18 100644 --- a/web/tests/e2e/support/objects/app-files/resource/index.ts +++ b/web/tests/e2e/support/objects/app-files/resource/index.ts @@ -220,6 +220,10 @@ export class Resource { await po.clickResource({ page: this.#page, path: resource }) } + async openResourceInNewTab(resource: string): Promise { + return po.openResourceInNewTab({ page: this.#page, path: resource }) + } + async openFolderViaBreadcrumb(resource: string): Promise { await po.clickResourceFromBreadcrumb({ page: this.#page, resource }) } diff --git a/web/tests/e2e/support/objects/app-files/resource/webOffice.ts b/web/tests/e2e/support/objects/app-files/resource/webOffice.ts index 8939bd2b0f0..b0a33582702 100644 --- a/web/tests/e2e/support/objects/app-files/resource/webOffice.ts +++ b/web/tests/e2e/support/objects/app-files/resource/webOffice.ts @@ -58,7 +58,16 @@ export const getOfficeDocumentContent = async (page: Page): Promise => { // navigator.clipboard calls throw "Document is not focused" unless this page's tab is the // OS-focused one - with multiple actors (e.g. Alice + Brian) each owning their own page/tab, // the one we're about to read from isn't necessarily the foregrounded one. - await page.bringToFront() + await expect + .poll( + async () => { + await page.bringToFront() + return page.evaluate(() => document.hasFocus()) + }, + { timeout: 10000 } + ) + .toBe(true) + // clear the clipboard await page.evaluate("navigator.clipboard.writeText('')") // copying and getting the value with keyboard requires some time