Skip to content

Commit 4072c3a

Browse files
committed
test(app-shell): re-pin the walled list-state test to the browser layout
Claude-Session: https://claude.ai/code/session_01L6bhgUkr3W7rNEqPk3J858 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 237bbe0 commit 4072c3a

1 file changed

Lines changed: 31 additions & 37 deletions

File tree

‎ui/packages/app-shell/src/console/__tests__/consoleListStateWall-12418.test.tsx‎

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
* `walledCatalogWriteVerdict`). A header sort and a Manage Views drag used to
77
* be such writes: the sort PUT the view, the drag PATCHed a `sortOrder` onto
88
* every saved view, so a workspace admin who is not the operator got an error
9-
* for a personal preference. They are the user's own list state now, a
10-
* `sys_user_preference` row: an organization row the tenant's user may write
11-
* under every posture.
9+
* for a personal preference. They are the user's own list state now. Since
10+
* objectstack#35955 the sort is the list's draft and the tab order and the
11+
* density are the reader's layout in this browser
12+
* (`list-layout:<user id>:<object>`, `../../views/listLayoutStore.ts`), so
13+
* neither reaches the server at all: no metadata write, and no
14+
* `sys_user_preference` write either.
1215
*
1316
* ## The tree
1417
*
1518
* The real `ConsoleShell` providers, the real `ConnectedShell` (its real
16-
* `ObjectStackAdapter`, its `UserStateBridge` and the list-state family), and
19+
* `ObjectStackAdapter` and its `UserStateBridge`), and
1720
* the real object page inside it, over the fake framework the preference
1821
* budget pin uses (`preferenceFramework.ts`), here WALLED: every metadata
1922
* write is answered 403. The session reports the `group` posture and a
@@ -23,13 +26,12 @@
2326
*
2427
* ## The pins
2528
*
26-
* 1. A header sort and a drag-reorder put NO metadata write on the wire
27-
* and raise no error. The drag lands as ONE preference write of the
28-
* object's row; the sort is the list's draft (objectstack#35955) and
29-
* writes nothing.
29+
* 1. A header sort and a drag-reorder put NO write on the wire and raise no
30+
* error. The drag is kept in this browser's layout entry; the sort is
31+
* the list's draft and is kept nowhere.
3032
* 2. objectui#12474 — the density toggle and a Hide Fields change put NO
31-
* metadata write on the wire and raise no error. The density lands as
32-
* ONE preference write of the same row; the hide is the draft's.
33+
* write on the wire and raise no error. The density is kept in the same
34+
* layout entry; the hide is the draft's.
3335
* 3. CONTROL — the wall is live: a metadata write made in this same tree
3436
* (the real adapter's own view write, `createView`) is answered 403.
3537
* Since objectui#12474 no list toolbar control makes one, so the control
@@ -126,7 +128,8 @@ import { useAdapter } from '../../providers/AdapterProvider';
126128
import '@objectstack/lint';
127129
import { ObjectView } from '../../views/ObjectView';
128130
import { resetListDraftStoreForTests } from '../../views/listDraftStore';
129-
import { createPreferenceFramework, preferenceRowId, type PreferenceFramework } from './preferenceFramework';
131+
import { listLayoutStorageKey, resetListLayoutStoreForTests } from '../../views/listLayoutStore';
132+
import { createPreferenceFramework, type PreferenceFramework } from './preferenceFramework';
130133

131134
const FIELDS = {
132135
id: { type: 'text', label: 'Id' },
@@ -142,7 +145,7 @@ const OBJECT = {
142145
},
143146
};
144147

145-
/** The user already has a list-state row for the object (from another device). */
148+
/** A list-state row an earlier Console stored for the user: no longer read or written (objectstack#35955). */
146149
const STORE = { u1: { 'ui.list.account': { viewOrder: [ALL_ID, MINE_ID] } } };
147150

148151
let fake: PreferenceFramework;
@@ -174,10 +177,14 @@ function boot() {
174177
);
175178
}
176179

180+
/** The reader's layout entry for the object in this browser. */
181+
const storedLayout = () => JSON.parse(localStorage.getItem(listLayoutStorageKey('u1', OBJECT_NAME)!) ?? 'null');
182+
177183
const wait = (ms: number) => act(() => new Promise<void>((resolve) => setTimeout(resolve, ms)));
178184

179185
beforeEach(() => {
180186
resetListDraftStoreForTests();
187+
resetListLayoutStoreForTests();
181188
listProps = null;
182189
pageAdapter = null;
183190
localStorage.clear();
@@ -195,7 +202,7 @@ afterEach(() => {
195202
});
196203

197204
describe('a user\'s list state under a walled posture (objectui#12418)', () => {
198-
it('a header sort and a drag-reorder write no metadata and raise no error; the drag lands as one preference write, the sort as the draft', async () => {
205+
it('a header sort and a drag-reorder write nothing to the server and raise no error; the drag is kept in this browser, the sort as the draft', async () => {
199206
boot();
200207
await waitFor(() => expect(typeof listProps?.onSortChange).toBe('function'), { timeout: 5000 });
201208
await screen.findByTestId('stub-reorder');
@@ -208,22 +215,18 @@ describe('a user\'s list state under a walled posture (objectui#12418)', () => {
208215
await act(async () => {
209216
fireEvent.click(screen.getByTestId('stub-reorder'));
210217
});
211-
// Past the preference debounce (500 ms) and the round trip.
212-
await waitFor(() => expect(fake.wire.writes).toHaveLength(1), { timeout: 3000 });
213-
await wait(400);
218+
// Past the old preference debounce (500 ms) and a round trip.
219+
await wait(900);
214220

215221
expect(fake.wire.metaWrites).toEqual([]);
222+
expect(fake.wire.writes).toEqual([]);
216223
expect(toast.error).not.toHaveBeenCalled();
217-
expect(fake.wire.writes).toHaveLength(1);
218-
const [write] = fake.wire.writes;
219-
// An update of the row the boot read found: no second read, no insert.
220-
expect(write.id).toBe(preferenceRowId('u1', 'ui.list.account'));
221224
expect(fake.wire.gets.length).toBe(readsBefore);
222-
// objectstack#35955 — the sort is the list's draft: it is stored nowhere.
223-
expect(write.value).toEqual({ viewOrder: [MINE_ID, ALL_ID] });
225+
// objectstack#35955 — the order is this browser's; the sort is the list's draft, stored nowhere.
226+
expect(storedLayout()).toEqual({ viewOrder: [MINE_ID, ALL_ID] });
224227
});
225228

226-
it('a density toggle and a Hide Fields change write no metadata and raise no error; the density lands as one preference write, the hide as the draft (objectui#12474)', async () => {
229+
it('a density toggle and a Hide Fields change write nothing to the server and raise no error; the density is kept in this browser, the hide as the draft (objectui#12474)', async () => {
227230
boot();
228231
await waitFor(() => expect(typeof listProps?.schema?.onDensityChange).toBe('function'), { timeout: 5000 });
229232
await wait(100);
@@ -232,30 +235,21 @@ describe('a user\'s list state under a walled posture (objectui#12418)', () => {
232235
act(() => {
233236
listProps.schema.onDensityChange('comfortable');
234237
});
235-
// Past the preference debounce (500 ms) and the round trip.
236-
await waitFor(() => expect(fake.wire.writes).toHaveLength(1), { timeout: 3000 });
237-
await wait(400);
238-
expect(fake.wire.metaWrites).toEqual([]);
239-
expect(toast.error).not.toHaveBeenCalled();
240-
expect(fake.wire.writes).toHaveLength(1);
241-
expect(fake.wire.writes[0].id).toBe(preferenceRowId('u1', 'ui.list.account'));
242-
expect(fake.wire.writes[0].value).toEqual({
243-
viewOrder: [ALL_ID, MINE_ID],
244-
perView: { [ALL_ID]: { rowHeight: 'medium' } },
245-
});
238+
await wait(100);
239+
expect(storedLayout()).toEqual({ perView: { [ALL_ID]: { rowHeight: 'medium' } } });
246240
// The list is handed the user's density back.
247241
expect(listProps.schema.rowHeight).toBe('medium');
248242

249243
act(() => {
250244
listProps.onHiddenFieldsChange(['name']);
251245
});
252-
// Past the preference debounce (500 ms) and a round trip: nothing more is written.
246+
// Past the old preference debounce (500 ms) and a round trip: nothing is written.
253247
await wait(900);
254248
expect(fake.wire.metaWrites).toEqual([]);
249+
expect(fake.wire.writes).toEqual([]);
255250
expect(toast.error).not.toHaveBeenCalled();
256-
expect(fake.wire.writes).toHaveLength(1);
257251
expect(listProps.schema.hiddenFields).toEqual(['name']);
258-
// No second read: each write updates the row the boot read found.
252+
expect(storedLayout()).toEqual({ perView: { [ALL_ID]: { rowHeight: 'medium' } } });
259253
expect(fake.wire.gets.length).toBe(readsBefore);
260254
});
261255

0 commit comments

Comments
 (0)