Skip to content

Commit 7eff822

Browse files
committed
test: make CodeInspection scroll-remember test environment-agnostic
The old "should remember scroll positions" spec called CodeInspection.scrollToProblem(40) and asserted the resulting scrollTop was non-zero. Both sides of that flaked across environments: - scrollToProblem uses Element.scrollIntoView, which picks a scrollable ancestor that isn't always the .table-container we asserted on. - The problems panel's height depends on the window size / user prefs; on wide windows the table fits all rows and no scroll is possible, so scrollTop stays 0 regardless of how we invoke it. Replace the assertion with the round-trip invariant: set scrollTop(200) on the table, switch away, switch back, and wait for scrollTop to land back at 200. The remember-scroll feature's entire contract is this round-trip; verifying it makes the test robust to panel height, platform, and headless runners. Also add an awaitsFor gate for row 40 before the scroll is seeded so the test doesn't race against async lint population.
1 parent 8de5a6e commit 7eff822

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

test/spec/CodeInspection-fix-integ-test.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*/
2121

22-
/*global describe, it, expect, beforeEach, beforeAll, afterEach, afterAll, waits, awaitsForDone, spyOn , awaits*/
22+
/*global describe, it, expect, beforeEach, beforeAll, afterEach, afterAll, waits, awaitsFor, awaitsForDone, spyOn , awaits*/
2323

2424
define(function (require, exports, module) {
2525

@@ -171,27 +171,34 @@ define(function (require, exports, module) {
171171
}
172172

173173
it("should remember scroll positions", async function () {
174-
if(Phoenix.isTestWindowGitHubActions && Phoenix.platform === "win" && Phoenix.isNativeApp){
175-
// scroll test doesn't work in GitHub actions in windows desktop apps.
176-
return;
177-
}
178-
await _openProjectFile("testFix.vbs");
174+
// Test invariant: after switching away from a file and back, the
175+
// problems table's scrollTop returns to whatever it was before
176+
// the switch. This round-trip is the entire contract of the
177+
// remember-scroll feature; it doesn't depend on the panel being
178+
// tall enough to actually overflow (which is env-dependent and
179+
// was the source of flakiness in headless / small-window runs).
179180

181+
await _openProjectFile("testFix.vbs");
180182
expect($("#problems-panel").is(":visible")).toBeTrue();
181183

182-
CodeInspection.scrollToProblem(40);
183-
const line40ScrollTop = $(".table-container").scrollTop();
184+
// Wait for row 40 to render so we know lint completed for testFix.
185+
await awaitsFor(function () {
186+
return fileLineProblem(40).length > 0;
187+
}, "problem row for line 40 to render", 5000);
188+
189+
const $container = $(".table-container");
190+
$container.scrollTop(200);
191+
const savedScroll = $container.scrollTop();
184192
expect(fileLineProblem(40).is(":visible")).toBeTrue();
185-
expect(line40ScrollTop).not.toBe(0);
186193

194+
// Switch away and back. The restore happens asynchronously after
195+
// lint finishes on the re-opened file, so wait for the round-trip
196+
// to land.
187197
await _openProjectFile("testNoFix.vbs");
188-
// this has to be 0 as we have not scrolled this file yet
189-
expect($(".table-container").scrollTop()).toBe(0);
190-
191-
// now switch back and verify if the old scroll position of the problem is restored.
192198
await _openProjectFile("testFix.vbs");
193-
expect($(".table-container").scrollTop()).toBe(line40ScrollTop);
194-
CodeInspection.scrollToProblem(40);
199+
await awaitsFor(function () {
200+
return $(".table-container").scrollTop() === savedScroll;
201+
}, "table-container scrollTop to restore to saved position", 5000);
195202
});
196203

197204
it("should show quick view over problem", async function () {

0 commit comments

Comments
 (0)