收口H5原生状态结果归一化门禁
H5 HostBridge 测试覆盖原生配色异常值归一化 原生壳门禁反查配色和网络状态结果归一化
This commit is contained in:
@@ -1164,6 +1164,27 @@ function assertH5HostBridgePayloadBoundaries() {
|
||||
'H5 HostBridge facade must normalize haptics.impact payloads with the shared style boundary',
|
||||
);
|
||||
}
|
||||
if (
|
||||
!h5HostBridgeSource.includes(
|
||||
'colorScheme: normalizeHostBridgeColorScheme(result?.colorScheme),',
|
||||
)
|
||||
) {
|
||||
throw new Error(
|
||||
'H5 HostBridge facade must normalize appearance.getColorScheme results with the shared color scheme boundary',
|
||||
);
|
||||
}
|
||||
if (
|
||||
!h5HostBridgeSource.includes(
|
||||
'const connectionType = normalizeHostBridgeConnectionType(\n payload?.connectionType ?? payload?.nativeType,\n );',
|
||||
) ||
|
||||
!h5HostBridgeSource.includes(
|
||||
'listener(normalizeHostNetworkStatus(payload));',
|
||||
)
|
||||
) {
|
||||
throw new Error(
|
||||
'H5 HostBridge facade must normalize network.status results and network.statusChanged events with shared network boundaries',
|
||||
);
|
||||
}
|
||||
if (
|
||||
!h5HostBridgeSource.includes(
|
||||
'const normalizedTitle = normalizeHostBridgeAppTitle(title);',
|
||||
|
||||
@@ -598,6 +598,43 @@ describe('hostBridge', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('原生 App 宿主配色结果进入 H5 前先归一化', async () => {
|
||||
const invoke = vi.fn(
|
||||
async (_command: string, args?: Record<string, unknown>) => {
|
||||
const request = (args as { request: { id: string; method: string } })
|
||||
.request;
|
||||
return {
|
||||
bridge: 'GenarrativeHostBridge',
|
||||
version: 1,
|
||||
id: request.id,
|
||||
ok: true,
|
||||
result: {
|
||||
colorScheme: 'sepia',
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
window.history.replaceState(
|
||||
null,
|
||||
'',
|
||||
nativeAppPath(['appearance.getColorScheme']),
|
||||
);
|
||||
window.__TAURI__ = {
|
||||
core: {
|
||||
invoke: asTauriInvoke(invoke),
|
||||
},
|
||||
};
|
||||
|
||||
await expect(getHostAppearanceColorScheme()).resolves.toEqual({
|
||||
colorScheme: 'unknown',
|
||||
});
|
||||
expect(invoke).toHaveBeenCalledWith('host_bridge_request', {
|
||||
request: expect.objectContaining({
|
||||
method: 'appearance.getColorScheme',
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
test('从真实宿主 runtime 回读能力并通知订阅者', async () => {
|
||||
const listener = vi.fn();
|
||||
const unsubscribe = subscribeHostRuntimeChange(listener);
|
||||
|
||||
Reference in New Issue
Block a user