@@ -22,19 +22,21 @@ export class EditorFixture {
22
22
private diagnosticsGutterIcon ! : Locator
23
23
public codeContent ! : Locator
24
24
public activeLine ! : Locator
25
+ public lines ! : Locator
25
26
26
27
constructor ( page : Page ) {
27
28
this . page = page
28
29
this . codeContent = page . locator ( '.cm-content[data-language="kcl"]' )
29
30
this . diagnosticsTooltip = page . locator ( '.cm-tooltip-lint' )
30
31
this . diagnosticsGutterIcon = page . locator ( '.cm-lint-marker-error' )
31
32
this . activeLine = this . page . locator ( '.cm-activeLine' )
33
+ this . lines = this . page . locator ( '.cm-line' )
32
34
}
33
35
34
36
private _expectEditorToContain =
35
37
( not = false ) =>
36
38
async (
37
- code : string ,
39
+ code : string | RegExp ,
38
40
{
39
41
shouldNormalise = false ,
40
42
timeout = 5_000 ,
@@ -49,17 +51,21 @@ export class EditorFixture {
49
51
await this . closePane ( )
50
52
}
51
53
}
54
+
55
+ await this . scrollToBottom ( )
52
56
if ( ! shouldNormalise ) {
53
- const expectStart = expect . poll ( ( ) => this . codeContent . textContent ( ) )
54
- if ( not ) {
55
- const result = await expectStart . not . toContain ( code )
56
- await resetPane ( )
57
- return result
58
- }
59
- const result = await expectStart . toContain ( code )
57
+ const result = not
58
+ ? await expect ( this . codeContent ) . not . toContainText ( code )
59
+ : await expect ( this . codeContent ) . toContainText ( code )
60
+
60
61
await resetPane ( )
61
62
return result
62
63
}
64
+ if ( typeof code !== 'string' ) {
65
+ throw new Error (
66
+ 'The `shouldNormalise` option does not work with a RegExp value for `code` argument'
67
+ )
68
+ }
63
69
const normalisedCode = code . replaceAll ( / \s + / g, '' ) . trim ( )
64
70
const expectStart = expect . poll (
65
71
async ( ) => {
@@ -88,14 +94,24 @@ export class EditorFixture {
88
94
} ,
89
95
}
90
96
getCurrentCode = async ( ) => {
91
- return await this . codeContent . innerText ( )
97
+ const isOpen = await this . checkIfPaneIsOpen ( )
98
+ if ( isOpen ) {
99
+ await this . scrollToBottom ( )
100
+ return await this . codeContent . innerText ( )
101
+ }
102
+
103
+ await this . openPane ( )
104
+ await this . scrollToBottom ( )
105
+ const code = await this . codeContent . innerText ( )
106
+ await this . closePane ( )
107
+ return code
92
108
}
93
109
snapshot = async ( options ?: { timeout ?: number ; name ?: string } ) => {
94
110
const wasPaneOpen = await this . checkIfPaneIsOpen ( )
95
111
if ( ! wasPaneOpen ) {
96
112
await this . openPane ( )
97
113
}
98
-
114
+ await this . scrollToBottom ( )
99
115
try {
100
116
// Use expect.poll to implement retry logic
101
117
await expect
@@ -180,6 +196,16 @@ export class EditorFixture {
180
196
openPane ( ) {
181
197
return openPane ( this . page , this . paneButtonTestId )
182
198
}
199
+ async scrollToBottom ( ) {
200
+ let nextLineCount = await this . lines . count ( )
201
+ let currLineCount : number
202
+ do {
203
+ currLineCount = nextLineCount
204
+ await this . lines . last ( ) . scrollIntoViewIfNeeded ( )
205
+ await this . page . waitForTimeout ( 50 )
206
+ nextLineCount = await this . lines . count ( )
207
+ } while ( nextLineCount !== currLineCount )
208
+ }
183
209
scrollToText ( text : string , placeCursor ?: boolean ) {
184
210
return this . page . evaluate (
185
211
( args : { text : string ; placeCursor ?: boolean } ) => {
0 commit comments