Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

test(web): 对齐共享模块与常驻面应用适配层

longmeidao83ca3ec42f36
diff --git a/frontend/test/history/history.test.ts b/frontend/test/history/history.test.ts
index 623c5f255..fcbb20450 100644
--- a/frontend/test/history/history.test.ts
+++ b/frontend/test/history/history.test.ts
@@ -2,7 +2,7 @@
* 都从同一个对象分发。 */
import { afterEach, beforeEach, expect, it } from 'vitest';
-import * as islands from '../../src/islands';
+import * as sharedHistory from '@peach/history';
import { peachHistory, routeMetaOf, shellNavigate, type Navigation } from '../../src/history';
let seen: Navigation[] = [];
@@ -20,9 +20,9 @@ function pop(path: string) {
window.dispatchEvent(new PopStateEvent('popstate', { state: window.history.state }));
}
-it('壳从 peach-ui.js 取到的就是这一份', () => {
- expect(islands.peachHistory).toBe(peachHistory);
- expect(islands.shellNavigate).toBe(shellNavigate);
+it('共享 history 入口与真实浏览器历史模块使用同一份绑定', () => {
+ expect(sharedHistory.peachHistory).toBe(peachHistory);
+ expect(sharedHistory.shellNavigate).toBe(shellNavigate);
});
it('push 加一条历史,replace 不加', () => {
diff --git a/frontend/test/history/overlay.test.ts b/frontend/test/history/overlay.test.ts
index 58b1530f7..56be1924a 100644
--- a/frontend/test/history/overlay.test.ts
+++ b/frontend/test/history/overlay.test.ts
@@ -5,7 +5,7 @@
* 启动那一次不调 `adoptOverlayState`,覆盖元素什么时候接背景见 `test/react/pages/overlay.test.tsx`。 */
import { beforeEach, expect, it } from 'vitest';
-import * as islands from '../../src/islands';
+import * as overlay from '../../src/history/overlay';
import {
adoptOverlayState, clearOverlayBackground, holdOverlayBackground, isOverlayPath, overlayState, peachHistory,
retagOverlay, shellNavigate, takeOverlayReturn,
@@ -39,12 +39,12 @@ function revisit() {
adoptOverlayState(usr());
}
-it('壳从 peach-ui.js 取到的就是这一份', () => {
- expect(islands.holdOverlayBackground).toBe(holdOverlayBackground);
- expect(islands.overlayState).toBe(overlayState);
- expect(islands.retagOverlay).toBe(retagOverlay);
- expect(islands.adoptOverlayState).toBe(adoptOverlayState);
- expect(islands.takeOverlayReturn).toBe(takeOverlayReturn);
+it('共享 history 入口与覆盖背景模块使用同一份绑定', () => {
+ expect(overlay.holdOverlayBackground).toBe(holdOverlayBackground);
+ expect(overlay.overlayState).toBe(overlayState);
+ expect(overlay.retagOverlay).toBe(retagOverlay);
+ expect(overlay.adoptOverlayState).toBe(adoptOverlayState);
+ expect(overlay.takeOverlayReturn).toBe(takeOverlayReturn);
});
it('覆盖层地址是作品详情、四种队列与关注详情,页面与沉浸不算', () => {
diff --git a/frontend/test/query/client.test.tsx b/frontend/test/query/client.test.tsx
index 206057e71..57aeaabd5 100644
--- a/frontend/test/query/client.test.tsx
+++ b/frontend/test/query/client.test.tsx
@@ -6,7 +6,7 @@ import { afterEach, expect, it } from 'vitest';
import { queryClient } from '@peach/query';
-import * as islands from '../../src/islands';
+import { queryClient as sharedQueryClient } from '../../src/query/client';
import { Providers } from '../../src/react/providers';
import { queryClient as reactQueryClient } from '../../src/react/query';
@@ -23,7 +23,7 @@ it('React 岛里 useQueryClient() 拿到的就是壳那一个', async () => {
await act(async () => { root.render(<Providers><Probe /></Providers>) });
expect(seen).toBe(queryClient);
expect(reactQueryClient).toBe(queryClient);
- expect(islands.queryClient).toBe(queryClient);
+ expect(sharedQueryClient).toBe(queryClient);
await act(async () => { root.unmount() });
});
diff --git a/frontend/test/react/batch-dock.test.tsx b/frontend/test/react/batch-dock.test.tsx
index 7723d8ac9..1624895fd 100644
--- a/frontend/test/react/batch-dock.test.tsx
+++ b/frontend/test/react/batch-dock.test.tsx
@@ -31,10 +31,9 @@ vi.mock(import('../../src/react/components/selection-dock'), async (importOrigin
};
});
-/* 壳那一侧的 `islands.ts` 按 `@peach/react` 引产物;React 子树的类型配置不映射这个名字(页面不该反过来引
- 自己所在的产物),所以这里不让类型检查跟进去,只按壳用的那两个入口取。运行时 Vitest 把它指到 `entry.tsx`。 */
+/* 常驻面适配层直接读取同一包内的配置函数;测试只接本场景的句柄契约。 */
type ShellIslands = { loadBatchDock(host: BatchDockHost): Promise<BatchDockApi>; batchDockApi(): BatchDockApi | null };
-const ISLANDS_MODULE = '../../src/islands';
+const ISLANDS_MODULE = '../../src/react/application-residents';
async function load() {
vi.resetModules();
@@ -189,7 +188,7 @@ describe('常驻面', () => {
const r = await load();
await mountRouter(r);
const host = dockHost();
- expect(r.islands.batchDockApi(), '包回来之前没有句柄,壳只记着手上那份').toBeNull();
+ expect(r.islands.batchDockApi(), '常驻面尚未挂载时没有句柄,应用只记着当前那份').toBeNull();
let api: BatchDockApi | null = null;
await act(async () => { api = await r.islands.loadBatchDock(host) });
expect(r.islands.batchDockApi()).toBe(api);
diff --git a/frontend/test/react/entity-controller.test.ts b/frontend/test/react/entity-controller.test.ts
index 65ca0b624..25ab2f4c7 100644
--- a/frontend/test/react/entity-controller.test.ts
+++ b/frontend/test/react/entity-controller.test.ts
@@ -163,4 +163,30 @@ describe('实体与索引域控制', () => {
expect(ports.pushEntity).toHaveBeenCalledWith({ photoSize: 'big', photoLayout: 'masonry', followImagesOnly: true });
expect(ports.pushFollow).toHaveBeenCalledWith({ photoSize: 'big', photoLayout: 'masonry', imagesOnly: true });
});
+
+ it('厂牌大位和圆框分别取 large 与 ring,标识可回落实体图但不能回落代表作', () => {
+ const company = { k: 'Peach & Co', n: 3, entity_id: 41, has_logo: true, logo_version: 'logo 2',
+ has_image: true, image_version: 'face 2', has_avatar: true, rep: 91,
+ avatar_focus: { axis: 'y', pct: 20 }, avatar_stand_in: true };
+ for (const big of [true, false]) {
+ const host = document.createElement('div');
+ host.innerHTML = personAvatar(company, 'studio', big).html;
+ const image = host.querySelector('img')!, url = new URL(image.src);
+ expect(url.pathname).toBe('/logo');
+ expect(url.searchParams.get('studio')).toBe(company.k);
+ expect(url.searchParams.get('variant')).toBe(big ? 'large' : 'ring');
+ expect(url.searchParams.get('v')).toBe('logo 2');
+ expect(image.getAttribute('data-fallbacks')).toContain('/entity-image?kind=studio');
+ expect(image.getAttribute('data-fallbacks')).not.toContain('/avatar');
+ expect(image.getAttribute('data-fallback-note')).toBeNull();
+ expect(image.style.objectPosition).toBe('');
+ }
+ const host = document.createElement('div');
+ host.innerHTML = entityPortraitImg('studio', { id: 41, canonical_name: company.k, asset_count: 3,
+ has_logo: true, logo_version: 'logo 2', has_image: true, image_version: 'face 2',
+ has_avatar: true, representative_asset_id: 91, avatar_stand_in: true });
+ const portrait = host.querySelector('img')!;
+ expect(new URL(portrait.src).searchParams.get('variant')).toBe('large');
+ expect(portrait.getAttribute('data-fallbacks')).not.toContain('/avatar');
+ });
});
diff --git a/frontend/test/react/immerse.test.tsx b/frontend/test/react/immerse.test.tsx
index cd634d04f..dbdaecfae 100644
--- a/frontend/test/react/immerse.test.tsx
+++ b/frontend/test/react/immerse.test.tsx
@@ -3,7 +3,7 @@
* (`RESIDENT_ROUTES.immerse`)在路由树里的行为:宿主是 body 末尾的 `[data-immerse-host]`、画上之后才交出
* 句柄、`open` 里的几次绘制同步画完、抛错只卸组件而模块上的监听还在。
*
- * 每条用例照壳的启动顺序走一遍:重新装载模块、画路由树、接上取数,再经 `islands.ts` 的 `loadImmerse` 拿句柄。
+ * 每条用例照应用启动顺序走一遍:重新装载模块、画路由树、接上取数,再经 `application-residents` 的 `loadImmerse` 拿句柄。
* 播放器换成一个记账的替身:这里看的是这一面交给它什么、什么时候拆它,真 Video.js 与真流会话由
* e2e 在浏览器里走一遍(`e2e/immerse.test.ts`)。 */
import { act } from 'react';
@@ -143,14 +143,13 @@ function makeHost(): HostMock {
};
}
-/* 壳那一侧的 `islands.ts` 按 `@peach/react` 引产物;React 子树的类型配置不映射这个名字,所以这里不让类型检查
- 跟进去,只按壳用的几个入口取。运行时 Vitest 把它指到 `entry.tsx`。 */
+/* 常驻面适配层直接读取同一包内的配置函数;测试只接本场景的句柄契约。 */
type ShellIslands = {
loadImmerse(host: ImmerseHost): Promise<ImmerseApi>;
immerseApi(): ImmerseApi | null;
loadBatchDock(host: BatchDockHost): Promise<BatchDockApi>;
};
-const ISLANDS_MODULE = '../../src/islands';
+const ISLANDS_MODULE = '../../src/react/application-residents';
async function load() {
vi.resetModules();
diff --git a/frontend/test/react/manage-header.test.tsx b/frontend/test/react/manage-header.test.tsx
index 7e83f9d7e..afb1d75cc 100644
--- a/frontend/test/react/manage-header.test.tsx
+++ b/frontend/test/react/manage-header.test.tsx
@@ -33,14 +33,13 @@ vi.mock(import('../../src/react/settings-panel/icon'), async (importOriginal) =>
};
});
-/* 壳那一侧的 `islands.ts` 按 `@peach/react` 引产物;React 子树的类型配置不映射这个名字,所以这里不让类型检查
- 跟进去,只按壳用的几个入口取。运行时 Vitest 把它指到 `entry.tsx`。 */
+/* 常驻面适配层直接读取同一包内的配置函数;测试只接本场景的句柄契约。 */
type ShellIslands = {
loadManageHeader(host: ManageHeaderHost): Promise<ManageHeaderApi>;
manageHeaderApi(): ManageHeaderApi | null;
loadBatchDock(host: BatchDockHost): Promise<BatchDockApi>;
};
-const ISLANDS_MODULE = '../../src/islands';
+const ISLANDS_MODULE = '../../src/react/application-residents';
async function load() {
vi.resetModules();
@@ -127,7 +126,7 @@ function watchReports() {
const title = (root: ParentNode) => root.querySelector('[data-manage-title]')?.textContent;
describe('换手', () => {
- it('包回来之前宿主里是骨架、句柄为 null;画上之后句柄才交出,画出来的是同一份结构', async () => {
+ it('预取未接上时宿主里是骨架、句柄为 null;画上之后句柄才交出,画出来的是同一份结构', async () => {
const first = props('cleanup', '/junk-files');
const skeleton = document.createElement('div');
skeleton.innerHTML = manageHeaderSkeletonHtml(first);
diff --git a/frontend/test/react/settings-panel.test.tsx b/frontend/test/react/settings-panel.test.tsx
index 1509d0f45..bc0813411 100644
--- a/frontend/test/react/settings-panel.test.tsx
+++ b/frontend/test/react/settings-panel.test.tsx
@@ -41,14 +41,13 @@ vi.mock(import('../../src/react/settings-panel/icon'), async (importOriginal) =>
};
});
-/* 壳那一侧的 `islands.ts` 按 `@peach/react` 引产物;React 子树的类型配置不映射这个名字,所以这里不让类型检查
- 跟进去,只按壳用的几个入口取。运行时 Vitest 把它指到 `entry.tsx`。 */
+/* 常驻面适配层直接读取同一包内的配置函数;测试只接本场景的句柄契约。 */
type ShellIslands = {
loadSettingsPanel(host: SettingsPanelHost): Promise<SettingsPanelApi>;
settingsPanelApi(): SettingsPanelApi | null;
loadBatchDock(host: BatchDockHost): Promise<BatchDockApi>;
};
-const ISLANDS_MODULE = '../../src/islands';
+const ISLANDS_MODULE = '../../src/react/application-residents';
async function load() {
vi.resetModules();
diff --git a/frontend/test/react/sidebar.test.tsx b/frontend/test/react/sidebar.test.tsx
index 942337f61..ea1799cbb 100644
--- a/frontend/test/react/sidebar.test.tsx
+++ b/frontend/test/react/sidebar.test.tsx
@@ -36,14 +36,13 @@ vi.mock(import('../../src/react/settings-panel/icon'), async (importOriginal) =>
};
});
-/* 壳那一侧的 `islands.ts` 按 `@peach/react` 引产物;React 子树的类型配置不映射这个名字,所以这里不让类型检查
- 跟进去,只按壳用的几个入口取。运行时 Vitest 把它指到 `entry.tsx`。 */
+/* 常驻面适配层直接读取同一包内的配置函数;测试只接本场景的句柄契约。 */
type ShellIslands = {
loadSidebar(host: SidebarHost): Promise<SidebarApi>;
sidebarApi(): SidebarApi | null;
loadBatchDock(host: BatchDockHost): Promise<BatchDockApi>;
};
-const ISLANDS_MODULE = '../../src/islands';
+const ISLANDS_MODULE = '../../src/react/application-residents';
async function load() {
vi.resetModules();
@@ -154,7 +153,7 @@ beforeEach(() => {
});
describe('换手', () => {
- it('骨架与侧栏画的是同一列:顺序、按下态与首页记号一致;包回来之前滚动层里是骨架、句柄为 null', async () => {
+ it('骨架与侧栏画的是同一列:顺序、按下态与首页记号一致;预取未接上时滚动层里是骨架、句柄为 null', async () => {
const skeleton = document.createElement('div');
skeleton.innerHTML = sidebarSkeletonHtml(['unseen', '', 'missing'], CATALOG, (key) => key === 'unseen');
expect(navKeys(skeleton)).toEqual(['unseen', '']);
diff --git a/frontend/test/react/stage.test.tsx b/frontend/test/react/stage.test.tsx
index a2688f5c7..1dc9b0d6e 100644
--- a/frontend/test/react/stage.test.tsx
+++ b/frontend/test/react/stage.test.tsx
@@ -2,7 +2,7 @@
* 画上之后才交出句柄、小窗节点在句柄交出时已经画好、`open` 里的几次绘制同步画完、换详情不换宿主、抛错只卸
* 组件而句柄照调不抛。
*
- * 每条用例照壳的启动顺序走一遍:重新装载模块、画路由树、接上取数,再经 `islands.ts` 的 `loadStage` 拿句柄。
+ * 每条用例照应用启动顺序走一遍:重新装载模块、画路由树、接上取数,再经 `application-residents` 的 `loadStage` 拿句柄。
* 播放器换成一个记账的替身:这里看的是舞台这一面怎么画、什么时候交出句柄,真 Video.js、进出场与小窗的交接
* 由 e2e 在浏览器里走一遍(`e2e/stage.test.ts`),播放器在两个位置之间的交接在 `stage-player.test.ts`。 */
import { act } from 'react';
@@ -98,14 +98,13 @@ function request(id: number, patch: Partial<StageItemRequest> = {}): StageItemRe
};
}
-/* 壳那一侧的 `islands.ts` 按 `@peach/react` 引产物;React 子树的类型配置不映射这个名字,所以这里不让类型检查
- 跟进去,只按壳用的几个入口取。运行时 Vitest 把它指到 `entry.tsx`。 */
+/* 常驻面适配层直接读取同一包内的配置函数;测试只接本场景的句柄契约。 */
type ShellIslands = {
loadStage(host: StageHost): Promise<StageApi>;
stageApi(): StageApi | null;
loadBatchDock(host: BatchDockHost): Promise<BatchDockApi>;
};
-const ISLANDS_MODULE = '../../src/islands';
+const ISLANDS_MODULE = '../../src/react/application-residents';
async function load() {
vi.resetModules();
diff --git a/frontend/test/shell/store.test.ts b/frontend/test/shell/store.test.ts
index 434d0fdaa..9eb6291f6 100644
--- a/frontend/test/shell/store.test.ts
+++ b/frontend/test/shell/store.test.ts
@@ -101,10 +101,10 @@ it('退订之后不再收到通知;版本号单调递增', () => {
expect(shell.shellVersion()).toBe(3);
});
-it('peach-ui.js 的入口交出的是同一份绑定:从入口写,单例这边当场读到', async () => {
- const islands = await import('../../src/islands');
- islands.writeShell({ configurationRequestedSection: '网络与访问' });
+it('共享 shell 入口交出同一份活绑定:从入口写,状态模块当场读到', async () => {
+ const sharedShell = await import('@peach/shell');
+ sharedShell.writeShell({ configurationRequestedSection: '网络与访问' });
expect(shell.configurationRequestedSection).toBe('网络与访问');
- expect(islands.selected).toBe(shell.selected);
- expect(islands.configurationRequestedSection).toBe('网络与访问');
+ expect(sharedShell.selected).toBe(shell.selected);
+ expect(sharedShell.configurationRequestedSection).toBe('网络与访问');
});