|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { deleteContentlets } from '@requests/contentlets'; |
| 3 | +import { ContentType, deleteContentType } from '@requests/contentType'; |
| 4 | +import { createPage, Page as DotPage } from '@requests/pages'; |
| 5 | +import { admin1 } from '@utils/credentials'; |
| 6 | +import { generateBase64Credentials } from '@utils/generateBase64Credential'; |
| 7 | + |
| 8 | +/** |
| 9 | + * SystemWorkflow ID — standard across all dotCMS instances. |
| 10 | + */ |
| 11 | +const SYSTEM_WORKFLOW_ID = 'd61a59e1-a49c-46f2-a929-db2b4bfa88b2'; |
| 12 | + |
| 13 | +type ContentTypeWithVariable = ContentType & { variable: string }; |
| 14 | + |
| 15 | +/** |
| 16 | + * Navigate to edit content for a given inode and click the Settings tab (tab index 3). |
| 17 | + * Uses direct navigation instead of goToContent() because HTML pages don't have |
| 18 | + * the data-testid="title" field that goToContent() waits for. |
| 19 | + */ |
| 20 | +async function navigateToSettingsTab(page: import('@playwright/test').Page, inode: string) { |
| 21 | + await page.goto(`/dotAdmin/#/content/${inode}`); |
| 22 | + await page.waitForLoadState('domcontentloaded'); |
| 23 | + // Wait for the edit content sidebar to confirm the editor has loaded |
| 24 | + await page.locator('dot-edit-content-sidebar').waitFor({ state: 'visible', timeout: 15000 }); |
| 25 | + |
| 26 | + // Settings tab is the p-tab containing the cog icon (tab index 3) |
| 27 | + const settingsTab = page.locator('p-tab:has(.pi-cog)'); |
| 28 | + await settingsTab.waitFor({ state: 'visible', timeout: 10000 }); |
| 29 | + await settingsTab.click(); |
| 30 | +} |
| 31 | + |
| 32 | +// ─── Permissions Dialog ─────────────────────────────────────────────────────── |
| 33 | + |
| 34 | +test.describe('Permissions Dialog', () => { |
| 35 | + test.describe.configure({ mode: 'serial' }); |
| 36 | + |
| 37 | + let htmlPage: DotPage; |
| 38 | + |
| 39 | + test.beforeAll(async ({ request }) => { |
| 40 | + htmlPage = await createPage(request, { |
| 41 | + contentType: 'htmlpageasset', |
| 42 | + title: `E2E Permissions Test Page ${Date.now()}`, |
| 43 | + url: `e2e-permissions-test-${Date.now()}`, |
| 44 | + template: 'SYSTEM_TEMPLATE', |
| 45 | + friendlyName: 'E2E Permissions Test Page', |
| 46 | + cachettl: 0 |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + test.afterAll(async ({ request }) => { |
| 51 | + if (htmlPage?.identifier) { |
| 52 | + await deleteContentlets(request, [htmlPage.identifier]); |
| 53 | + } |
| 54 | + }); |
| 55 | + |
| 56 | + test.describe('permissions card visibility', () => { |
| 57 | + test('permissions card is visible in settings tab for any saved contentlet @critical', async ({ |
| 58 | + page |
| 59 | + }) => { |
| 60 | + await navigateToSettingsTab(page, htmlPage.inode); |
| 61 | + |
| 62 | + await expect(page.getByTestId('permissions')).toBeAttached(); |
| 63 | + await expect(page.getByTestId('permissions-card')).toBeVisible(); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + test.describe('open permissions dialog', () => { |
| 68 | + test('clicking the permissions card opens the permissions dialog @critical', async ({ |
| 69 | + page |
| 70 | + }) => { |
| 71 | + await navigateToSettingsTab(page, htmlPage.inode); |
| 72 | + |
| 73 | + await expect(page.getByTestId('permissions-card')).toBeVisible(); |
| 74 | + await page.getByTestId('permissions-card').click(); |
| 75 | + |
| 76 | + await expect(page.locator('.p-dialog')).toBeVisible({ timeout: 10000 }); |
| 77 | + await expect(page.getByTestId('permissions-iframe')).toBeVisible({ timeout: 10000 }); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + test.describe('close permissions dialog', () => { |
| 82 | + test('close button dismisses the permissions dialog @critical', async ({ page }) => { |
| 83 | + await navigateToSettingsTab(page, htmlPage.inode); |
| 84 | + await page.getByTestId('permissions-card').click(); |
| 85 | + |
| 86 | + await expect(page.locator('.p-dialog')).toBeVisible({ timeout: 10000 }); |
| 87 | + await page.locator('.p-dialog-header-close, .p-dialog-close-button').click(); |
| 88 | + |
| 89 | + await expect(page.locator('.p-dialog')).toBeHidden(); |
| 90 | + await expect(page.getByTestId('permissions-card')).toBeVisible(); |
| 91 | + }); |
| 92 | + |
| 93 | + test('escape key does NOT close the permissions dialog @smoke', async ({ page }) => { |
| 94 | + await navigateToSettingsTab(page, htmlPage.inode); |
| 95 | + await page.getByTestId('permissions-card').click(); |
| 96 | + |
| 97 | + await expect(page.locator('.p-dialog')).toBeVisible({ timeout: 10000 }); |
| 98 | + await page.keyboard.press('Escape'); |
| 99 | + |
| 100 | + // Dialog must remain open — closeOnEscape: false by design |
| 101 | + await expect(page.locator('.p-dialog')).toBeVisible(); |
| 102 | + await expect(page.getByTestId('permissions-iframe')).toBeVisible(); |
| 103 | + }); |
| 104 | + }); |
| 105 | +}); |
| 106 | + |
| 107 | +// ─── Rules Dialog ───────────────────────────────────────────────────────────── |
| 108 | + |
| 109 | +test.describe('Rules Dialog', () => { |
| 110 | + // Serial mode ensures beforeAll runs once and all tests share the same page instance |
| 111 | + test.describe.configure({ mode: 'serial' }); |
| 112 | + |
| 113 | + let htmlPage: DotPage; |
| 114 | + |
| 115 | + test.beforeAll(async ({ request }) => { |
| 116 | + htmlPage = await createPage(request, { |
| 117 | + contentType: 'htmlpageasset', |
| 118 | + title: `E2E Rules Test Page ${Date.now()}`, |
| 119 | + url: `e2e-rules-test-${Date.now()}`, |
| 120 | + template: 'SYSTEM_TEMPLATE', |
| 121 | + friendlyName: 'E2E Rules Test Page', |
| 122 | + cachettl: 0 |
| 123 | + }); |
| 124 | + }); |
| 125 | + |
| 126 | + test.afterAll(async ({ request }) => { |
| 127 | + if (htmlPage?.identifier) { |
| 128 | + await deleteContentlets(request, [htmlPage.identifier]); |
| 129 | + } |
| 130 | + }); |
| 131 | + |
| 132 | + test.describe('rules card visibility', () => { |
| 133 | + test('rules card is visible in settings tab for saved HTML Page @critical', async ({ |
| 134 | + page |
| 135 | + }) => { |
| 136 | + await navigateToSettingsTab(page, htmlPage.inode); |
| 137 | + |
| 138 | + await expect(page.getByTestId('rules')).toBeAttached(); |
| 139 | + await expect(page.getByTestId('rules-card')).toBeVisible(); |
| 140 | + }); |
| 141 | + }); |
| 142 | + |
| 143 | + test.describe('open rules dialog', () => { |
| 144 | + test('clicking the rules card opens the rules dialog @critical', async ({ page }) => { |
| 145 | + await navigateToSettingsTab(page, htmlPage.inode); |
| 146 | + |
| 147 | + await expect(page.getByTestId('rules-card')).toBeVisible(); |
| 148 | + await page.getByTestId('rules-card').click(); |
| 149 | + |
| 150 | + await expect(page.locator('.p-dialog')).toBeVisible({ timeout: 10000 }); |
| 151 | + await expect(page.getByTestId('rules-container')).toBeVisible({ timeout: 10000 }); |
| 152 | + await expect(page.getByTestId('rules-empty')).not.toBeAttached(); |
| 153 | + }); |
| 154 | + }); |
| 155 | + |
| 156 | + test.describe('close rules dialog', () => { |
| 157 | + test('close button dismisses the rules dialog @critical', async ({ page }) => { |
| 158 | + await navigateToSettingsTab(page, htmlPage.inode); |
| 159 | + await page.getByTestId('rules-card').click(); |
| 160 | + |
| 161 | + await expect(page.locator('.p-dialog')).toBeVisible({ timeout: 10000 }); |
| 162 | + await page.locator('.p-dialog-header-close, .p-dialog-close-button').click(); |
| 163 | + |
| 164 | + await expect(page.locator('.p-dialog')).toBeHidden(); |
| 165 | + await expect(page.getByTestId('rules-card')).toBeVisible(); |
| 166 | + }); |
| 167 | + |
| 168 | + test('escape key does NOT close the rules dialog @smoke', async ({ page }) => { |
| 169 | + await navigateToSettingsTab(page, htmlPage.inode); |
| 170 | + await page.getByTestId('rules-card').click(); |
| 171 | + |
| 172 | + await expect(page.locator('.p-dialog')).toBeVisible({ timeout: 10000 }); |
| 173 | + await page.keyboard.press('Escape'); |
| 174 | + |
| 175 | + // Dialog must remain open — closeOnEscape: false by design |
| 176 | + await expect(page.locator('.p-dialog')).toBeVisible(); |
| 177 | + await expect(page.getByTestId('rules-container')).toBeVisible(); |
| 178 | + }); |
| 179 | + }); |
| 180 | + |
| 181 | + test.describe('prevent duplicate dialogs', () => { |
| 182 | + test('rapid repeated clicks open only one dialog @critical', async ({ page }) => { |
| 183 | + await navigateToSettingsTab(page, htmlPage.inode); |
| 184 | + |
| 185 | + const rulesCard = page.getByTestId('rules-card'); |
| 186 | + await expect(rulesCard).toBeVisible(); |
| 187 | + |
| 188 | + // After the first click, the dialog mask intercepts real pointer events on the card. |
| 189 | + // Programmatic HTMLElement.click() still fires on the card (stress test for duplicate opens). |
| 190 | + for (let i = 0; i < 3; i++) { |
| 191 | + await rulesCard.evaluate((el) => (el as HTMLElement).click()); |
| 192 | + } |
| 193 | + |
| 194 | + await expect(page.locator('.p-dialog')).toHaveCount(1, { timeout: 10000 }); |
| 195 | + }); |
| 196 | + }); |
| 197 | + |
| 198 | + test.describe('rules card not visible for non-Page content type', () => { |
| 199 | + test.describe.configure({ mode: 'serial' }); |
| 200 | + |
| 201 | + let contentType: ContentTypeWithVariable; |
| 202 | + let contentletInode: string; |
| 203 | + let contentletIdentifier: string; |
| 204 | + |
| 205 | + test.beforeEach(async ({ request }) => { |
| 206 | + const suffix = Date.now(); |
| 207 | + |
| 208 | + // Create a simple (non-Page) content type with the new editor enabled. |
| 209 | + // Avoids createFakeContentType which calls /api/v1/schemas (404). |
| 210 | + const ctResponse = await request.post('/api/v1/contenttype', { |
| 211 | + data: { |
| 212 | + clazz: 'com.dotcms.contenttype.model.type.ImmutableSimpleContentType', |
| 213 | + name: `RulesTestType${suffix}`, |
| 214 | + variable: `rulesCT${suffix}`, |
| 215 | + host: 'SYSTEM_HOST', |
| 216 | + folder: 'SYSTEM_FOLDER', |
| 217 | + metadata: { CONTENT_EDITOR2_ENABLED: true }, |
| 218 | + workflow: [SYSTEM_WORKFLOW_ID], |
| 219 | + fields: [ |
| 220 | + { |
| 221 | + clazz: 'com.dotcms.contenttype.model.field.ImmutableTextField', |
| 222 | + name: 'Title', |
| 223 | + variable: 'title', |
| 224 | + sortOrder: 1 |
| 225 | + } |
| 226 | + ] |
| 227 | + }, |
| 228 | + headers: { |
| 229 | + Authorization: generateBase64Credentials(admin1.username, admin1.password) |
| 230 | + } |
| 231 | + }); |
| 232 | + const ctData = await ctResponse.json(); |
| 233 | + contentType = (ctData.entity[0] ?? ctData.entity) as ContentTypeWithVariable; |
| 234 | + |
| 235 | + const contentletResponse = await request.post( |
| 236 | + '/api/v1/workflow/actions/default/fire/PUBLISH?indexPolicy=WAIT_FOR', |
| 237 | + { |
| 238 | + data: { |
| 239 | + contentlet: { |
| 240 | + contentType: contentType.variable, |
| 241 | + title: `Rules Non-Page Test ${suffix}` |
| 242 | + } |
| 243 | + }, |
| 244 | + headers: { |
| 245 | + Authorization: generateBase64Credentials(admin1.username, admin1.password) |
| 246 | + } |
| 247 | + } |
| 248 | + ); |
| 249 | + const contentletData = await contentletResponse.json(); |
| 250 | + const key = Object.keys(contentletData.entity.results[0])[0]; |
| 251 | + const contentlet = contentletData.entity.results[0][key]; |
| 252 | + contentletInode = contentlet.inode; |
| 253 | + contentletIdentifier = contentlet.identifier; |
| 254 | + }); |
| 255 | + |
| 256 | + test.afterEach(async ({ request }) => { |
| 257 | + if (contentletIdentifier) { |
| 258 | + await deleteContentlets(request, [contentletIdentifier]); |
| 259 | + } |
| 260 | + if (contentType?.id) { |
| 261 | + await deleteContentType(request, contentType.id); |
| 262 | + } |
| 263 | + }); |
| 264 | + |
| 265 | + test('rules card is absent in settings tab for non-Page contentlet @critical', async ({ |
| 266 | + page |
| 267 | + }) => { |
| 268 | + await navigateToSettingsTab(page, contentletInode); |
| 269 | + |
| 270 | + await expect(page.getByTestId('rules')).not.toBeAttached(); |
| 271 | + await expect(page.getByTestId('rules-card')).not.toBeAttached(); |
| 272 | + }); |
| 273 | + }); |
| 274 | +}); |
0 commit comments