Skip to content

Commit 0428b9e

Browse files
committed
test(console): the boot manifest pin waits for the manifest step main now runs after first paint
Claude-Session: https://claude.ai/code/session_01QsR2jSpg4SQPs6XFLsrBhv Co-authored-by: Claude <noreply@anthropic.com>
1 parent bc792ba commit 0428b9e

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

‎ui/apps/console/src/__tests__/main.nativeBridgeVersion-29330.test.tsx‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ import type { ReactNode } from 'react';
2626
import type { Root } from 'react-dom/client';
2727
import { NATIVE_HOST_GLOBAL } from '../../../../packages/mobile/src/nativeHost';
2828

29-
const { passthrough, roots } = vi.hoisted(() => ({
29+
const { passthrough, roots, resolveManifestIcons } = vi.hoisted(() => ({
3030
passthrough: ({ children }: { children?: ReactNode }) => <>{children}</>,
3131
roots: [] as Root[],
32+
/** The manifest's icon step; the manifest link lands once it settles. */
33+
resolveManifestIcons: vi.fn(async () => []),
3234
}));
3335

3436
vi.mock('react-dom/client', async (importOriginal) => {
@@ -68,6 +70,10 @@ vi.mock('@object-ui/app-shell', async (importOriginal) => ({
6870
vi.mock('../loadLanguage', () => ({ loadLanguage: async () => ({}) }));
6971
vi.mock('../loadLocales', () => ({ loadLocales: async () => [] }));
7072
vi.mock('../languageSeed', () => ({ seedTenantLanguage: async () => undefined }));
73+
vi.mock('../pwaManifestIcons', async (importOriginal) => ({
74+
...(await importOriginal<Record<string, unknown>>()),
75+
resolveManifestIcons,
76+
}));
7177
vi.mock('../lib/auth-preflight', () => ({ preflightAuth: async () => undefined }));
7278
vi.mock('../register-plugins', () => ({}));
7379
vi.mock('../registerDeveloperComponents', () => ({}));
@@ -93,19 +99,23 @@ function installBridge(version: number): void {
9399
}
94100

95101
/** Run `main.tsx` once, as a page load does, and wait for it to render. */
96-
async function boot(): Promise<string[]> {
102+
async function boot(): Promise<void> {
97103
vi.resetModules();
98104
await import('../main');
99105
await waitFor(() => expect(screen.getByTestId('app')).toBeInTheDocument());
100-
return Array.from(document.querySelectorAll<HTMLLinkElement>('link[rel="manifest"]')).map((link) =>
101-
link.getAttribute('href') ?? '',
106+
}
107+
108+
function manifestHrefs(): string[] {
109+
return Array.from(document.querySelectorAll<HTMLLinkElement>('link[rel="manifest"]')).map(
110+
(link) => link.getAttribute('href') ?? '',
102111
);
103112
}
104113

105114
beforeEach(() => {
106115
document.head.innerHTML = '<link rel="manifest" href="./manifest.json" />';
107116
document.body.innerHTML = '<div id="root"></div>';
108117
vi.spyOn(URL, 'createObjectURL').mockReturnValue(BLOB_MANIFEST);
118+
resolveManifestIcons.mockClear();
109119
});
110120

111121
afterEach(() => {
@@ -121,15 +131,22 @@ afterEach(() => {
121131
describe('the boot manifest and the bridge protocol version', () => {
122132
it('a version 2 bridge is no shell: the generated manifest replaces the static one', async () => {
123133
installBridge(2);
124-
expect(await boot()).toEqual([BLOB_MANIFEST]);
134+
await boot();
135+
expect(resolveManifestIcons).toHaveBeenCalledTimes(1);
136+
await waitFor(() => expect(manifestHrefs()).toEqual([BLOB_MANIFEST]));
125137
});
126138

127139
it('control: a version 1 bridge is the shell, and the manifest is dropped', async () => {
128140
installBridge(1);
129-
expect(await boot()).toEqual([]);
141+
await boot();
142+
// The manifest step never started, so no link can land later either.
143+
expect(resolveManifestIcons).not.toHaveBeenCalled();
144+
expect(manifestHrefs()).toEqual([]);
130145
});
131146

132147
it('control: without a bridge the generated manifest replaces the static one', async () => {
133-
expect(await boot()).toEqual([BLOB_MANIFEST]);
148+
await boot();
149+
expect(resolveManifestIcons).toHaveBeenCalledTimes(1);
150+
await waitFor(() => expect(manifestHrefs()).toEqual([BLOB_MANIFEST]));
134151
});
135152
});

0 commit comments

Comments
 (0)