|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { expect, test } from '@playwright/test' |
| 7 | +import { login } from '../support/nc-login' |
| 8 | +import { configureOpenSsl, setAppConfig } from '../support/nc-provisioning' |
| 9 | + |
| 10 | +test('visible signature element persists and can be deleted', async ({ page }) => { |
| 11 | + await login( |
| 12 | + page.request, |
| 13 | + process.env.NEXTCLOUD_ADMIN_USER ?? 'admin', |
| 14 | + process.env.NEXTCLOUD_ADMIN_PASSWORD ?? 'admin', |
| 15 | + ) |
| 16 | + |
| 17 | + await configureOpenSsl(page.request, 'LibreSign Test', { |
| 18 | + C: 'BR', |
| 19 | + OU: ['Organization Unit'], |
| 20 | + ST: 'Rio de Janeiro', |
| 21 | + O: 'LibreSign', |
| 22 | + L: 'Rio de Janeiro', |
| 23 | + }) |
| 24 | + |
| 25 | + await setAppConfig( |
| 26 | + page.request, |
| 27 | + 'libresign', |
| 28 | + 'identify_methods', |
| 29 | + JSON.stringify([ |
| 30 | + { name: 'account', enabled: true, mandatory: true, signatureMethods: { clickToSign: { enabled: true } } }, |
| 31 | + { name: 'email', enabled: false, mandatory: false }, |
| 32 | + ]), |
| 33 | + ) |
| 34 | + |
| 35 | + await page.goto('./apps/libresign') |
| 36 | + await page.getByRole('button', { name: 'Upload from URL' }).click() |
| 37 | + await page.getByRole('textbox', { name: 'URL of a PDF file' }).fill('https://raw.githubusercontent.com/LibreSign/libresign/main/tests/php/fixtures/pdfs/small_valid.pdf') |
| 38 | + await page.getByRole('button', { name: 'Send' }).click() |
| 39 | + await page.getByRole('button', { name: 'Add signer' }).click() |
| 40 | + await page.getByPlaceholder('Account').fill('a') |
| 41 | + await page.getByRole('option', { name: 'admin@email.tld' }).click() |
| 42 | + await page.getByRole('textbox', { name: 'Signer name' }).click() |
| 43 | + await page.getByRole('textbox', { name: 'Signer name' }).press('ControlOrMeta+a') |
| 44 | + await page.getByRole('textbox', { name: 'Signer name' }).fill('Admin Name') |
| 45 | + |
| 46 | + // Save the signer first, then open the signature positions modal |
| 47 | + await page.getByRole('button', { name: 'Save' }).click() |
| 48 | + await page.getByRole('button', { name: 'Setup signature positions' }).click() |
| 49 | + await expect(page.getByLabel('Page 1 of 1.')).toBeVisible() |
| 50 | + |
| 51 | + // Select the signer to enter element-placement mode |
| 52 | + await page.getByLabel('Signature positions').getByRole('link', { name: 'Edit signer Admin Name' }).click() |
| 53 | + await expect(page.getByText('Click on the place you want to add.')).toBeVisible() |
| 54 | + |
| 55 | + // Placing a signature element requires three steps: |
| 56 | + // 1. hover() triggers handleMouseMove, setting previewVisible=true inside a rAF callback. |
| 57 | + // 2. Waiting for .preview-element confirms the rAF ran. |
| 58 | + // 3. click() fires mouseup, which calls finishAdding() and places the element. |
| 59 | + const overlay = page.getByLabel('Page 1 of 1. Press Enter or Space to place the signature here.') |
| 60 | + await overlay.hover() |
| 61 | + await page.getByLabel('Signature positions').locator('.preview-element').first().waitFor({ state: 'visible' }) |
| 62 | + await overlay.click() |
| 63 | + |
| 64 | + await expect( |
| 65 | + page.getByLabel('Signature positions').getByRole('img', { name: 'Signature position for Admin Name' }), |
| 66 | + ).toBeVisible() |
| 67 | + |
| 68 | + // Save closes the modal and persists the element via API |
| 69 | + await page.getByLabel('Signature positions').getByRole('button', { name: 'Save' }).click() |
| 70 | + |
| 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() |
| 88 | + |
| 89 | + // Verify the element survived the round-trip to the server |
| 90 | + await expect( |
| 91 | + page.getByLabel('Signature positions').getByRole('img', { name: 'Signature position for Admin Name' }), |
| 92 | + ).toBeVisible() |
| 93 | + |
| 94 | + // Select the element so the toolbar (Duplicate / Delete) appears, then delete it |
| 95 | + await page.getByLabel('Signature positions').getByRole('img', { name: 'Signature position for Admin Name' }).click() |
| 96 | + await page.getByLabel('Signature positions').getByRole('button', { name: 'Delete' }).click() |
| 97 | + |
| 98 | + await expect( |
| 99 | + page.getByLabel('Signature positions').getByRole('img', { name: 'Signature position for Admin Name' }), |
| 100 | + ).toBeHidden() |
| 101 | + |
| 102 | + // Save the now-empty element list |
| 103 | + await page.getByLabel('Signature positions').getByRole('button', { name: 'Save' }).click() |
| 104 | + |
| 105 | + // Navigate away and back to force a fresh load from the server |
| 106 | + 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() |
| 119 | + |
| 120 | + // 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() |
| 123 | + await expect(page.getByLabel('Page 1 of 1.')).toBeVisible() |
| 124 | + |
| 125 | + await expect( |
| 126 | + page.getByLabel('Signature positions').getByRole('img', { name: 'Signature position for Admin Name' }), |
| 127 | + ).toBeHidden() |
| 128 | +}) |
0 commit comments