Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions apps/web/src/activatable-row.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
import { describe, expect, test } from "bun:test";
import { afterEach, describe, expect, test } from "bun:test";

import {
isAdditiveSelectClick,
isRowActivationKey,
rowActivationProps,
} from "./activatable-row";

// `isAdditiveSelectClick`'s Mac/non-Mac branch reads `navigator.platform`,
// which happy-dom's `GlobalRegistrator` reports as whatever the *host* OS
// is — Darwin-flavored on a Mac, something else on Linux CI. Each test
// below pins the platform it means to exercise instead of inheriting the
// host's, so both branches are deterministic on any OS.
const originalPlatform = Object.getOwnPropertyDescriptor(navigator, "platform");

function stubPlatform(platform: string): void {
Object.defineProperty(navigator, "platform", {
configurable: true,
value: platform,
});
}

afterEach(() => {
if (originalPlatform !== undefined) {
Object.defineProperty(navigator, "platform", originalPlatform);
}
});

describe("isAdditiveSelectClick", () => {
// The test DOM reports a Darwin platform, so these exercise the Mac rules.
test("cmd-click is additive", () => {
expect(isAdditiveSelectClick({ metaKey: true, ctrlKey: false })).toBe(true);
});

test("ctrl-click is not additive on Mac (it's the context-menu gesture)", () => {
stubPlatform("MacIntel");
expect(isAdditiveSelectClick({ metaKey: false, ctrlKey: true })).toBe(
false,
);
});

test("ctrl-click is additive on non-Mac", () => {
stubPlatform("Linux x86_64");
expect(isAdditiveSelectClick({ metaKey: false, ctrlKey: true })).toBe(true);
});

test("a plain click is not additive", () => {
expect(isAdditiveSelectClick({ metaKey: false, ctrlKey: false })).toBe(
false,
Expand Down
8 changes: 8 additions & 0 deletions apps/web/test/library-page-selection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ beforeEach(() => {
configurable: true,
value: { writeText: mock(() => Promise.resolve()) },
});
// isAdditiveSelectClick's Mac/non-Mac branch reads navigator.platform,
// which happy-dom reports as whatever the host OS is — Darwin-flavored
// locally, something else on Linux CI. Pinned here so the ctrl-click
// test below exercises the Mac branch deterministically on any OS.
Object.defineProperty(navigator, "platform", {
configurable: true,
value: "MacIntel",
});
toastMock.mockClear();
});

Expand Down
Loading