Skip to content

Commit ed7a2f7

Browse files
committed
feat: integ tests for tab bar scrolling
1 parent c87e586 commit ed7a2f7

File tree

1 file changed

+268
-0
lines changed

1 file changed

+268
-0
lines changed

test/spec/Extn-Tabbar-integ-test.js

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,5 +2307,273 @@ define(function (require, exports, module) {
23072307
MainViewManager.setLayoutScheme(1, 2);
23082308
});
23092309
});
2310+
2311+
describe("Tab Bar Scrolling", function () {
2312+
let longTestFilePaths = [];
2313+
2314+
beforeEach(async function () {
2315+
// Create multiple test files to ensure scrolling is needed
2316+
longTestFilePaths = [];
2317+
for (let i = 1; i <= 15; i++) {
2318+
const filePath = SpecRunnerUtils.getTempDirectory() + `/scroll-test-file-${i}.js`;
2319+
longTestFilePaths.push(filePath);
2320+
await jsPromise(
2321+
SpecRunnerUtils.createTextFile(filePath, `// Test file ${i} for scrolling`, FileSystem)
2322+
);
2323+
}
2324+
2325+
// Open all files to create many tabs
2326+
for (let filePath of longTestFilePaths) {
2327+
await awaitsForDone(
2328+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: filePath }),
2329+
`Open ${filePath}`
2330+
);
2331+
}
2332+
2333+
// Wait for tabs to be rendered
2334+
await awaitsFor(
2335+
function () {
2336+
return getTabCount() >= 15;
2337+
},
2338+
"All tabs to be created",
2339+
3000
2340+
);
2341+
});
2342+
2343+
afterEach(async function () {
2344+
// Close all test files
2345+
for (let filePath of longTestFilePaths) {
2346+
const fileObj = FileSystem.getFileForPath(filePath);
2347+
try {
2348+
await awaitsForDone(
2349+
CommandManager.execute(Commands.FILE_CLOSE, { file: fileObj }),
2350+
`Close ${filePath}`
2351+
);
2352+
} catch (e) {
2353+
// Ignore errors if file is already closed
2354+
}
2355+
}
2356+
});
2357+
2358+
it("should scroll tab bar horizontally when mouse wheel is scrolled", function () {
2359+
const $tabBar = $("#phoenix-tab-bar");
2360+
expect($tabBar.length).toBe(1);
2361+
2362+
// Get initial scroll position
2363+
const initialScrollLeft = $tabBar.scrollLeft();
2364+
2365+
// Create a wheel event for scrolling down (should scroll right)
2366+
const wheelEventDown = $.Event("wheel");
2367+
wheelEventDown.originalEvent = { deltaY: 100 }; // Positive deltaY = scroll down/right
2368+
2369+
// Trigger the wheel event
2370+
$tabBar.trigger(wheelEventDown);
2371+
2372+
// Check that scroll position has changed to the right
2373+
const scrollAfterDown = $tabBar.scrollLeft();
2374+
expect(scrollAfterDown).toBeGreaterThan(initialScrollLeft);
2375+
// Verify the scroll amount is proportional to deltaY (implementation multiplies by 2.5)
2376+
expect(scrollAfterDown - initialScrollLeft).toBeCloseTo(100 * 2.5, 0);
2377+
2378+
// Create a wheel event for scrolling up (should scroll left)
2379+
const wheelEventUp = $.Event("wheel");
2380+
wheelEventUp.originalEvent = { deltaY: -100 }; // Negative deltaY = scroll up/left
2381+
2382+
// Trigger the wheel event
2383+
$tabBar.trigger(wheelEventUp);
2384+
2385+
// Check that scroll position has moved left from the previous position
2386+
const scrollAfterUp = $tabBar.scrollLeft();
2387+
expect(scrollAfterUp).toBeLessThan(scrollAfterDown);
2388+
// Verify the scroll amount is proportional to deltaY
2389+
expect(scrollAfterDown - scrollAfterUp).toBeCloseTo(100 * 2.5, 0);
2390+
});
2391+
2392+
it("should scroll tab bar with trackpad scrolling", function () {
2393+
const $tabBar = $("#phoenix-tab-bar");
2394+
expect($tabBar.length).toBe(1);
2395+
2396+
// Get initial scroll position
2397+
const initialScrollLeft = $tabBar.scrollLeft();
2398+
2399+
// Create a wheel event simulating trackpad scrolling (smaller deltaY values)
2400+
const trackpadEvent = $.Event("wheel");
2401+
trackpadEvent.originalEvent = { deltaY: 25 }; // Smaller value typical of trackpad
2402+
2403+
// Trigger the trackpad scrolling event multiple times
2404+
for (let i = 0; i < 4; i++) {
2405+
$tabBar.trigger(trackpadEvent);
2406+
}
2407+
2408+
// Check that scroll position has changed
2409+
const scrollAfterTrackpad = $tabBar.scrollLeft();
2410+
expect(scrollAfterTrackpad).toBeGreaterThan(initialScrollLeft);
2411+
// Verify the total scroll amount after multiple small scrolls
2412+
// 4 scrolls of 25 * 2.5 = 250 pixels total
2413+
expect(scrollAfterTrackpad - initialScrollLeft).toBeCloseTo(4 * 25 * 2.5, 0);
2414+
});
2415+
2416+
it("should scroll second pane tab bar when it exists", async function () {
2417+
// Create the second pane first
2418+
MainViewManager.setLayoutScheme(1, 2);
2419+
2420+
// Wait for the layout to be created
2421+
await awaitsFor(
2422+
function () {
2423+
return MainViewManager.getPaneIdList().length === 2;
2424+
},
2425+
"Second pane to be created",
2426+
1000
2427+
);
2428+
2429+
// Open a file in the second pane to create the second tab bar
2430+
await awaitsForDone(
2431+
CommandManager.execute(Commands.FILE_OPEN, {
2432+
fullPath: longTestFilePaths[0],
2433+
paneId: "second-pane"
2434+
}),
2435+
"Open file in second pane"
2436+
);
2437+
2438+
// Wait for second tab bar to appear
2439+
await awaitsFor(
2440+
function () {
2441+
return $("#phoenix-tab-bar-2").length > 0;
2442+
},
2443+
"Second tab bar to appear",
2444+
1000
2445+
);
2446+
2447+
const $tabBar2 = $("#phoenix-tab-bar-2");
2448+
expect($tabBar2.length).toBe(1);
2449+
2450+
// Open multiple files in second pane to enable scrolling
2451+
for (let i = 1; i < 8; i++) {
2452+
await awaitsForDone(
2453+
CommandManager.execute(Commands.FILE_OPEN, {
2454+
fullPath: longTestFilePaths[i],
2455+
paneId: "second-pane"
2456+
}),
2457+
`Open file ${i} in second pane`
2458+
);
2459+
}
2460+
2461+
// Wait for tabs to be rendered in second pane
2462+
await awaitsFor(
2463+
function () {
2464+
return $tabBar2.find(".tab").length >= 8;
2465+
},
2466+
"Tabs to be created in second pane",
2467+
2000
2468+
);
2469+
2470+
// Get initial scroll position of second tab bar
2471+
const initialScrollLeft = $tabBar2.scrollLeft();
2472+
2473+
// Create a wheel event for scrolling
2474+
const wheelEvent = $.Event("wheel");
2475+
wheelEvent.originalEvent = { deltaY: 150 };
2476+
2477+
// Trigger the wheel event on second tab bar
2478+
$tabBar2.trigger(wheelEvent);
2479+
2480+
// Check that scroll position has changed
2481+
const scrollAfterWheel = $tabBar2.scrollLeft();
2482+
expect(scrollAfterWheel).toBeGreaterThan(initialScrollLeft);
2483+
// Verify the scroll amount is proportional to deltaY
2484+
expect(scrollAfterWheel - initialScrollLeft).toBeCloseTo(150 * 2.5, 0);
2485+
2486+
// Reset layout scheme back to single pane
2487+
MainViewManager.setLayoutScheme(1, 1);
2488+
});
2489+
2490+
it("should calculate correct scroll amount based on deltaY", function () {
2491+
const $tabBar = $("#phoenix-tab-bar");
2492+
expect($tabBar.length).toBe(1);
2493+
2494+
// Ensure the tab bar is scrollable by checking if scrollWidth > clientWidth
2495+
if ($tabBar[0].scrollWidth <= $tabBar[0].clientWidth) {
2496+
// Skip test if tab bar is not scrollable
2497+
return;
2498+
}
2499+
2500+
// Set initial scroll position to middle to allow scrolling in both directions
2501+
const maxScroll = $tabBar[0].scrollWidth - $tabBar[0].clientWidth;
2502+
const midScroll = Math.floor(maxScroll / 2);
2503+
$tabBar.scrollLeft(midScroll);
2504+
2505+
// Test positive deltaY (scroll right)
2506+
const initialScrollLeft = $tabBar.scrollLeft();
2507+
const wheelEventRight = $.Event("wheel");
2508+
wheelEventRight.originalEvent = { deltaY: 40 };
2509+
$tabBar.trigger(wheelEventRight);
2510+
2511+
const scrollAfterRight = $tabBar.scrollLeft();
2512+
expect(scrollAfterRight).toBeGreaterThan(initialScrollLeft);
2513+
expect(scrollAfterRight - initialScrollLeft).toBeCloseTo(40 * 2.5, 0);
2514+
2515+
// Reset and test negative deltaY (scroll left)
2516+
$tabBar.scrollLeft(midScroll);
2517+
const wheelEventLeft = $.Event("wheel");
2518+
wheelEventLeft.originalEvent = { deltaY: -40 };
2519+
$tabBar.trigger(wheelEventLeft);
2520+
2521+
const scrollAfterLeft = $tabBar.scrollLeft();
2522+
expect(scrollAfterLeft).toBeLessThan(midScroll);
2523+
expect(midScroll - scrollAfterLeft).toBeCloseTo(40 * 2.5, 0);
2524+
});
2525+
2526+
it("should not scroll beyond the scrollable bounds", function () {
2527+
const $tabBar = $("#phoenix-tab-bar");
2528+
expect($tabBar.length).toBe(1);
2529+
2530+
// Get the maximum scrollable width
2531+
const maxScrollLeft = $tabBar[0].scrollWidth - $tabBar[0].clientWidth;
2532+
2533+
// Scroll far to the right
2534+
$tabBar.scrollLeft(maxScrollLeft + 1000); // Try to scroll beyond max
2535+
2536+
// Create a wheel event to scroll further right
2537+
const wheelEventRight = $.Event("wheel");
2538+
wheelEventRight.originalEvent = { deltaY: 500 }; // Large scroll right
2539+
$tabBar.trigger(wheelEventRight);
2540+
2541+
// Should not exceed maximum scroll
2542+
expect($tabBar.scrollLeft()).toBeLessThanOrEqual(maxScrollLeft);
2543+
2544+
// Scroll far to the left
2545+
$tabBar.scrollLeft(-1000); // Try to scroll beyond minimum
2546+
2547+
// Create a wheel event to scroll further left
2548+
const wheelEventLeft = $.Event("wheel");
2549+
wheelEventLeft.originalEvent = { deltaY: -500 }; // Large scroll left
2550+
$tabBar.trigger(wheelEventLeft);
2551+
2552+
// Should not go below 0
2553+
expect($tabBar.scrollLeft()).toBeGreaterThanOrEqual(0);
2554+
});
2555+
2556+
it("should handle rapid consecutive scroll events", function () {
2557+
const $tabBar = $("#phoenix-tab-bar");
2558+
expect($tabBar.length).toBe(1);
2559+
2560+
const initialScrollLeft = $tabBar.scrollLeft();
2561+
2562+
// Trigger multiple rapid scroll events
2563+
for (let i = 0; i < 10; i++) {
2564+
const wheelEvent = $.Event("wheel");
2565+
wheelEvent.originalEvent = { deltaY: 50 };
2566+
$tabBar.trigger(wheelEvent);
2567+
}
2568+
2569+
// Should have scrolled significantly
2570+
const finalScrollLeft = $tabBar.scrollLeft();
2571+
expect(finalScrollLeft).toBeGreaterThan(initialScrollLeft + 100);
2572+
2573+
// Verify the total scroll amount after multiple events
2574+
// 10 scrolls of 50 * 2.5 = 1250 pixels total
2575+
expect(finalScrollLeft - initialScrollLeft).toBeCloseTo(10 * 50 * 2.5, 0);
2576+
});
2577+
});
23102578
});
23112579
});

0 commit comments

Comments
 (0)