test: cut low-value tests, rewrite the rest around behavior, parallelize lanes (#285)

This commit is contained in:
sudacode authored and GitHub committed 2026-10-05 00:07:44 -07:00
1 parent 4b6842d034
commit b48083ddd8
368 files changed
+18045 -60331

No files matched your search

+119 -336
View File
@@ -1,27 +1,27 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { syncOverlayMouseIgnoreState } from './overlay-mouse-ignore.js';
import { createRendererState, type RendererState } from './state.js';
import { YOMITAN_POPUP_VISIBLE_HOST_SELECTOR } from './yomitan-popup.js';
function createClassList() {
const classes = new Set<string>();
return {
add: (...tokens: string[]) => {
for (const token of tokens) classes.add(token);
},
remove: (...tokens: string[]) => {
for (const token of tokens) classes.delete(token);
},
contains: (token: string) => classes.has(token),
};
type IgnoreCall = { ignore: boolean; forward?: boolean };
type RunOptions = {
// `toggle` matches Windows/macOS (renderer toggles ignore), `linux` matches the cursor-poll path.
platform: 'toggle' | 'linux';
state?: Partial<RendererState>;
// Popup host marked visible in the DOM, independent of the cached `yomitanPopupVisible` flag.
popupHostVisible?: boolean;
sidebarSelecting?: boolean;
};
function makeState(overrides: Partial<RendererState> = {}): RendererState {
return { ...createRendererState(), ...overrides };
}
function replaceGlobalProperty(key: 'window' | 'document', value: unknown): () => void {
const original = Object.getOwnPropertyDescriptor(globalThis, key);
Object.defineProperty(globalThis, key, {
configurable: true,
writable: true,
value,
});
Object.defineProperty(globalThis, key, { configurable: true, writable: true, value });
return () => {
if (original) {
Object.defineProperty(globalThis, key, original);
@@ -31,342 +31,125 @@ function replaceGlobalProperty(key: 'window' | 'document', value: unknown): () =
};
}
test('idle visible overlay starts click-through on platforms that toggle mouse ignore', () => {
const classList = createClassList();
const ignoreCalls: Array<{ ignore: boolean; forward?: boolean }> = [];
const restoreWindow = replaceGlobalProperty('window', {
electronAPI: {
setIgnoreMouseEvents: (ignore: boolean, options?: { forward?: boolean }) => {
ignoreCalls.push({ ignore, forward: options?.forward });
},
},
});
try {
syncOverlayMouseIgnoreState({
dom: {
overlay: { classList },
},
platform: {
shouldToggleMouseIgnore: true,
},
state: {
isOverSubtitle: false,
isOverSubtitleSidebar: false,
yomitanPopupVisible: false,
controllerSelectModalOpen: false,
controllerDebugModalOpen: false,
jimakuModalOpen: false,
youtubePickerModalOpen: false,
kikuModalOpen: false,
runtimeOptionsModalOpen: false,
subsyncModalOpen: false,
sessionHelpModalOpen: false,
subtitleSidebarModalOpen: false,
subtitleSidebarConfig: null,
},
} as never);
assert.equal(classList.contains('interactive'), false);
assert.deepEqual(ignoreCalls, [{ ignore: true, forward: true }]);
} finally {
restoreWindow();
}
});
test('youtube picker keeps overlay interactive even when subtitle hover is inactive', () => {
const classList = createClassList();
const ignoreCalls: Array<{ ignore: boolean; forward?: boolean }> = [];
const restoreWindow = replaceGlobalProperty('window', {
electronAPI: {
setIgnoreMouseEvents: (ignore: boolean, options?: { forward?: boolean }) => {
ignoreCalls.push({ ignore, forward: options?.forward });
},
},
});
try {
syncOverlayMouseIgnoreState({
dom: {
overlay: { classList },
},
platform: {
shouldToggleMouseIgnore: true,
},
state: {
isOverSubtitle: false,
isOverSubtitleSidebar: false,
yomitanPopupVisible: false,
controllerSelectModalOpen: false,
controllerDebugModalOpen: false,
jimakuModalOpen: false,
youtubePickerModalOpen: true,
kikuModalOpen: false,
runtimeOptionsModalOpen: false,
subsyncModalOpen: false,
sessionHelpModalOpen: false,
subtitleSidebarModalOpen: false,
subtitleSidebarConfig: null,
},
} as never);
assert.equal(classList.contains('interactive'), true);
assert.deepEqual(ignoreCalls, [{ ignore: false, forward: undefined }]);
} finally {
restoreWindow();
}
});
test('visible yomitan popup host keeps overlay interactive even when cached popup state is false', () => {
const classList = createClassList();
const ignoreCalls: Array<{ ignore: boolean; forward?: boolean }> = [];
const restoreWindow = replaceGlobalProperty('window', {
electronAPI: {
setIgnoreMouseEvents: (ignore: boolean, options?: { forward?: boolean }) => {
ignoreCalls.push({ ignore, forward: options?.forward });
},
},
getComputedStyle: () => ({
visibility: 'visible',
display: 'block',
opacity: '1',
}),
});
const restoreDocument = replaceGlobalProperty('document', {
querySelectorAll: (selector: string) =>
selector ===
'[data-subminer-yomitan-popup-host="true"][data-subminer-yomitan-popup-visible="true"]'
? [{ getAttribute: () => 'true' }]
: [],
});
try {
syncOverlayMouseIgnoreState({
dom: {
overlay: { classList },
},
platform: {
shouldToggleMouseIgnore: true,
},
state: {
isOverSubtitle: false,
isOverSubtitleSidebar: false,
yomitanPopupVisible: false,
controllerSelectModalOpen: false,
controllerDebugModalOpen: false,
jimakuModalOpen: false,
youtubePickerModalOpen: false,
kikuModalOpen: false,
runtimeOptionsModalOpen: false,
subsyncModalOpen: false,
sessionHelpModalOpen: false,
subtitleSidebarModalOpen: false,
subtitleSidebarConfig: null,
},
} as never);
assert.equal(classList.contains('interactive'), true);
assert.deepEqual(ignoreCalls, [{ ignore: false, forward: undefined }]);
} finally {
restoreDocument();
restoreWindow();
}
});
test('visible yomitan popup host on macOS keeps overlay interactive so click-away reaches popup', () => {
const classList = createClassList();
const ignoreCalls: Array<{ ignore: boolean; forward?: boolean }> = [];
const restoreWindow = replaceGlobalProperty('window', {
electronAPI: {
setIgnoreMouseEvents: (ignore: boolean, options?: { forward?: boolean }) => {
ignoreCalls.push({ ignore, forward: options?.forward });
},
},
getComputedStyle: () => ({
visibility: 'visible',
display: 'block',
opacity: '1',
}),
});
const restoreDocument = replaceGlobalProperty('document', {
querySelectorAll: (selector: string) =>
selector ===
'[data-subminer-yomitan-popup-host="true"][data-subminer-yomitan-popup-visible="true"]'
? [{ getAttribute: () => 'true' }]
: [],
});
try {
syncOverlayMouseIgnoreState({
dom: {
overlay: { classList },
},
platform: {
isMacOSPlatform: true,
shouldToggleMouseIgnore: true,
},
state: {
isOverSubtitle: false,
isOverSubtitleSidebar: false,
isOverYomitanPopup: false,
yomitanPopupVisible: false,
controllerSelectModalOpen: false,
controllerDebugModalOpen: false,
jimakuModalOpen: false,
youtubePickerModalOpen: false,
kikuModalOpen: false,
runtimeOptionsModalOpen: false,
subsyncModalOpen: false,
sessionHelpModalOpen: false,
subtitleSidebarModalOpen: false,
subtitleSidebarConfig: null,
},
} as never);
assert.equal(classList.contains('interactive'), true);
assert.deepEqual(ignoreCalls, [{ ignore: false, forward: undefined }]);
} finally {
restoreDocument();
restoreWindow();
}
});
test('macOS pointer over a visible yomitan popup keeps the overlay interactive', () => {
const classList = createClassList();
const ignoreCalls: Array<{ ignore: boolean; forward?: boolean }> = [];
const restoreWindow = replaceGlobalProperty('window', {
electronAPI: {
setIgnoreMouseEvents: (ignore: boolean, options?: { forward?: boolean }) => {
ignoreCalls.push({ ignore, forward: options?.forward });
},
},
});
try {
syncOverlayMouseIgnoreState({
dom: {
overlay: { classList },
},
platform: {
isMacOSPlatform: true,
shouldToggleMouseIgnore: true,
},
state: {
isOverSubtitle: false,
isOverSubtitleSidebar: false,
isOverYomitanPopup: true,
yomitanPopupVisible: true,
controllerSelectModalOpen: false,
controllerDebugModalOpen: false,
jimakuModalOpen: false,
youtubePickerModalOpen: false,
kikuModalOpen: false,
runtimeOptionsModalOpen: false,
subsyncModalOpen: false,
sessionHelpModalOpen: false,
subtitleSidebarModalOpen: false,
subtitleSidebarConfig: null,
},
} as never);
assert.equal(classList.contains('interactive'), true);
assert.deepEqual(ignoreCalls, [{ ignore: false, forward: undefined }]);
} finally {
restoreWindow();
}
});
test('Linux subtitle hover keeps root passive and does not report whole-window interactive hint', () => {
const classList = createClassList();
function run({ platform, state, popupHostVisible = false, sidebarSelecting = false }: RunOptions) {
const classes = new Set<string>();
const ignoreCalls: IgnoreCall[] = [];
const interactiveHints: boolean[] = [];
const restoreWindow = replaceGlobalProperty('window', {
electronAPI: {
setIgnoreMouseEvents: (ignore: boolean, options?: { forward?: boolean }) => {
ignoreCalls.push({ ignore, forward: options?.forward });
},
reportOverlayInteractive: (interactive: boolean) => {
interactiveHints.push(interactive);
},
},
});
try {
syncOverlayMouseIgnoreState({
dom: {
overlay: { classList },
},
platform: {
isLinuxPlatform: true,
shouldToggleMouseIgnore: false,
},
state: {
isOverSubtitle: true,
isOverSubtitleSidebar: false,
yomitanPopupVisible: false,
controllerSelectModalOpen: false,
controllerDebugModalOpen: false,
jimakuModalOpen: false,
youtubePickerModalOpen: false,
kikuModalOpen: false,
runtimeOptionsModalOpen: false,
subsyncModalOpen: false,
sessionHelpModalOpen: false,
subtitleSidebarModalOpen: false,
subtitleSidebarConfig: null,
},
} as never);
assert.equal(classList.contains('interactive'), false);
assert.deepEqual(interactiveHints, [false]);
} finally {
restoreWindow();
}
});
test('Linux modal state reports whole-window interactive hint', () => {
const classList = createClassList();
const interactiveHints: boolean[] = [];
const restoreWindow = replaceGlobalProperty('window', {
electronAPI: {
reportOverlayInteractive: (interactive: boolean) => {
interactiveHints.push(interactive);
},
},
const restoreDocument = replaceGlobalProperty('document', {
querySelectorAll: (selector: string) =>
popupHostVisible && selector === YOMITAN_POPUP_VISIBLE_HOST_SELECTOR ? [{}] : [],
});
try {
syncOverlayMouseIgnoreState({
dom: {
overlay: { classList },
},
platform: {
isLinuxPlatform: true,
shouldToggleMouseIgnore: false,
},
state: {
isOverSubtitle: false,
isOverSubtitleSidebar: false,
yomitanPopupVisible: false,
controllerSelectModalOpen: false,
controllerDebugModalOpen: false,
jimakuModalOpen: false,
youtubePickerModalOpen: false,
kikuModalOpen: false,
runtimeOptionsModalOpen: true,
subsyncModalOpen: false,
sessionHelpModalOpen: false,
subtitleSidebarModalOpen: false,
subtitleSidebarConfig: null,
overlay: {
classList: {
add: (token: string) => classes.add(token),
remove: (token: string) => classes.delete(token),
},
},
subtitleSidebarList: { dataset: sidebarSelecting ? { selecting: 'true' } : {} },
},
platform:
platform === 'linux'
? { isLinuxPlatform: true, shouldToggleMouseIgnore: false }
: { isLinuxPlatform: false, shouldToggleMouseIgnore: true },
state: makeState(state),
} as never);
assert.equal(classList.contains('interactive'), true);
assert.deepEqual(interactiveHints, [true]);
} finally {
restoreDocument();
restoreWindow();
}
});
return { interactive: classes.has('interactive'), ignoreCalls, interactiveHints };
}
const CLICK_THROUGH: IgnoreCall[] = [{ ignore: true, forward: true }];
const CAPTURE: IgnoreCall[] = [{ ignore: false, forward: undefined }];
const toggleCases: Array<{
name: string;
options: Omit<RunOptions, 'platform'>;
capture: boolean;
}> = [
{ name: 'idle overlay starts click-through', options: {}, capture: false },
{
name: 'youtube picker keeps overlay interactive even when subtitle hover is inactive',
options: { state: { youtubePickerModalOpen: true } },
capture: true,
},
{
name: 'visible yomitan popup host keeps overlay interactive even when cached popup state is false',
options: { popupHostVisible: true, state: { yomitanPopupVisible: false } },
capture: true,
},
{
name: 'pointer over the yomitan popup keeps overlay interactive',
options: { state: { isOverYomitanPopup: true } },
capture: true,
},
{
name: 'pointer over an overlay notification keeps overlay interactive',
options: { state: { isOverOverlayNotification: true } },
capture: true,
},
{
name: 'pointer over notification history keeps overlay interactive',
options: { state: { isOverNotificationHistory: true } },
capture: true,
},
{
name: 'subtitle sidebar drag selection keeps overlay interactive',
options: { sidebarSelecting: true },
capture: true,
},
];
for (const c of toggleCases) {
test(c.name, () => {
const result = run({ platform: 'toggle', ...c.options });
assert.equal(result.interactive, c.capture);
assert.deepEqual(result.ignoreCalls, c.capture ? CAPTURE : CLICK_THROUGH);
assert.deepEqual(result.interactiveHints, []);
});
}
// Linux never toggles ignore itself; it only reports a whole-window hint for popups/modals.
const linuxCases: Array<{ name: string; state: Partial<RendererState>; interactive: boolean }> = [
{
name: 'Linux subtitle hover keeps root passive and does not report whole-window interactive hint',
state: { isOverSubtitle: true },
interactive: false,
},
{
name: 'Linux modal state reports whole-window interactive hint',
state: { runtimeOptionsModalOpen: true },
interactive: true,
},
{
name: 'Linux visible yomitan popup reports whole-window interactive hint',
state: { yomitanPopupVisible: true },
interactive: true,
},
];
for (const c of linuxCases) {
test(c.name, () => {
const result = run({ platform: 'linux', state: c.state });
assert.equal(result.interactive, c.interactive);
assert.deepEqual(result.interactiveHints, [c.interactive]);
assert.deepEqual(result.ignoreCalls, []);
});
}