Skip to content

Commit 9445feb

Browse files
authored
Update longest multi-profile sketch E2E test to not check specific KCL values (#8010)
We should and do capture that sort of thing elsewhere. This is another breakout PR from #7802, towards #7222. I've confirmed it works locally on MacOS both against `main` and the branch for #7802.
1 parent 5c66351 commit 9445feb

File tree

2 files changed

+99
-137
lines changed

2 files changed

+99
-137
lines changed

e2e/playwright/fixtures/editorFixture.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ export class EditorFixture {
2222
private diagnosticsGutterIcon!: Locator
2323
public codeContent!: Locator
2424
public activeLine!: Locator
25+
public lines!: Locator
2526

2627
constructor(page: Page) {
2728
this.page = page
2829
this.codeContent = page.locator('.cm-content[data-language="kcl"]')
2930
this.diagnosticsTooltip = page.locator('.cm-tooltip-lint')
3031
this.diagnosticsGutterIcon = page.locator('.cm-lint-marker-error')
3132
this.activeLine = this.page.locator('.cm-activeLine')
33+
this.lines = this.page.locator('.cm-line')
3234
}
3335

3436
private _expectEditorToContain =
3537
(not = false) =>
3638
async (
37-
code: string,
39+
code: string | RegExp,
3840
{
3941
shouldNormalise = false,
4042
timeout = 5_000,
@@ -49,17 +51,21 @@ export class EditorFixture {
4951
await this.closePane()
5052
}
5153
}
54+
55+
await this.scrollToBottom()
5256
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+
6061
await resetPane()
6162
return result
6263
}
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+
}
6369
const normalisedCode = code.replaceAll(/\s+/g, '').trim()
6470
const expectStart = expect.poll(
6571
async () => {
@@ -88,14 +94,24 @@ export class EditorFixture {
8894
},
8995
}
9096
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
92108
}
93109
snapshot = async (options?: { timeout?: number; name?: string }) => {
94110
const wasPaneOpen = await this.checkIfPaneIsOpen()
95111
if (!wasPaneOpen) {
96112
await this.openPane()
97113
}
98-
114+
await this.scrollToBottom()
99115
try {
100116
// Use expect.poll to implement retry logic
101117
await expect
@@ -180,6 +196,16 @@ export class EditorFixture {
180196
openPane() {
181197
return openPane(this.page, this.paneButtonTestId)
182198
}
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+
}
183209
scrollToText(text: string, placeCursor?: boolean) {
184210
return this.page.evaluate(
185211
(args: { text: string; placeCursor?: boolean }) => {

0 commit comments

Comments
 (0)