1
1
import { test , expect } from '@playwright/test' ;
2
2
import type { Locator , Page } from '@playwright/test' ;
3
3
import * as TEST_CONST from '../../testConstants' ;
4
- import { checkCursorPosition , setupInput } from './utils' ;
5
-
6
- const OPERATION_MODIFIER = process . platform === 'darwin' ? 'Meta' : 'Control' ;
4
+ import { checkCursorPosition , setupInput , getElementStyle , pressCmd } from './utils' ;
7
5
8
6
const pasteContent = async ( { text, page, inputLocator} : { text : string ; page : Page ; inputLocator : Locator } ) => {
9
7
await page . evaluate ( async ( pasteText ) => navigator . clipboard . writeText ( pasteText ) , text ) ;
10
8
await inputLocator . focus ( ) ;
11
- await inputLocator . press ( ` ${ OPERATION_MODIFIER } +v` ) ;
9
+ await pressCmd ( { inputLocator , command : 'v' } ) ;
12
10
} ;
13
11
14
12
test . beforeEach ( async ( { page, context, browserName} ) => {
15
13
await page . goto ( TEST_CONST . LOCAL_URL , { waitUntil : 'load' } ) ;
16
- if ( browserName === 'chromium' ) await context . grantPermissions ( [ 'clipboard-write' , 'clipboard-read' ] ) ;
14
+ if ( browserName === 'chromium' ) {
15
+ await context . grantPermissions ( [ 'clipboard-write' , 'clipboard-read' ] ) ;
16
+ }
17
17
} ) ;
18
18
19
19
test . describe ( 'paste content' , ( ) => {
20
- test . skip ( ( { browserName} ) => ! ! process . env . CI && browserName === 'webkit' , 'Excluded from webkit CI tests' ) ;
20
+ test . skip ( ( { browserName} ) => ! ! process . env . CI && browserName === 'webkit' , 'Excluded from WebKit CI tests' ) ;
21
21
22
22
test ( 'paste' , async ( { page} ) => {
23
23
const PASTE_TEXT = 'bold' ;
@@ -29,20 +29,16 @@ test.describe('paste content', () => {
29
29
await pasteContent ( { text : wrappedText , page, inputLocator} ) ;
30
30
31
31
const elementHandle = await inputLocator . locator ( 'span' , { hasText : PASTE_TEXT } ) . last ( ) ;
32
- let elementStyle ;
33
- if ( elementHandle ) {
34
- await elementHandle . waitFor ( { state : 'attached' } ) ;
32
+ const elementStyle = await getElementStyle ( elementHandle ) ;
35
33
36
- elementStyle = await elementHandle . getAttribute ( 'style' ) ;
37
- }
38
34
expect ( elementStyle ) . toEqual ( boldStyleDefinition . style ) ;
39
35
} ) ;
40
36
41
37
test ( 'paste replace' , async ( { page} ) => {
42
38
const inputLocator = await setupInput ( page , 'reset' ) ;
43
39
44
40
await inputLocator . focus ( ) ;
45
- await inputLocator . press ( ` ${ OPERATION_MODIFIER } +a` ) ;
41
+ await pressCmd ( { inputLocator , command : 'a' } ) ;
46
42
47
43
const newText = '*bold*' ;
48
44
await pasteContent ( { text : newText , page, inputLocator} ) ;
@@ -51,7 +47,7 @@ test.describe('paste content', () => {
51
47
} ) ;
52
48
53
49
test ( 'paste undo' , async ( { page, browserName} ) => {
54
- test . skip ( ! ! process . env . CI && browserName === 'firefox' , 'Excluded from firefox CI tests' ) ;
50
+ test . skip ( ! ! process . env . CI && browserName === 'firefox' , 'Excluded from Firefox CI tests' ) ;
55
51
56
52
const PASTE_TEXT_FIRST = '*bold*' ;
57
53
const PASTE_TEXT_SECOND = '@here' ;
@@ -60,13 +56,13 @@ test.describe('paste content', () => {
60
56
61
57
await page . evaluate ( async ( pasteText ) => navigator . clipboard . writeText ( pasteText ) , PASTE_TEXT_FIRST ) ;
62
58
63
- await inputLocator . press ( ` ${ OPERATION_MODIFIER } +v` ) ;
59
+ await pressCmd ( { inputLocator , command : 'v' } ) ;
64
60
await page . waitForTimeout ( TEST_CONST . INPUT_HISTORY_DEBOUNCE_TIME_MS ) ;
65
61
await page . evaluate ( async ( pasteText ) => navigator . clipboard . writeText ( pasteText ) , PASTE_TEXT_SECOND ) ;
66
- await inputLocator . press ( ` ${ OPERATION_MODIFIER } +v` ) ;
62
+ await pressCmd ( { inputLocator , command : 'v' } ) ;
67
63
await page . waitForTimeout ( TEST_CONST . INPUT_HISTORY_DEBOUNCE_TIME_MS ) ;
68
64
69
- await inputLocator . press ( ` ${ OPERATION_MODIFIER } +z` ) ;
65
+ await pressCmd ( { inputLocator , command : 'z' } ) ;
70
66
71
67
expect ( await inputLocator . innerText ( ) ) . toBe ( PASTE_TEXT_FIRST ) ;
72
68
} ) ;
@@ -78,32 +74,32 @@ test.describe('paste content', () => {
78
74
const inputLocator = await setupInput ( page , 'clear' ) ;
79
75
80
76
await page . evaluate ( async ( pasteText ) => navigator . clipboard . writeText ( pasteText ) , PASTE_TEXT_FIRST ) ;
81
- await inputLocator . press ( ` ${ OPERATION_MODIFIER } +v` ) ;
77
+ await pressCmd ( { inputLocator , command : 'v' } ) ;
82
78
await page . waitForTimeout ( TEST_CONST . INPUT_HISTORY_DEBOUNCE_TIME_MS ) ;
83
79
await page . evaluate ( async ( pasteText ) => navigator . clipboard . writeText ( pasteText ) , PASTE_TEXT_SECOND ) ;
84
80
await page . waitForTimeout ( TEST_CONST . INPUT_HISTORY_DEBOUNCE_TIME_MS ) ;
85
- await inputLocator . press ( ` ${ OPERATION_MODIFIER } +v` ) ;
81
+ await pressCmd ( { inputLocator , command : 'v' } ) ;
86
82
await page . waitForTimeout ( TEST_CONST . INPUT_HISTORY_DEBOUNCE_TIME_MS ) ;
87
83
88
- await inputLocator . press ( ` ${ OPERATION_MODIFIER } +z` ) ;
89
- await inputLocator . press ( ` ${ OPERATION_MODIFIER } + Shift+z` ) ;
84
+ await pressCmd ( { inputLocator , command : 'z' } ) ;
85
+ await pressCmd ( { inputLocator , command : ' Shift+z' } ) ;
90
86
91
87
expect ( await inputLocator . innerText ( ) ) . toBe ( `${ PASTE_TEXT_FIRST } ${ PASTE_TEXT_SECOND } ` ) ;
92
88
} ) ;
93
89
} ) ;
94
90
95
- test ( 'select' , async ( { page} ) => {
91
+ test ( 'select all ' , async ( { page} ) => {
96
92
const inputLocator = await setupInput ( page , 'reset' ) ;
97
93
await inputLocator . focus ( ) ;
98
- await inputLocator . press ( ` ${ OPERATION_MODIFIER } +a` ) ;
94
+ await pressCmd ( { inputLocator , command : 'a' } ) ;
99
95
100
96
const cursorPosition = await page . evaluate ( checkCursorPosition ) ;
101
97
102
98
expect ( cursorPosition ) . toBe ( TEST_CONST . EXAMPLE_CONTENT . length ) ;
103
99
} ) ;
104
100
105
101
test ( 'cut content changes' , async ( { page, browserName} ) => {
106
- test . skip ( ! ! process . env . CI && browserName === 'webkit' , 'Excluded from webkit CI tests' ) ;
102
+ test . skip ( ! ! process . env . CI && browserName === 'webkit' , 'Excluded from WebKit CI tests' ) ;
107
103
108
104
const INITIAL_CONTENT = 'bold' ;
109
105
const WRAPPED_CONTENT = TEST_CONST . MARKDOWN_STYLE_DEFINITIONS . bold . wrapContent ( INITIAL_CONTENT ) ;
@@ -133,7 +129,7 @@ test('cut content changes', async ({page, browserName}) => {
133
129
} , INITIAL_CONTENT ) ;
134
130
135
131
await inputLocator . focus ( ) ;
136
- await inputLocator . press ( ` ${ OPERATION_MODIFIER } +x` ) ;
132
+ await pressCmd ( { inputLocator , command : 'x' } ) ;
137
133
138
134
expect ( await rootHandle . innerHTML ( ) ) . toBe ( EXPECTED_CONTENT ) ;
139
135
} ) ;
0 commit comments