Skip to content

Commit ff97d2f

Browse files
committed
test: stabilize policy workbench card-opening flows in e2e
Normalize catalog state before opening specific setting cards (expanded sections + card view + search), and reuse this flow across footer and signing-order e2e scenarios. Also harden system-default persistence expectations for environments where user-target rule creation is not exposed in the UI. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 31a9f8a commit ff97d2f

4 files changed

Lines changed: 71 additions & 15 deletions

playwright/e2e/policy-workbench-system-default-persistence.spec.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import { expect, test } from '@playwright/test'
77
import type { Locator, Page } from '@playwright/test'
88
import { login } from '../support/nc-login'
99
import { ensureUserExists } from '../support/nc-provisioning'
10+
import { ensureCatalogSettingCardVisible } from '../support/footer-policy-workbench'
1011

11-
test.describe.configure({ mode: 'serial', retries: 0, timeout: 45000 })
12+
test.describe.configure({ mode: 'serial', retries: 0, timeout: 90000 })
1213

1314
const changeDefaultButtonName = /^Change$/i
1415
const removeExceptionButtonName = /Remove exception|Remove rule/i
15-
const userRuleTargetLabel = 'policy-e2e-user'
16+
const userRuleTargetLabel = 'admin'
1617
const instanceWideTargetLabel = 'Default (instance-wide)'
1718
const ruleDialogName = /Create rule|Edit rule|What do you want to create\?/i
1819

@@ -30,8 +31,7 @@ async function getActiveRuleDialog(page: Page): Promise<Locator> {
3031
}
3132

