33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55
6- import type { Page } from '@playwright/test'
76import { expect } from '@playwright/test'
8- import { test } from '../support/fixtures/random-user '
7+ import { test } from '../support/fixtures/editor-api '
98
109test . describe ( 'createTable API' , ( ) => {
11- const containerId = 'test-table'
12-
13- const createTable = async (
14- page : Page ,
15- options : { content : string ; readOnly : boolean } ,
16- ) => {
17- await page . evaluate (
18- async ( { containerId, content, readOnly } ) => {
19- const container = document . createElement ( 'div' )
20- container . id = containerId
21- container . style . position = 'fixed'
22- container . style . top = '0'
23- container . style . left = '0'
24- container . style . width = '100%'
25- container . style . height = '100%'
26- container . style . padding = '50px'
27- container . style . zIndex = '10000'
28- container . style . background = 'white'
29- document . body . appendChild ( container )
30-
31- // @ts -expect-error - OCA.Text is a global
32- await window . OCA . Text . createTable ( {
33- el : container ,
34- content,
35- readOnly,
36- } )
37- } ,
38- { containerId, ...options } ,
39- )
40- }
41-
4210 test . beforeEach ( async ( { page } ) => {
4311 // Open the files app so we're somewhere with `window.OCA.Text` available
4412 await page . goto ( '/apps/files' )
@@ -50,8 +18,9 @@ test.describe('createTable API', () => {
5018 } )
5119 } )
5220
53- test ( 'renders table editor' , async ( { page } ) => {
54- await createTable ( page , {
21+ test ( 'renders table editor' , async ( { page, createEditor, containerId } ) => {
22+ await createEditor ( {
23+ type : 'table' ,
5524 content : '| A | B |\n|---|---|\n| 1 | 2 |' ,
5625 readOnly : false ,
5726 } )
@@ -61,8 +30,13 @@ test.describe('createTable API', () => {
6130 await expect ( page . locator ( `#${ containerId } td` ) . first ( ) ) . toContainText ( '1' )
6231 } )
6332
64- test ( 'allows editing when not readonly' , async ( { page } ) => {
65- await createTable ( page , {
33+ test ( 'allows editing when not readonly' , async ( {
34+ page,
35+ createEditor,
36+ containerId,
37+ } ) => {
38+ await createEditor ( {
39+ type : 'table' ,
6640 content : '| A |\n|---|\n| x |' ,
6741 readOnly : false ,
6842 } )
@@ -75,9 +49,13 @@ test.describe('createTable API', () => {
7549
7650 await expect ( cell ) . toContainText ( 'edited' )
7751 } )
78-
79- test ( 'prevents editing when readonly' , async ( { page } ) => {
80- await createTable ( page , {
52+ test ( 'prevents editing when readonly' , async ( {
53+ page,
54+ createEditor,
55+ containerId,
56+ } ) => {
57+ await createEditor ( {
58+ type : 'table' ,
8159 content : '| A |\n|---|---|\n| 1 |' ,
8260 readOnly : true ,
8361 } )
0 commit comments