[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
This commit is contained in:
1 parent
0642bb1514
commit
a700f0cccc
5 files changed
+108
-2
No files matched your search
@@ -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' })
|
||||
})
|
||||
})
|
||||
@@ -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<Page> {
|
||||
const world = getWorld()
|
||||
const { page } = world.actorsEnvironment.getActor({ key: stepUser })
|
||||
const resourceObject = new objects.applicationFiles.Resource({ page })
|
||||
return resourceObject.openResourceInNewTab(resource)
|
||||
}
|
||||
@@ -207,6 +207,27 @@ export const clickResource = async ({
|
||||
}
|
||||
}
|
||||
|
||||
export const openResourceInNewTab = async ({
|
||||
page,
|
||||
path
|
||||
}: {
|
||||
page: Page
|
||||
path: string
|
||||
}): Promise<Page> => {
|
||||
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<void> => {
|
||||
const topbarResourceName = page.locator(topbarFilenameSelector)
|
||||
|
||||
await expect(topbarResourceName).toBeVisible()
|
||||
await expect(topbarResourceName).toHaveAttribute('data-test-resource-name', expectedName)
|
||||
}
|
||||
@@ -220,6 +220,10 @@ export class Resource {
|
||||
await po.clickResource({ page: this.#page, path: resource })
|
||||
}
|
||||
|
||||
async openResourceInNewTab(resource: string): Promise<Page> {
|
||||
return po.openResourceInNewTab({ page: this.#page, path: resource })
|
||||
}
|
||||
|
||||
async openFolderViaBreadcrumb(resource: string): Promise<void> {
|
||||
await po.clickResourceFromBreadcrumb({ page: this.#page, resource })
|
||||
}
|
||||
|
||||
@@ -58,7 +58,16 @@ export const getOfficeDocumentContent = async (page: Page): Promise<string> => {
|
||||
// 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
|
||||
|
||||
Reference in new issue
Block a user