|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { expect, mergeTests } from '@playwright/test' |
| 7 | +import { test as uploadFileTest } from '../support/fixtures/upload-file' |
| 8 | +import { test as randomUserTest } from '../support/fixtures/random-user' |
| 9 | + |
| 10 | +const test = mergeTests(uploadFileTest, randomUserTest) |
| 11 | + |
| 12 | +test.describe('createTable API', () => { |
| 13 | + test.beforeEach(async ({ open, page }) => { |
| 14 | + await open() |
| 15 | + |
| 16 | + // Load the editor API bundle |
| 17 | + await page.evaluate(async () => { |
| 18 | + await import('/apps/text/js/text-editor.mjs') |
| 19 | + }) |
| 20 | + }) |
| 21 | + |
| 22 | + test('renders table editor', async ({ page }) => { |
| 23 | + await page.evaluate(async () => { |
| 24 | + const container = document.createElement('div') |
| 25 | + container.id = 'test-table' |
| 26 | + document.body.appendChild(container) |
| 27 | + |
| 28 | + // @ts-expect-error - OCA.Text is a global |
| 29 | + await window.OCA.Text.createTable({ |
| 30 | + el: container, |
| 31 | + content: '| A | B |\n|---|---|\n| 1 | 2 |', |
| 32 | + readOnly: false, |
| 33 | + }) |
| 34 | + }) |
| 35 | + |
| 36 | + await expect(page.locator('#test-table table')).toBeVisible() |
| 37 | + await expect(page.locator('#test-table th').first()).toContainText('A') |
| 38 | + await expect(page.locator('#test-table td').first()).toContainText('1') |
| 39 | + }) |
| 40 | + |
| 41 | + test('allows editing when not readonly', async ({ page }) => { |
| 42 | + await page.evaluate(async () => { |
| 43 | + const container = document.createElement('div') |
| 44 | + container.id = 'test-editable' |
| 45 | + container.style.position = 'fixed' |
| 46 | + container.style.top = '10px' |
| 47 | + container.style.left = '10px' |
| 48 | + container.style.zIndex = '10000' |
| 49 | + container.style.background = 'white' |
| 50 | + document.body.appendChild(container) |
| 51 | + |
| 52 | + // @ts-expect-error - OCA.Text is a global |
| 53 | + await window.OCA.Text.createTable({ |
| 54 | + el: container, |
| 55 | + content: '| A |\n|---|\n| x |', |
| 56 | + readOnly: false, |
| 57 | + }) |
| 58 | + }) |
| 59 | + |
| 60 | + const cell = page.locator('#test-editable .ProseMirror td').first() |
| 61 | + await cell.click({ force: true }) |
| 62 | + await page.waitForTimeout(100) |
| 63 | + await cell.selectText() |
| 64 | + await page.keyboard.type('edited') |
| 65 | + |
| 66 | + await expect(cell).toContainText('edited') |
| 67 | + }) |
| 68 | + |
| 69 | + test('prevents editing when readonly', async ({ page }) => { |
| 70 | + await page.evaluate(async () => { |
| 71 | + const container = document.createElement('div') |
| 72 | + container.id = 'test-readonly' |
| 73 | + document.body.appendChild(container) |
| 74 | + |
| 75 | + // @ts-expect-error - OCA.Text is a global |
| 76 | + await window.OCA.Text.createTable({ |
| 77 | + el: container, |
| 78 | + content: '| A |\n|---|---|\n| 1 |', |
| 79 | + readOnly: true, |
| 80 | + }) |
| 81 | + }) |
| 82 | + |
| 83 | + const editable = page.locator('#test-readonly [contenteditable]').first() |
| 84 | + await expect(editable).toHaveAttribute('contenteditable', 'false') |
| 85 | + }) |
| 86 | +}) |
0 commit comments