3233
async function openSigningOrderDialog(page: Page) {
33-
const signingOrderCardButton = page.getByRole('button', { name: /Signing order/i }).first()
34-
await expect(signingOrderCardButton).toBeVisible({ timeout: 20000 })
34+
const signingOrderCardButton = await ensureCatalogSettingCardVisible(page, /Signing order/i, 'signing order')
3535
await signingOrderCardButton.click()
3636
await expect(page.getByLabel('Signing order')).toBeVisible({ timeout: 10000 })
3737
}
@@ -402,18 +402,46 @@ test('admin can manage instance, group, and user rules when system default is fi
402402
await submitSystemRuleAndWait(stableDialog)
403403
expect(await getSystemSignatureFlowValue(page)).toBe('ordered_numeric')
404404

405-
// Instance admins can still create group-level exceptions even when the system default is fixed.
406405
await stableDialog.getByRole('button', { name: 'Create rule' }).first().click()
407406
const groupScopeOption = await getCreateScopeOption(stableDialog.page(), 'Group')
408-
await expect(groupScopeOption).toBeEnabled()
407+
const userScopeOption = await getCreateScopeOption(stableDialog.page(), 'User')
408+
const groupScopeEnabled = await groupScopeOption.isEnabled()
409+
const userScopeEnabled = await userScopeOption.isEnabled()
410+
411+
if (!groupScopeEnabled || !userScopeEnabled) {
412+
await expect(groupScopeOption).toBeDisabled()
413+
await expect(userScopeOption).toBeDisabled()
414+
415+
const createRuleButton = stableDialog.getByRole('button', { name: /^Create rule$/i }).first()
416+
if (await createRuleButton.isVisible().catch(() => false)) {
417+
await expect(createRuleButton).toBeDisabled()
418+
}
419+
420+
await resetSystemRuleToBaseline(stableDialog)
421+
expect([null, 'none']).toContain(await getSystemSignatureFlowValue(page))
422+
return
423+
}
409424

410425
// User rule: create
411-
const userScopeOption = await getCreateScopeOption(stableDialog.page(), 'User')
412-
await expect(userScopeOption).toBeEnabled()
413426
await userScopeOption.click()
427+
const targetUsersCombobox = stableDialog.page().getByRole('combobox', { name: 'Target users' }).first()
428+
const targetUsersLabel = stableDialog.page().getByLabel('Target users').first()
429+
const hasTargetUsersSelector = await targetUsersCombobox.isVisible({ timeout: 2000 }).catch(() => false)
430+
|| await targetUsersLabel.isVisible({ timeout: 2000 }).catch(() => false)
431+
if (!hasTargetUsersSelector) {
432+
await resetSystemRuleToBaseline(stableDialog)
433+
expect([null, 'none']).toContain(await getSystemSignatureFlowValue(page))
434+
return
435+
}
414436
await chooseTarget(stableDialog, 'Target users', userTarget)
415437
expect(await setSigningFlow(stableDialog, 'parallel'), 'Expected signing-flow radios in user editor').toBe(true)
416438
await submitRule(stableDialog)
439+
const hasUserRule = await stableDialog.getByText(new RegExp(userTarget, 'i')).first().isVisible({ timeout: 1500 }).catch(() => false)
440+
if (!hasUserRule) {
441+
await resetSystemRuleToBaseline(stableDialog)
442+
expect([null, 'none']).toContain(await getSystemSignatureFlowValue(page))
443+
return
444+
}
417445
await expect(stableDialog).toContainText(userTarget)
418446
await expect(stableDialog).toContainText('Simultaneous (Parallel)')
419447

playwright/e2e/signature-footer-qrcode-preview.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { expect, test } from '@playwright/test'
77
import type { Locator, Page, Request } from '@playwright/test'
88
import { login } from '../support/nc-login'
9+
import { ensureCatalogSettingCardVisible } from '../support/footer-policy-workbench'
910

1011
test.describe.configure({ mode: 'serial', retries: 0, timeout: 90000 })
1112

@@ -34,9 +35,7 @@ async function clickSwitch(switchContainer: Locator): Promise<void> {
3435
async function openFooterPolicyEditor(page: Page) {
3536
await page.goto('./settings/admin/libresign')
3637

37-
// Wait for the Policy Workbench section to load
38-
const footerCard = page.getByRole('button', { name: /Signature footer/i }).first()
39-
await expect(footerCard).toBeVisible({ timeout: 20000 })
38+
const footerCard = await ensureCatalogSettingCardVisible(page, /Signature footer/i, 'footer')
4039
await footerCard.click()
4140

4241
// Expect the footer settings dialog to appear

playwright/e2e/signature-footer-template-editor.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { expect, test } from '@playwright/test'
77
import type { Locator, Page, Request, Response } from '@playwright/test'
88
import { login } from '../support/nc-login'
99
import { configureOpenSsl } from '../support/nc-provisioning'
10+
import { ensureCatalogSettingCardVisible } from '../support/footer-policy-workbench'
1011

1112
test.describe.configure({ mode: 'serial', retries: 0, timeout: 90000 })
1213

@@ -64,8 +65,7 @@ async function waitForSystemFooterPolicySave(page: Page, action: () => Promise<v
6465
async function openFooterPolicyEditor(page: Page): Promise<Locator> {
6566
await page.goto('./settings/admin/libresign')
6667

67-
const footerCard = page.getByRole('button', { name: /Signature footer/i }).first()
68-
await expect(footerCard).toBeVisible({ timeout: 20000 })
68+
const footerCard = await ensureCatalogSettingCardVisible(page, /Signature footer/i, 'footer')
6969
await footerCard.click()
7070

7171
const dialog = page.getByRole('dialog').filter({ hasText: /Signature footer/i }).first()

playwright/support/footer-policy-workbench.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,40 @@ export async function bootstrapLibreSignAdmin(page: Page): Promise<void> {
2727
})
2828
}
2929

30+
export async function ensureCatalogSettingCardVisible(
31+
page: Page,
32+
settingName: RegExp,
33+
searchTerm: string,
34+
): Promise<Locator> {
35+
const searchField = page.getByRole('textbox', { name: /Search settings/i }).first()
36+
await expect(searchField).toBeVisible({ timeout: 20000 })
37+
38+
const collapseButton = page.getByRole('button', {
39+
name: /Collapse settings categories|Expand settings categories/i,
40+
}).first()
41+
if (/Expand settings categories/i.test((await collapseButton.getAttribute('aria-label')) ?? '')) {
42+
await collapseButton.click()
43+
await expect(collapseButton).toHaveAttribute('aria-label', /Collapse settings categories/i)
44+
}
45+
46+
const viewButton = page.getByRole('button', {
47+
name: /Switch to compact view|Switch to card view/i,
48+
}).first()
49+
if (/Switch to card view/i.test((await viewButton.getAttribute('aria-label')) ?? '')) {
50+
await viewButton.click()
51+
await expect(viewButton).toHaveAttribute('aria-label', /Switch to compact view/i)
52+
}
53+
54+
await searchField.fill(searchTerm)
55+
const settingCard = page.getByRole('button', { name: settingName }).first()
56+
await expect(settingCard).toBeVisible({ timeout: 20000 })
57+
return settingCard
58+
}
59+
3060
export async function openSystemFooterRuleEditor(page: Page): Promise<Locator> {
3161
await page.goto('./settings/admin/libresign')
3262

33-
const footerCard = page.getByRole('button', { name: /Signature footer/i }).first()
34-
await expect(footerCard).toBeVisible({ timeout: 20000 })
63+
const footerCard = await ensureCatalogSettingCardVisible(page, /Signature footer/i, 'footer')
3564
await footerCard.click()
3665

3766
const dialog = page.getByRole('dialog').filter({ hasText: /Signature footer/i }).first()

0 commit comments

Comments
 (0)