Skip to content

Commit 9f4f6f3

Browse files
committed
test(app-shell): pin launcher narrowing by /me/apps on the hook, Home and the switcher
Claude-Session: https://claude.ai/code/session_01JQwxbYwBbR8jCpWPE5Kosz Co-authored-by: Claude <noreply@anthropic.com>
1 parent c31701a commit 9f4f6f3

3 files changed

Lines changed: 544 additions & 0 deletions

File tree

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#26838 — Home's tiles are the apps the user's `GET /me/apps`
5+
* answer lists, so an app a permission set hides (`tabPermissions: hidden`)
6+
* draws no tile, while `GET /meta/app` still serves it (it opens from a URL).
7+
*
8+
* On the real `HomePage` and `HomeAppsStrip`, under the real
9+
* `LauncherAppsProvider` fed a `/me/apps` double:
10+
*
11+
* - `/meta/app` = [setup, crm, showcase_app], `/me/apps` = [setup, crm]:
12+
* no Showcase tile; Setup's System Settings link stays;
13+
* - a set that hides Setup takes the System Settings link away too;
14+
* - `404` (no security plugin): every tile, as before;
15+
* - while the first read is out the page holds its loading line and draws
16+
* no tile, so a hidden tile is never drawn and then taken away.
17+
*
18+
* The harness is `HomePage.greetingAndApps-12601.test.tsx`'s.
19+
*/
20+
21+
import '@testing-library/jest-dom/vitest';
22+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
23+
import React from 'react';
24+
import { render, screen, cleanup, act } from '@testing-library/react';
25+
26+
const navigateMock = vi.fn();
27+
28+
const state = vi.hoisted(() => ({
29+
isAdmin: true,
30+
canAuthorMetadata: true,
31+
marketplaceEnabled: true,
32+
pendingApprovalsCount: 0,
33+
approvalsStatus: 'ready' as 'idle' | 'loading' | 'ready' | 'error',
34+
apps: [] as Array<Record<string, unknown>>,
35+
recentItems: [] as Array<Record<string, unknown>>,
36+
}));
37+
38+
vi.mock('react-router-dom', async () => {
39+
const { createElement } = await import('react');
40+
return {
41+
useNavigate: () => navigateMock,
42+
// The tiles and the settings link are router `Link`s; this harness has no
43+
// router, so the stand-in renders the anchor `Link` would, minus the basename.
44+
Link: ({ to, ...rest }: { to: string } & Record<string, unknown>) =>
45+
createElement('a', { ...rest, href: to }),
46+
};
47+
});
48+
49+
vi.mock('@object-ui/i18n', async (importOriginal) => ({
50+
...(await importOriginal<Record<string, unknown>>()),
51+
useObjectTranslation: () => ({
52+
t: (key: string, opts?: { count?: number; time?: string }) =>
53+
`«${key}»` +
54+
(opts?.count === undefined ? '' : `[count=${opts.count}]`) +
55+
(opts?.time === undefined ? '' : `[time=${opts.time}]`),
56+
language: 'en',
57+
}),
58+
// Every labeller echoes the label, else the name: the tiles read `appLabel`,
59+
// and the recent rail beside them labels the store's entries.
60+
useObjectLabel: () => {
61+
const label = (x: { name?: string; label?: string }) => String(x?.label || x?.name || '');
62+
return {
63+
appLabel: label,
64+
objectLabel: label,
65+
objectPluralLabel: label,
66+
dashboardLabel: label,
67+
pageLabel: label,
68+
reportLabel: label,
69+
viewLabel: (_object: string, _view: string, fallback?: string) => fallback ?? '',
70+
};
71+
},
72+
}));
73+
74+
vi.mock('@object-ui/auth', async (importOriginal) => ({
75+
...(await importOriginal<Record<string, unknown>>()),
76+
useAuth: () => ({ user: { id: 'u1', name: 'Dev Admin', email: 'dev.admin@example.com' } }),
77+
useWorkspaceAdminStatus: () => ({ isAdmin: state.isAdmin, isResolved: true }),
78+
}));
79+
80+
// One custom agent and no ask or build agent: AI is on here, so the build chip
81+
// keeps its "Build an app" form (objectstack#26614 gives the agent-less
82+
// deployment its own, `HomePage.noAgentsBuildChip-26614.test.tsx`), and no AI
83+
// CTA joins the greeting row, which holds the builder chips alone.
84+
vi.mock('@object-ui/plugin-chatbot/core', async (importOriginal) => ({
85+
...(await importOriginal<typeof import('@object-ui/plugin-chatbot/core')>()),
86+
useAgents: () => ({ agents: [{ name: 'custom_helper' }] }),
87+
isAskAgent: () => false,
88+
agentHasCapability: () => false,
89+
}));
90+
91+
vi.mock('../../../providers/MetadataProvider', () => ({
92+
useMetadata: () => ({ apps: state.apps, objects: [], dashboards: [], pages: [], reports: [], loading: false }),
93+
}));
94+
vi.mock('../../../context/NavigationContext', () => ({
95+
useNavigationContext: () => ({ currentAppName: undefined }),
96+
}));
97+
vi.mock('../../../hooks/useCanAuthorMetadata', () => ({
98+
useCanAuthorMetadata: () => state.canAuthorMetadata,
99+
useCanReadPendingDrafts: () => true,
100+
}));
101+
// The page's one inbox seam: the approvals count AND whether it is an answer.
102+
vi.mock('../../../hooks/useHomeInbox', () => ({
103+
useHomeInbox: () => ({
104+
pendingApprovalsCount: state.pendingApprovalsCount,
105+
// objectui#12602: the approvals preview, and whether each source is
106+
// the caller's to read — the My-work section draws a column per source.
107+
pendingApprovals: [],
108+
pendingApprovalsReadable: true,
109+
notificationsReadable: true,
110+
pendingApprovalsStatus: state.approvalsStatus,
111+
notifications: [],
112+
unreadTopicCount: 0,
113+
notificationsStatus: 'ready',
114+
activity: { value: [], status: 'ready', readable: true },
115+
}),
116+
}));
117+
vi.mock('../../../runtime-config', () => ({
118+
getRuntimeConfig: () => ({ branding: { productName: 'ObjectStack' } }),
119+
isMarketplaceEnabled: () => state.marketplaceEnabled,
120+
isAiStudioEnabled: () => true,
121+
}));
122+
123+
// The tiles' last-opened time reads the recent-items store.
124+
vi.mock('../../../hooks/useRecentItems', () => ({
125+
useRecentItems: () => ({ recentItems: state.recentItems }),
126+
}));
127+
128+
// --- surfaces these cases do not read ---------------------------------------
129+
vi.mock('../../../hooks/useFavorites', () => ({ useFavorites: () => ({ favorites: [] }) }));
130+
vi.mock('../../../hooks/useAiSurface', () => ({ resolveAiApiBase: () => '' }));
131+
vi.mock('../../../preview/usePendingDrafts', () => ({ usePendingDrafts: () => ({ count: 0 }) }));
132+
vi.mock('../../../preview/usePublishAllDrafts', () => ({
133+
usePublishAllDrafts: () => ({ publishAll: async () => ({ ok: true }), publishing: false }),
134+
}));
135+
136+
import { HomePage } from '../HomePage';
137+
import { LauncherAppsProvider } from '../../../hooks/useLauncherApps';
138+
139+
const SETUP = { name: 'setup', label: 'Setup', icon: 'Settings', _packageId: 'com.objectstack.setup' };
140+
const CRM = { name: 'crm', label: 'CRM', icon: 'Building2' };
141+
const SHOWCASE = { name: 'showcase_app', label: 'Showcase', icon: 'Sparkles' };
142+
143+
const ENDPOINT = '/me-apps-double';
144+
145+
/** A `/me/apps` double: the listed names, or a bare status. */
146+
function meApps(answer: string[] | number) {
147+
return vi.fn(async (_url: unknown) =>
148+
typeof answer === 'number'
149+
? new Response('{}', { status: answer })
150+
: new Response(JSON.stringify({ apps: answer.map((name) => ({ name })) }), { status: 200 }),
151+
);
152+
}
153+
154+
function renderHome(fetcher: unknown) {
155+
return render(
156+
<LauncherAppsProvider endpoint={ENDPOINT} fetcher={fetcher as typeof fetch}>
157+
<HomePage />
158+
</LauncherAppsProvider>,
159+
);
160+
}
161+
162+
/** Every URL the page handed the global `fetch` — none is expected. */
163+
let fetchCalls: string[] = [];
164+
165+
beforeEach(() => {
166+
navigateMock.mockReset();
167+
state.isAdmin = true;
168+
state.canAuthorMetadata = true;
169+
state.marketplaceEnabled = true;
170+
state.pendingApprovalsCount = 0;
171+
state.approvalsStatus = 'ready';
172+
state.apps = [SETUP, CRM, SHOWCASE];
173+
state.recentItems = [];
174+
fetchCalls = [];
175+
vi.stubGlobal(
176+
'fetch',
177+
vi.fn(async (input: unknown) => {
178+
fetchCalls.push(String(input));
179+
return { ok: false, status: 404, json: async () => ({}) };
180+
}),
181+
);
182+
});
183+
184+
afterEach(() => {
185+
expect(fetchCalls).toEqual([]);
186+
cleanup();
187+
vi.unstubAllGlobals();
188+
});
189+
190+
describe('Home draws a tile only for an app /me/apps lists (objectstack#26838)', () => {
191+
it('an app the member’s set hides draws no tile', async () => {
192+
const fetcher = meApps(['setup', 'crm']);
193+
renderHome(fetcher);
194+
expect(await screen.findByTestId('app-tile-crm')).toBeInTheDocument();
195+
expect(screen.queryByTestId('app-tile-showcase_app')).toBeNull();
196+
expect(screen.getByTestId('home-system-settings-link')).toBeInTheDocument();
197+
expect(screen.getByTestId('home-apps-count')).toHaveTextContent(/^1$/);
198+
expect(fetcher).toHaveBeenCalledTimes(1);
199+
});
200+
201+
it('a set that hides Setup takes the System Settings link away', async () => {
202+
renderHome(meApps(['crm', 'showcase_app']));
203+
expect(await screen.findByTestId('app-tile-showcase_app')).toBeInTheDocument();
204+
expect(screen.getByTestId('app-tile-crm')).toBeInTheDocument();
205+
expect(screen.queryByTestId('home-system-settings-link')).toBeNull();
206+
});
207+
208+
it('CONTROL — a 404 (no security plugin) draws every tile, as before', async () => {
209+
renderHome(meApps(404));
210+
expect(await screen.findByTestId('app-tile-showcase_app')).toBeInTheDocument();
211+
expect(screen.getByTestId('app-tile-crm')).toBeInTheDocument();
212+
expect(screen.getByTestId('home-system-settings-link')).toBeInTheDocument();
213+
});
214+
215+
it('holds the loading line, and no tile, while the first read is out', async () => {
216+
let answer!: (res: Response) => void;
217+
renderHome(vi.fn(() => new Promise<Response>((resolve) => (answer = resolve))));
218+
expect(await screen.findByText('«home.loading»')).toBeInTheDocument();
219+
expect(screen.queryByTestId('app-tile-showcase_app')).toBeNull();
220+
expect(screen.queryByTestId('app-tile-crm')).toBeNull();
221+
222+
await act(async () => {
223+
answer(new Response(JSON.stringify({ apps: [{ name: 'setup' }, { name: 'crm' }] }), { status: 200 }));
224+
});
225+
expect(screen.getByTestId('app-tile-crm')).toBeInTheDocument();
226+
expect(screen.queryByTestId('app-tile-showcase_app')).toBeNull();
227+
});
228+
});

0 commit comments

Comments
 (0)