Skip to content

Commit b6e7ccb

Browse files
fix(playwright): stabilize visible element persistence flow
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent b2f49a5 commit b6e7ccb

1 file changed

Lines changed: 25 additions & 32 deletions

File tree

playwright/e2e/visible-element-persistence.spec.ts

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import { login } from '../support/nc-login'
88
import { configureOpenSsl, setAppConfig } from '../support/nc-provisioning'
99

1010
test('visible signature element persists and can be deleted', async ({ page }) => {
11+
const requestSignatureTab = page.locator('#request-signature-tab')
12+
const setupSignaturePositionsButton = requestSignatureTab.getByRole('button', { name: 'Setup signature positions' })
13+
const openSidebarButton = page.getByRole('button', { name: 'Open sidebar' })
14+
15+
async function reopenFileFromUuid(uuid: string) {
16+
await page.goto(`./apps/libresign/f/filelist/sign?uuid=${uuid}`)
17+
if (await openSidebarButton.isVisible()) {
18+
await openSidebarButton.click()
19+
}
20+
await expect(setupSignaturePositionsButton).toBeVisible()
21+
await setupSignaturePositionsButton.click()
22+
}
23+
1124
await login(
1225
page.request,
1326
process.env.NEXTCLOUD_ADMIN_USER ?? 'admin',
@@ -44,8 +57,16 @@ test('visible signature element persists and can be deleted', async ({ page }) =
4457
await page.getByRole('textbox', { name: 'Signer name' }).fill('Admin Name')
4558

4659
// Save the signer first, then open the signature positions modal
60+
const createRequestResponsePromise = page.waitForResponse(response =>
61+
response.url().includes('/apps/libresign/api/v1/request-signature')
62+
&& ['POST', 'PATCH'].includes(response.request().method()),
63+
)
4764
await page.getByRole('button', { name: 'Save' }).click()
48-
await page.getByRole('button', { name: 'Setup signature positions' }).click()
65+
const createRequestResponse = await createRequestResponsePromise
66+
const createRequestBody = await createRequestResponse.json()
67+
const requestUuid = createRequestBody.ocs.data.uuid as string
68+
await expect(setupSignaturePositionsButton).toBeVisible()
69+
await setupSignaturePositionsButton.click()
4970
await expect(page.getByLabel('Page 1 of 1.')).toBeVisible()
5071

5172
// Select the signer to enter element-placement mode
@@ -68,23 +89,8 @@ test('visible signature element persists and can be deleted', async ({ page }) =
6889
// Save closes the modal and persists the element via API
6990
await page.getByLabel('Signature positions').getByRole('button', { name: 'Save' }).click()
7091

71-
// Navigate to the Files list and ensure it is sorted by Created at, newest first (descending)
72-
await page.locator('#fileslist').getByRole('link', { name: 'Files' }).click()
73-
const createdAtTh = page.locator('th.files-list__row-created_at')
74-
const sortDirection = await createdAtTh.getAttribute('aria-sort')
75-
if (sortDirection !== 'descending') {
76-
await page.getByRole('button', { name: 'Created at' }).click()
77-
if (sortDirection === 'none') {
78-
// Column was sortable but not active: first click set it to ascending, one more for descending
79-
await page.getByRole('button', { name: 'Created at' }).click()
80-
}
81-
}
82-
const firstRow = page.locator('[data-cy-files-list-tbody] tr.files-list__row').first()
83-
await expect(firstRow.getByRole('button', { name: 'small_valid' })).toBeVisible()
84-
85-
// Re-open the document by clicking the file name — the sidebar opens automatically
86-
await firstRow.getByRole('button', { name: 'small_valid' }).click()
87-
await page.getByRole('button', { name: 'Setup signature positions' }).click()
92+
// Open the document again through the Files route using the request uuid to force a fresh load
93+
await reopenFileFromUuid(requestUuid)
8894

8995
// Verify the element survived the round-trip to the server
9096
await expect(
@@ -104,22 +110,9 @@ test('visible signature element persists and can be deleted', async ({ page }) =
104110

105111
// Navigate away and back to force a fresh load from the server
106112
await page.getByRole('link', { name: 'Request' }).click()
107-
await page.locator('#fileslist').getByRole('link', { name: 'Files' }).click()
108-
const createdAtTh2 = page.getByRole('columnheader', { name: 'Created at' })
109-
const sortDirection2 = await createdAtTh2.evaluate((el: HTMLElement) => el.ariaSort)
110-
if (sortDirection2 !== 'descending') {
111-
await page.getByRole('button', { name: 'Created at' }).click()
112-
if (sortDirection2 === 'none') {
113-
// Column was sortable but not active: first click set it to ascending, one more for descending
114-
await page.getByRole('button', { name: 'Created at' }).click()
115-
}
116-
}
117-
const lastRow = page.locator('[data-cy-files-list-tbody] tr.files-list__row').first()
118-
await expect(lastRow.getByRole('button', { name: 'small_valid' })).toBeVisible()
119113

120114
// Re-open the document one last time and confirm the element is gone
121-
await lastRow.getByRole('button', { name: 'small_valid' }).click()
122-
await page.getByRole('button', { name: 'Setup signature positions' }).click()
115+
await reopenFileFromUuid(requestUuid)
123116
await expect(page.getByLabel('Page 1 of 1.')).toBeVisible()
124117

125118
await expect(

0 commit comments

Comments
 (0)