mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-04-12 04:19:25 -07:00
Address second CodeRabbit review round
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { YOMITAN_LOOKUP_EVENT, registerYomitanLookupListener } from './yomitan-popup.js';
|
||||
import {
|
||||
YOMITAN_LOOKUP_EVENT,
|
||||
YOMITAN_POPUP_VISIBLE_HOST_SELECTOR,
|
||||
isYomitanPopupVisible,
|
||||
registerYomitanLookupListener,
|
||||
} from './yomitan-popup.js';
|
||||
|
||||
test('registerYomitanLookupListener forwards the SubMiner Yomitan lookup event', () => {
|
||||
const target = new EventTarget();
|
||||
@@ -16,3 +21,12 @@ test('registerYomitanLookupListener forwards the SubMiner Yomitan lookup event',
|
||||
|
||||
assert.deepEqual(calls, ['lookup']);
|
||||
});
|
||||
|
||||
test('isYomitanPopupVisible falls back to querySelector when querySelectorAll is unavailable', () => {
|
||||
const root = {
|
||||
querySelector: (selector: string) =>
|
||||
selector === YOMITAN_POPUP_VISIBLE_HOST_SELECTOR ? ({} as Element) : null,
|
||||
} as ParentNode;
|
||||
|
||||
assert.equal(isYomitanPopupVisible(root), true);
|
||||
});
|
||||
|
||||
@@ -62,10 +62,14 @@ function queryPopupElements<T extends Element>(
|
||||
root: ParentNode | null | undefined,
|
||||
selector: string,
|
||||
): T[] {
|
||||
if (typeof root?.querySelectorAll !== 'function') {
|
||||
return [];
|
||||
if (typeof root?.querySelectorAll === 'function') {
|
||||
return Array.from(root.querySelectorAll<T>(selector));
|
||||
}
|
||||
return Array.from(root.querySelectorAll<T>(selector));
|
||||
if (typeof root?.querySelector === 'function') {
|
||||
const first = root.querySelector(selector) as T | null;
|
||||
return first ? [first] : [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
export function isYomitanPopupVisible(root: ParentNode | null | undefined = document): boolean {
|
||||
|
||||
Reference in New Issue
Block a user