Skip to content

Commit b7edbeb

Browse files
fix(app-shell): Home draws the Connect an AI Assistant card after the greeting, apps and My work, one row on a phone (#35071)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBLW6dHPW6sSheA32XPKZzPV)_ Fixes #35017 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:首页「在 AI 助手里使用本系统」卡片从问候语上方挪到「我的工作」之后(没有「我的工作」时跟在「我的应用」之后;还没有应用的空首页则放在欢迎区之后);手机宽度下卡片缩成一行:图标 + 标题 + 「连接 AI 助手」+ 关闭。 - 为什么改:原来它是首页第一块内容,手机 375 宽下正文折成 5 行、卡片高 164px,把「我的应用」挤到屏幕中部以下。现在 375 宽下实测 54px。 - 风险与回滚:只动这张卡片的位置和样式,显示条件(未连接才显示、关闭后记住、首次设置清单在时让位)一行没改;回滚即 revert 本 PR。 - 先看:`HomePage.tsx`(两个渲染分支各挪一处,空首页分支的外框用 `empty:hidden` 在卡片不显示时不占位)、`ConnectAssistantCard.tsx`(`sm` 以下正文改为 `sr-only`,标题 `truncate`)、`ConnectAssistantCard.homePlacement-35017.test.tsx`。 - 两分钟验证:在一个未连接 AI 助手的账号上打开首页(管理员先关掉首次设置清单),桌面应看到问候语、我的应用、我的工作,然后才是这张卡片;把窗口拉到 375 宽,卡片应是一行。 - 需要你做的:无,席位落地。 ## What changes - `HomePage.tsx`: the card moves out of the page header. On the main branch it now sits inside the content column right after My work (`HomeActionCenter`), before Recent and Activity. When My work draws nothing, that still puts it right after the apps strip. On the no-apps branch it moves from above the welcome to after it, in a frame that collapses with `empty:hidden` when the card draws nothing, so the welcome's centring is unchanged on a page with no card. - `ConnectAssistantCard.tsx`: the card no longer draws its own page gutter and 1120 px column; the host's column gives both (an optional `className` lets the no-apps branch centre it). Below `sm` it is one row: tighter padding and gaps, the title on one line (`truncate`), and the sentence under it `sr-only`, so screen readers still read it. From `sm` up (`sm:not-sr-only`, `sm:whitespace-normal`, `sm:px-4 sm:py-3 sm:gap-3`) it looks as before. - Not changed: the show condition (`connectAssistantPath`, the dismissal record, `useConnectedAccess`, `useHomeItemClaimed('connect_assistant')`), the first-run checklist's row for the same item, and the rest of Home's layout. ## Why The card was the first thing on Home, above the greeting and the apps. On a 375 px phone its sentence wrapped to five lines and the card took about a quarter of the first screen. The card asks for: greeting, My apps and My work first, then this card, and one row on a phone at about 64 px. ## Tests - `ConnectAssistantCard.homePlacement-35017.test.tsx` (new, card-named, beside the harness): the real `HomePage` with the card stood in by a marker. With apps, the order is greeting, then the apps strip, then My work, then the card. With no My work section, the card still follows the greeting and the apps. With no app yet, the card follows the welcome. - `ConnectAssistantCard-30895.test.tsx` §8 (new): the card is one non-wrapping flex row of four parts (icon, title box, Connect, close); the title carries `truncate`; the sentence carries `sr-only sm:not-sr-only` and keeps its text. jsdom applies no stylesheet, so this pins classes and structure only; the drawn height and the breakpoint are the browser reading below. - Controls: §1 to §7 of the same harness (shown when nothing is connected, hidden when connected, unknown, dismissed, MCP off, connected while shown, checklist claim) are unchanged and green, so the show condition did not move. Run on `695d9213ec`, under the verify lock: pnpm exec vitest run --maxWorkers=2 .../ConnectAssistantCard-30895.test.tsx .../ConnectAssistantCard.homePlacement-35017.test.tsx Test Files 2 passed (2) Tests 16 passed (16) Ablation (one-off, not kept): with `scripts/ablation-replace.mjs`, the main-branch card was moved back above the greeting (leg 1 `--hold` replaced the new placement with a marker, leg 2 put `ConnectAssistantCard` back after `RecoveryPasswordReminder`). The two with-apps order pins went red (`expected false to be true`, 2 failed and 1 passed). The no-apps pin stayed green, as expected, because that branch was not mutated. The tool restored the file to its HEAD blob `f8a12eb872`, and `git diff HEAD` was empty. ## Acceptance notes - To see the card on a fresh admin, the first-run checklist has to be closed first. While its own Connect an AI assistant row is not done it claims the item, and the card stands aside (#32021 item 3). The live readings below close it first, and that behaviour is unchanged. - At 375 px the card now sits below the first screen (top 772 px on an 812 px viewport, under My work). That is the order the card asks for. - Phone breakpoint: the one-row form switches at Tailwind `sm` (640 px), as the card's existing `sm:` classes did, not at the console's 768 px `usePhoneViewport`. Between 640 and 767 px it is the two-line card. ## Verification Live, showcase backend (`objectstack dev --seed-admin`) and the console Vite server with `DEV_PROXY_TARGET` on it, zh-CN, signed in as the seeded admin, first-run checklist closed. Before = `origin/main` source served after a `--force` restart (served module checked for the absence of the new classes); after = this branch. | viewport | before: order, card | after: order, card | |---|---|---| | 1280x800 | card, greeting, apps, My work; card top 64 px, 66 px tall | greeting, apps, My work, card; card top 547 px, 66 px tall | | 375x812 | card, greeting, apps, My work; card top 64 px, **164 px** tall | greeting, apps, My work, card; card top 772 px, **54 px** tall | At 1280 the card looks as before (same 66 px, sentence shown). At 375 the sentence is visually collapsed (`position: absolute` from `sr-only`), and the title "在 AI 助手里使用本系统" fits on one line beside 连接 AI 助手 and the close button. The eight screenshots (page and card crop for each viewport, before and after) are kept with the seat's project files under `35017-live/` and can be attached on request. <details><summary>Gates (local subset)</summary> - `node scripts/pm/dispatch-gates.mjs --commands` derived 38 families; all 38 ran. `--ran` reconciliation: 38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN. - Exit 0 on first run: 35 of them. - `pnpm check:test-source-alias` exited 1 on `4fad856ab9`: the new placement pin reaches `import('@objectstack/lint')` through `usePublishAllDrafts`. Fixed in `695d9213ec` with a module-top `import '@objectstack/lint';`; the rerun exited 0. - `pnpm --dir ui exec vitest run scripts/` was SIGKILLed by the cgroup (memory) on the first run, with nothing judged. Rerun with `--maxWorkers=2`: exit 0, 171 files passed and 2 skipped, 5077 tests passed and 2 skipped. - `pnpm check:type-check-debt` exited 3 (PREREQUISITE NOT MET, queue timeout on the verify lock), with nothing measured. Rerun inside the lock: exit 0, "128/131 workspace packages type-checked ... 0 raw tsc error(s)". - Outside the derivation: `pnpm --filter @object-ui/app-shell type-check` exit 0. Its tsconfig excludes `__tests__/`, so it does not cover the two test files. `npx eslint` on the four changed ui files: 0 errors, 6 warnings, all on lines this PR does not touch. - CI runs the full farm (Test UI, lint and the rest). Those check-runs are read at L1, not repeated here. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (Not touched.) - [x] 2. Every name I added uses the casing for its kind. - [ ] 3. No formatter ran; `pnpm lint` passes. (No formatter ran; the repo-wide `pnpm lint` is CI's run, the changed files lint with 0 errors.) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (Not touched.) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. (The 维护者速读 block is the fleet's Chinese summary for the maintainer.) 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WGufzfrh8TiPJf1i2kMSoa <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzfrh8TiPJf1i2kMSoa --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a3e216e commit b7edbeb

5 files changed

Lines changed: 275 additions & 34 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/console': patch
4+
---
5+
6+
fix(app-shell): Home draws the Connect an AI Assistant card after the greeting, My apps and My work, as one row on a phone
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
Home used to open with the "Use this system in your AI assistant" card, above the greeting and the apps. On a 375 px phone its sentence wrapped to five lines, so the card took about a quarter of the first screen and pushed My apps below the middle.
12+
13+
- **Place.** The card now comes after the greeting, My apps and My work. When there is no My work section, it follows the apps. On a workspace with no app yet, it follows the welcome instead of sitting above it.
14+
- **Size on a phone.** Below the `sm` breakpoint the card is one row: icon, title on one line, Connect and close. The sentence under the title is hidden from view there but screen readers still read it. From `sm` up the card looks as it did.
15+
16+
When the card shows has not changed. It still shows only to someone who has connected no assistant, and it stays away after they close it. The first-run checklist's row for the same item is untouched.

‎ui/packages/app-shell/src/console/home/ConnectAssistantCard.tsx‎

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@
1919
*
2020
* Once the person connects one it is gone on the next read, and it does not
2121
* come back after a dismissal.
22+
*
23+
* Where and how big (objectstack#35017): the host draws it after the greeting,
24+
* My apps and My work, never above them, so it brings no padding or width of
25+
* its own; the host's column gives both. Below `sm` it is one row (icon,
26+
* title, Connect, close): the title keeps one line and the sentence under it
27+
* is visually collapsed but still read out, so a phone's first screen keeps
28+
* the apps. From `sm` up it is the two-line card it always was.
2229
*/
2330

2431
import { useState } from 'react';
2532
import { useNavigate } from 'react-router-dom';
2633
import { useAuth } from '@object-ui/auth';
27-
import { Button } from '@object-ui/components';
34+
import { Button, cn } from '@object-ui/components';
2835
import { useObjectTranslation } from '@object-ui/i18n';
2936
import { Bot, X } from 'lucide-react';
3037
import { useMetadata } from '../../providers/MetadataProvider.js';
@@ -33,7 +40,7 @@ import { useConnectedAccess } from '../connect/connectedAccess.js';
3340
import { cardStorage, markCardDismissed, wasCardDismissed } from './connectAssistantCardGate.js';
3441
import { useHomeItemClaimed } from './homeItemClaims.js';
3542

36-
export function ConnectAssistantCard() {
43+
export function ConnectAssistantCard({ className }: { className?: string } = {}) {
3744
const { t } = useObjectTranslation();
3845
const navigate = useNavigate();
3946
const { user } = useAuth();
@@ -55,35 +62,46 @@ export function ConnectAssistantCard() {
5562
};
5663

5764
return (
58-
<div className="px-4 sm:px-6 lg:px-8 pt-4">
59-
<div className="mx-auto max-w-[1120px]">
60-
<section
61-
className="flex items-center gap-3 rounded-xl border border-border bg-card px-4 py-3"
62-
data-testid="home-connect-assistant"
63-
aria-labelledby="home-connect-assistant-title"
65+
<section
66+
className={cn(
67+
'flex items-center gap-2 rounded-xl border border-border bg-card px-3 py-2 sm:gap-3 sm:px-4 sm:py-3',
68+
className,
69+
)}
70+
data-testid="home-connect-assistant"
71+
aria-labelledby="home-connect-assistant-title"
72+
>
73+
<Bot className="h-5 w-5 shrink-0 text-muted-foreground" aria-hidden />
74+
<div className="min-w-0 flex-1">
75+
<h2
76+
id="home-connect-assistant-title"
77+
className="truncate text-sm font-medium sm:whitespace-normal"
78+
data-testid="home-connect-assistant-title"
6479
>
65-
<Bot className="h-5 w-5 shrink-0 text-muted-foreground" aria-hidden />
66-
<div className="min-w-0 flex-1">
67-
<h2 id="home-connect-assistant-title" className="text-sm font-medium">
68-
{t('home.connectAssistant.title')}
69-
</h2>
70-
<p className="text-[13px] text-muted-foreground">{t('home.connectAssistant.body')}</p>
71-
</div>
72-
<Button size="sm" variant="outline" onClick={() => navigate(path)} data-testid="home-connect-assistant-open">
73-
{t('home.connectAssistant.action')}
74-
</Button>
75-
<button
76-
type="button"
77-
onClick={dismiss}
78-
aria-label={t('home.connectAssistant.dismiss')}
79-
title={t('home.connectAssistant.dismiss')}
80-
className="shrink-0 rounded-md p-1 text-muted-foreground hover:bg-accent hover:text-foreground"
81-
data-testid="home-connect-assistant-dismiss"
82-
>
83-
<X className="h-4 w-4" />
84-
</button>
85-
</section>
80+
{t('home.connectAssistant.title')}
81+
</h2>
82+
<p className="sr-only text-[13px] text-muted-foreground sm:not-sr-only" data-testid="home-connect-assistant-body">
83+
{t('home.connectAssistant.body')}
84+
</p>
8685
</div>
87-
</div>
86+
<Button
87+
size="sm"
88+
variant="outline"
89+
className="shrink-0"
90+
onClick={() => navigate(path)}
91+
data-testid="home-connect-assistant-open"
92+
>
93+
{t('home.connectAssistant.action')}
94+
</Button>
95+
<button
96+
type="button"
97+
onClick={dismiss}
98+
aria-label={t('home.connectAssistant.dismiss')}
99+
title={t('home.connectAssistant.dismiss')}
100+
className="shrink-0 rounded-md p-1 text-muted-foreground hover:bg-accent hover:text-foreground"
101+
data-testid="home-connect-assistant-dismiss"
102+
>
103+
<X className="h-4 w-4" />
104+
</button>
105+
</section>
88106
);
89107
}

‎ui/packages/app-shell/src/console/home/HomePage.tsx‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ export function HomePage({ checklist }: HomePageProps = {}) {
607607
{checklist?.('top')}
608608
<DeploymentNotice placement="home" />
609609
<RecoveryPasswordReminder t={t} />
610-
<ConnectAssistantCard />
611610
<div className="flex flex-1 items-center justify-center p-6">
612611
{/*
613612
Role-aware empty state. ADMINS get the AI-first magic moment as the
@@ -686,6 +685,12 @@ export function HomePage({ checklist }: HomePageProps = {}) {
686685
</Empty>
687686
)}
688687
</div>
688+
{/* objectstack#30895 — connect an AI assistant: after the page's own
689+
content, never above it (objectstack#35017). The frame collapses
690+
(`empty:hidden`) when the card draws nothing. */}
691+
<div className="px-4 pb-6 sm:px-6 lg:px-8 empty:hidden">
692+
<ConnectAssistantCard className="mx-auto max-w-[1120px]" />
693+
</div>
689694
</div>
690695
);
691696
}
@@ -697,8 +702,6 @@ export function HomePage({ checklist }: HomePageProps = {}) {
697702
{/* objectstack#30120 — see the empty-state branch above. */}
698703
<DeploymentNotice placement="home" />
699704
<RecoveryPasswordReminder t={t} />
700-
{/* objectstack#30895 — every person: connect an AI assistant, until they have or hide it. */}
701-
<ConnectAssistantCard />
702705

703706
{/* The content column (objectui#12601): 1120 px, centred, 28 px above the
704707
first section and 28 px between sections. No bordered card around the
@@ -919,6 +922,12 @@ export function HomePage({ checklist }: HomePageProps = {}) {
919922
t={t}
920923
/>
921924

925+
{/* objectstack#30895 — every person: connect an AI assistant, until
926+
they have or hide it. After the greeting, My apps and My work, so
927+
a first screen opens on the person's own things (objectstack#35017);
928+
with no My work it follows the apps. */}
929+
<ConnectAssistantCard />
930+
922931
{/* Continue where you left off + ambient activity. The activity column
923932
exists only for a caller who may read `sys_activity`
924933
(objectui#12081) — `HomeActivity` renders nothing otherwise, and an

‎ui/packages/app-shell/src/console/home/__tests__/ConnectAssistantCard-30895.test.tsx‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
* - §4 the close button hides it for this person on this browser, also in a
1212
* later mount (which reads nothing), and not for another person;
1313
* - §5 MCP turned off (the Account app carries no page): no card, no read;
14-
* - §6 connecting while it is shown (a key minted on this page) takes it away.
14+
* - §6 connecting while it is shown (a key minted on this page) takes it away;
15+
* - §8 its shape (objectstack#35017): one row of icon, title, Connect and
16+
* close, the title on one line and the sentence collapsed below `sm`.
17+
* jsdom applies no stylesheet, so this reads the classes and the order of
18+
* the row's parts; the drawn height at 375 px is the PR's browser reading.
1519
*
1620
* Rendered with the real router, the real data bus and the real hook; only
1721
* the adapter, the person and the served apps are stubbed. `t` echoes the key.
@@ -232,3 +236,28 @@ describe('§7 said once on Home (objectstack#32021 item 3)', () => {
232236
expect(await screen.findByTestId('home-connect-assistant')).toBeInTheDocument();
233237
});
234238
});
239+
240+
describe('§8 one row on a phone (objectstack#35017)', () => {
241+
it('is a single non-wrapping row: icon, title box, Connect, close', async () => {
242+
renderHome();
243+
const card = await screen.findByTestId('home-connect-assistant');
244+
expect(card).toHaveClass('flex', 'items-center');
245+
expect(card.className).not.toMatch(/\bflex-(col|wrap)\b/);
246+
const parts = Array.from(card.children);
247+
expect(parts).toHaveLength(4);
248+
expect(parts[0].tagName.toLowerCase()).toBe('svg');
249+
expect(parts[1]).toContainElement(screen.getByTestId('home-connect-assistant-title'));
250+
expect(parts[2]).toBe(screen.getByTestId('home-connect-assistant-open'));
251+
expect(parts[3]).toBe(screen.getByTestId('home-connect-assistant-dismiss'));
252+
});
253+
254+
it('keeps the title to one line and collapses the sentence below sm, still read out', async () => {
255+
renderHome();
256+
await screen.findByTestId('home-connect-assistant');
257+
expect(screen.getByTestId('home-connect-assistant-title')).toHaveClass('truncate');
258+
const body = screen.getByTestId('home-connect-assistant-body');
259+
// Visually hidden on a phone, back in the flow from `sm` up; never removed.
260+
expect(body).toHaveClass('sr-only', 'sm:not-sr-only');
261+
expect(body).toHaveTextContent('«home.connectAssistant.body»');
262+
});
263+
});
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#35017 — where Home draws the "Connect an AI Assistant" card.
5+
*
6+
* On the real `HomePage`, with the card itself stood in by a marker (whether
7+
* it shows is `ConnectAssistantCard-30895.test.tsx`'s, unchanged):
8+
*
9+
* - with apps, the first screen reads greeting, My apps, My work, and only
10+
* then the card; with no My work section it still follows the apps;
11+
* - with no app yet, it follows the empty state's welcome, not above it.
12+
*
13+
* The harness is `HomePage.greetingAndApps-12601.test.tsx`'s: every source the
14+
* page reads is stubbed, `t` echoes the key.
15+
*/
16+
17+
// HomePage reaches `import('@objectstack/lint')` (usePublishAllDrafts →
18+
// capabilityLint); pay that load at collection, not inside a case's timeout.
19+
import '@objectstack/lint';
20+
import '@testing-library/jest-dom/vitest';
21+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
22+
import { render, screen, cleanup } from '@testing-library/react';
23+
24+
const navigateMock = vi.fn();
25+
26+
const state = vi.hoisted(() => ({
27+
apps: [] as Array<Record<string, unknown>>,
28+
readable: true,
29+
}));
30+
31+
vi.mock('react-router-dom', async () => {
32+
const { createElement } = await import('react');
33+
return {
34+
useNavigate: () => navigateMock,
35+
Link: ({ to, ...rest }: { to: string } & Record<string, unknown>) =>
36+
createElement('a', { ...rest, href: to }),
37+
};
38+
});
39+
40+
vi.mock('@object-ui/i18n', async (importOriginal) => ({
41+
...(await importOriginal<Record<string, unknown>>()),
42+
useObjectTranslation: () => ({ t: (key: string) => `«${key}»`, language: 'en' }),
43+
useObjectLabel: () => {
44+
const label = (x: { name?: string; label?: string }) => String(x?.label || x?.name || '');
45+
return {
46+
appLabel: label,
47+
objectLabel: label,
48+
objectPluralLabel: label,
49+
dashboardLabel: label,
50+
pageLabel: label,
51+
reportLabel: label,
52+
viewLabel: (_object: string, _view: string, fallback?: string) => fallback ?? '',
53+
};
54+
},
55+
}));
56+
57+
vi.mock('@object-ui/auth', async (importOriginal) => ({
58+
...(await importOriginal<Record<string, unknown>>()),
59+
useAuth: () => ({ user: { id: 'u1', name: 'Dev Admin', email: 'dev.admin@example.com' } }),
60+
useWorkspaceAdminStatus: () => ({ isAdmin: true, isResolved: true }),
61+
}));
62+
63+
vi.mock('@object-ui/plugin-chatbot/core', async (importOriginal) => ({
64+
...(await importOriginal<typeof import('@object-ui/plugin-chatbot/core')>()),
65+
useAgents: () => ({ agents: [{ name: 'custom_helper' }] }),
66+
isAskAgent: () => false,
67+
agentHasCapability: () => false,
68+
}));
69+
70+
vi.mock('../../../providers/MetadataProvider', () => ({
71+
useMetadata: () => ({ apps: state.apps, objects: [], dashboards: [], pages: [], reports: [], loading: false }),
72+
}));
73+
vi.mock('../../../context/NavigationContext', () => ({
74+
useNavigationContext: () => ({ currentAppName: undefined }),
75+
}));
76+
vi.mock('../../../hooks/useCanAuthorMetadata', () => ({
77+
useCanAuthorMetadata: () => true,
78+
useCanReadPendingDrafts: () => true,
79+
}));
80+
// `readable: false` on both sources and no drafts row: My work draws nothing.
81+
vi.mock('../../../hooks/useHomeInbox', () => ({
82+
useHomeInbox: () => ({
83+
pendingApprovalsCount: 0,
84+
pendingApprovals: [],
85+
pendingApprovalsReadable: state.readable,
86+
notificationsReadable: state.readable,
87+
pendingApprovalsStatus: 'ready',
88+
notifications: [],
89+
unreadTopicCount: 0,
90+
notificationsStatus: 'ready',
91+
activity: { value: [], status: 'ready', readable: true },
92+
}),
93+
}));
94+
vi.mock('../../../runtime-config', () => ({
95+
getRuntimeConfig: () => ({ branding: { productName: 'ObjectStack' } }),
96+
isMarketplaceEnabled: () => true,
97+
isAiStudioEnabled: () => true,
98+
}));
99+
vi.mock('../../../hooks/useRecentItems', () => ({ useRecentItems: () => ({ recentItems: [] }) }));
100+
vi.mock('../../../hooks/useFavorites', () => ({ useFavorites: () => ({ favorites: [] }) }));
101+
vi.mock('../../../hooks/useAiSurface', () => ({ resolveAiApiBase: () => '' }));
102+
vi.mock('../../../preview/usePendingDrafts', () => ({ usePendingDrafts: () => ({ count: 0 }) }));
103+
vi.mock('../../../preview/usePublishAllDrafts', () => ({
104+
usePublishAllDrafts: () => ({ publishAll: async () => ({ ok: true }), publishing: false }),
105+
}));
106+
vi.mock('../../../hooks/useInboxBell', () => ({ useInboxBell: () => ({ markRead: vi.fn() }) }));
107+
vi.mock('../../deployment-notice/DeploymentNotice', () => ({ DeploymentNotice: () => null }));
108+
109+
// The card stood in by a marker that always draws, so only its place is read.
110+
vi.mock('../ConnectAssistantCard', async () => {
111+
const { createElement } = await import('react');
112+
return {
113+
ConnectAssistantCard: ({ className }: { className?: string }) =>
114+
createElement('section', { 'data-testid': 'home-connect-assistant', className }),
115+
};
116+
});
117+
118+
import { HomePage } from '../HomePage';
119+
120+
const CRM = { name: 'crm', label: 'CRM', icon: 'Building2' };
121+
122+
beforeEach(() => {
123+
navigateMock.mockReset();
124+
state.apps = [CRM];
125+
state.readable = true;
126+
vi.stubGlobal('fetch', vi.fn(async () => ({ ok: false, status: 404, json: async () => ({}) })));
127+
});
128+
129+
afterEach(() => {
130+
cleanup();
131+
vi.unstubAllGlobals();
132+
});
133+
134+
/** `a` comes before `b` in document order. */
135+
function before(a: Element, b: Element): boolean {
136+
return Boolean(a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING);
137+
}
138+
139+
describe('with apps: greeting, My apps, My work, then the card (objectstack#35017)', () => {
140+
it('draws the card after the greeting, the apps strip and My work', () => {
141+
render(<HomePage />);
142+
const greeting = screen.getByRole('heading', { level: 1 });
143+
const apps = screen.getByTestId('app-tile-crm');
144+
const work = screen.getByTestId('home-my-work');
145+
const card = screen.getByTestId('home-connect-assistant');
146+
expect(before(greeting, apps)).toBe(true);
147+
expect(before(apps, work)).toBe(true);
148+
expect(before(work, card)).toBe(true);
149+
});
150+
151+
it('with no My work section, the card still follows the greeting and the apps', () => {
152+
state.readable = false;
153+
render(<HomePage />);
154+
expect(screen.queryByTestId('home-my-work')).toBeNull();
155+
const card = screen.getByTestId('home-connect-assistant');
156+
expect(before(screen.getByRole('heading', { level: 1 }), card)).toBe(true);
157+
expect(before(screen.getByTestId('app-tile-crm'), card)).toBe(true);
158+
});
159+
});
160+
161+
describe('with no app yet: after the welcome (objectstack#35017)', () => {
162+
it('draws the card after the empty state, not above it', () => {
163+
state.apps = [];
164+
render(<HomePage />);
165+
const welcome = screen.getByText('«home.welcome»');
166+
const card = screen.getByTestId('home-connect-assistant');
167+
expect(before(welcome, card)).toBe(true);
168+
});
169+
});

0 commit comments

Comments
 (0)