Skip to content

Commit be788ed

Browse files
committed
test(plugin-list,plugin-grid): pin the no-access and "mine" empty states; changeset
Claude-Session: https://claude.ai/code/session_01RYq63NT6L4eGmQNvE9e7D8 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 202b884 commit be788ed

4 files changed

Lines changed: 401 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@object-ui/plugin-list': patch
3+
'@object-ui/plugin-grid': patch
4+
'@object-ui/i18n': patch
5+
---
6+
7+
fix(plugin-list,plugin-grid): an empty list tells "no records you can see" and "nothing of yours yet" apart from "no records"
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
An empty list chose its copy from the user's query and the view's filter alone. A member who may read none of an object's records and may not create one was told "Nothing here yet / Create your first record to get started." beside no Create button, and every "my …" view (`owner` equals the current user) told someone who owns nothing "No records match this view's filter."
13+
14+
- **No filter, no create grant.** When the permission answer has loaded and the caller does not hold the create grant (the `listNew` row of the affordance-to-grant map, the verdict the page's own New reads), the empty state reads "No records you can see" and asks the reader to contact an administrator. The add-record action is not drawn for that caller, even on a view that enables `addRecord`.
15+
- **A filter naming the signed-in user.** When the view's declared filter compares a field to the caller's own id (or still carries the `{current_user_id}` placeholder), the empty state reads "Nothing of yours yet", with the add-record action only under the create grant.
16+
- **Unchanged.** The first-run copy and action for a caller who may create, the user-query and view-filter copy, an authored `emptyState`, the 403 error panel, and every surface with no permission provider mounted.
17+
18+
`ListView` (grid and gallery), the standalone `ObjectGallery` and `ObjectGrid`'s default empty state decide the same way. `@object-ui/i18n` gains `list.ownedNoneTitle`, `list.ownedNoneMessage`, `list.noneVisibleTitle` and `list.noneVisibleMessage` in all ten locale packs.
19+
20+
What to do: nothing. A view that authors its own `emptyState` keeps it.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*
8+
* objectstack#25898 — an empty `object-grid` tells "no records you can see"
9+
* and "nothing of yours yet" apart from "no records", the way `ListEmptyState`
10+
* (plugin-list) does and in the same `list.*` words.
11+
*
12+
* - No filter and a caller KNOWN not to hold the create grant (the `listNew`
13+
* row, asked once permissions have loaded): "No records you can see", never
14+
* the first-run invitation to create.
15+
* - A declared filter naming the signed-in user (resolved to the caller's id,
16+
* or the `{current_user_id}` placeholder): "Nothing of yours yet", not "No
17+
* records match this view's filter".
18+
*
19+
* SUITE DIRECTION, predicted before running: the read-only and "my" cases are
20+
* RED against the base commit; the create-grant, no-provider and
21+
* plain-filter controls are green in both worlds.
22+
*/
23+
24+
import React from 'react';
25+
import { describe, it, expect, afterEach } from 'vitest';
26+
import { render, screen, cleanup } from '@testing-library/react';
27+
import '@testing-library/jest-dom';
28+
import { FilterScopeProvider } from '@object-ui/react';
29+
import { MePermissionsProvider, type MePermissionsResponse } from '@object-ui/permissions';
30+
// Registers `object-grid`, the block under test.
31+
import { ObjectGridRenderer } from '../index';
32+
33+
afterEach(cleanup);
34+
35+
const OBJECT = 'crm_case';
36+
const USER = 'u-rep';
37+
38+
const READ_ONLY = { allowCreate: false, allowRead: true, allowEdit: false, allowDelete: false };
39+
const FULL = { allowCreate: true, allowRead: true, allowEdit: true, allowDelete: true };
40+
41+
const envelope = (bits: Record<string, boolean>): MePermissionsResponse => ({
42+
authenticated: true,
43+
userId: USER,
44+
tenantId: null,
45+
roles: ['member'],
46+
permissionSets: ['member'],
47+
objects: { [OBJECT]: bits },
48+
fields: {},
49+
});
50+
51+
const grid = (extra: Record<string, unknown> = {}) => ({
52+
type: 'object-grid',
53+
objectName: OBJECT,
54+
columns: ['name'],
55+
data: { provider: 'value', items: [] },
56+
...extra,
57+
});
58+
59+
function mount(schema: Record<string, unknown>, bits?: Record<string, boolean>, currentUserId?: string) {
60+
let tree: React.ReactNode = <ObjectGridRenderer schema={schema} />;
61+
if (currentUserId) tree = <FilterScopeProvider currentUserId={currentUserId}>{tree}</FilterScopeProvider>;
62+
if (bits) tree = <MePermissionsProvider initialPermissions={envelope(bits)}>{tree}</MePermissionsProvider>;
63+
return render(<>{tree}</>);
64+
}
65+
66+
const emptyState = () => screen.findByTestId('object-grid-empty-state', {}, { timeout: 5000 });
67+
68+
describe('an empty object-grid says what the caller may see and do (objectstack#25898)', () => {
69+
it('no filter, no create grant: "No records you can see", never the first-run invitation', async () => {
70+
mount(grid(), READ_ONLY);
71+
const state = await emptyState();
72+
expect(state.querySelector('h3')).toHaveTextContent('No records you can see');
73+
expect(state).toHaveTextContent('ask your administrator');
74+
expect(state).not.toHaveTextContent('Create your first record');
75+
});
76+
77+
it('CONTROL: no filter, the create grant: the first-run copy as before', async () => {
78+
mount(grid(), FULL);
79+
const state = await emptyState();
80+
expect(state.querySelector('h3')).toHaveTextContent('Nothing here yet');
81+
});
82+
83+
it('CONTROL: no permission provider: the first-run copy as before (fail-open)', async () => {
84+
mount(grid());
85+
const state = await emptyState();
86+
expect(state.querySelector('h3')).toHaveTextContent('Nothing here yet');
87+
});
88+
89+
it('a filter resolved to the caller\'s id: "Nothing of yours yet"', async () => {
90+
mount(grid({ filter: [['owner', '=', '{current_user_id}']] }), FULL, USER);
91+
const state = await emptyState();
92+
expect(state.querySelector('h3')).toHaveTextContent('Nothing of yours yet');
93+
expect(state).not.toHaveTextContent('No records match this view');
94+
});
95+
96+
it('CONTROL: a filter about something else keeps the view-filter copy', async () => {
97+
mount(grid({ filter: [['status', '=', 'open']] }), FULL, USER);
98+
const state = await emptyState();
99+
expect(state.querySelector('h3')).toHaveTextContent('No matching records');
100+
});
101+
});
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#25898 — the list empty state tells "no records you can see" and
11+
* "nothing of yours yet" apart from "no records".
12+
*
13+
* Measured on the console: a sales rep who may read none of 38 cases opened
14+
* the case list and was told "Nothing here yet / Create your first record to
15+
* get started." beside no New button; and every "my …" view (`owner` equals
16+
* the current user) told an owner of nothing "No records match this view's
17+
* filter."
18+
*
19+
* Three cases, chosen by what the list knows:
20+
* - no filter, and the caller holds the create grant: today's first-run copy
21+
* and the add-record action;
22+
* - no filter, and the caller is KNOWN not to hold it (the `listNew` row of the
23+
* affordance-to-grant map, once permissions have loaded): "No records you can
24+
* see", and no add-record action even when the view enables one;
25+
* - the view's declared filter names the signed-in user: "Nothing of yours
26+
* yet", with the action only under the create grant.
27+
*
28+
* SUITE DIRECTION, predicted before running: the read-only and "my view" cases
29+
* are RED against the base commit (first-run copy / view-filter copy, and the
30+
* action drawn for a read-only caller); the create-grant, no-provider and
31+
* plain-filter cases are green in both worlds and pin that the fix leaves them
32+
* alone.
33+
*/
34+
35+
import * as React from 'react';
36+
import { describe, it, expect, vi, afterEach } from 'vitest';
37+
import { render, waitFor, cleanup } from '@testing-library/react';
38+
import { ListView } from '../ListView';
39+
import { filterNamesCurrentUser } from '../ListEmptyState';
40+
import { SchemaRendererProvider, FilterScopeProvider } from '@object-ui/react';
41+
import { MePermissionsProvider, type MePermissionsResponse } from '@object-ui/permissions';
42+
import type { ListViewSchema } from '@object-ui/types';
43+
44+
afterEach(cleanup);
45+
46+
const OBJECT = 'crm_case';
47+
const USER = 'u-rep';
48+
49+
function emptyDataSource() {
50+
return {
51+
find: vi.fn().mockResolvedValue([]),
52+
findOne: vi.fn(),
53+
create: vi.fn(),
54+
update: vi.fn(),
55+
delete: vi.fn(),
56+
};
57+
}
58+
59+
const READ_ONLY = { allowCreate: false, allowRead: true, allowEdit: false, allowDelete: false };
60+
const FULL = { allowCreate: true, allowRead: true, allowEdit: true, allowDelete: true };
61+
62+
const envelope = (bits: Record<string, boolean>): MePermissionsResponse => ({
63+
authenticated: true,
64+
userId: USER,
65+
tenantId: null,
66+
roles: ['member'],
67+
permissionSets: ['member'],
68+
objects: { [OBJECT]: bits },
69+
fields: {},
70+
});
71+
72+
/** A `list-view` node as an author writes it (FilterNode-array filters). */
73+
const authored = (node: Record<string, unknown>): ListViewSchema =>
74+
({ type: 'list-view', objectName: OBJECT, fields: ['name'], addRecord: { enabled: true }, ...node }) as unknown as ListViewSchema;
75+
76+
async function emptyState(
77+
schema: ListViewSchema,
78+
{ bits, currentUserId }: { bits?: Record<string, boolean>; currentUserId?: string } = {},
79+
): Promise<HTMLElement> {
80+
const ds = emptyDataSource();
81+
let tree: React.ReactNode = (
82+
<SchemaRendererProvider dataSource={ds as any}>
83+
<ListView schema={schema} dataSource={ds as any} onAddRecord={() => {}} />
84+
</SchemaRendererProvider>
85+
);
86+
if (currentUserId) tree = <FilterScopeProvider currentUserId={currentUserId}>{tree}</FilterScopeProvider>;
87+
if (bits) tree = <MePermissionsProvider initialPermissions={envelope(bits)}>{tree}</MePermissionsProvider>;
88+
const { container } = render(<>{tree}</>);
89+
await waitFor(() => {
90+
expect(container.querySelector('[data-testid="empty-state"]')).not.toBeNull();
91+
});
92+
return container.querySelector('[data-testid="empty-state"]') as HTMLElement;
93+
}
94+
95+
const addAction = (panel: HTMLElement) => panel.querySelector('[data-testid="empty-state-add-record"]');
96+
97+
describe('ListView empty state — no access vs no records (objectstack#25898)', () => {
98+
it('a caller without the create grant is told there is nothing they can see, and offered no Create', async () => {
99+
const panel = await emptyState(authored({}), { bits: READ_ONLY });
100+
expect(panel.textContent).toMatch(/No records you can see/);
101+
expect(panel.textContent).toMatch(/ask your administrator/);
102+
expect(panel.textContent).not.toMatch(/Nothing here yet/);
103+
expect(panel.textContent).not.toMatch(/Create your first record/);
104+
expect(addAction(panel)).toBeNull();
105+
});
106+
107+
it('a caller with the create grant still gets the first-run copy and the action', async () => {
108+
const panel = await emptyState(authored({}), { bits: FULL });
109+
expect(panel.textContent).toMatch(/Nothing here yet/);
110+
expect(panel.textContent).toMatch(/Create your first record/);
111+
expect(addAction(panel)).not.toBeNull();
112+
});
113+
114+
it('with no permission provider the copy is unchanged (fail-open)', async () => {
115+
const panel = await emptyState(authored({}));
116+
expect(panel.textContent).toMatch(/Nothing here yet/);
117+
expect(addAction(panel)).not.toBeNull();
118+
});
119+
120+
it('a "my" view — its filter resolved to the caller\'s id — says the caller has none yet', async () => {
121+
const panel = await emptyState(
122+
authored({ filter: [['owner', '=', USER]] }),
123+
{ bits: FULL, currentUserId: USER },
124+
);
125+
expect(panel.textContent).toMatch(/Nothing of yours yet/);
126+
expect(panel.textContent).not.toMatch(/No records match this view/);
127+
expect(addAction(panel)).not.toBeNull();
128+
});
129+
130+
it('a "my" view for a caller without the create grant offers no Create', async () => {
131+
const panel = await emptyState(
132+
authored({ filter: [['owner', '=', USER]] }),
133+
{ bits: READ_ONLY, currentUserId: USER },
134+
);
135+
expect(panel.textContent).toMatch(/Nothing of yours yet/);
136+
expect(addAction(panel)).toBeNull();
137+
});
138+
139+
it('a filter that does not name the caller keeps the view-filter copy', async () => {
140+
const panel = await emptyState(
141+
authored({ filter: [['status', '=', 'open']] }),
142+
{ bits: FULL, currentUserId: USER },
143+
);
144+
expect(panel.textContent).toMatch(/No matching records/);
145+
expect(panel.textContent).toMatch(/No records match this view/);
146+
});
147+
});
148+
149+
describe('filterNamesCurrentUser (objectstack#25898)', () => {
150+
it('finds the caller in every filter shape a list receives', () => {
151+
expect(filterNamesCurrentUser([['owner', '=', USER]], USER)).toBe(true);
152+
expect(filterNamesCurrentUser([{ field: 'owner', operator: 'equals', value: USER }], USER)).toBe(true);
153+
expect(filterNamesCurrentUser({ owner: { $eq: USER } }, USER)).toBe(true);
154+
expect(filterNamesCurrentUser(['and', ['status', '=', 'open'], ['owner', '=', USER]], USER)).toBe(true);
155+
});
156+
157+
it('reads the unresolved placeholder in both spellings', () => {
158+
expect(filterNamesCurrentUser([['owner', '=', '{current_user_id}']], undefined)).toBe(true);
159+
expect(filterNamesCurrentUser({ owner: '${current_user_id}' }, null)).toBe(true);
160+
});
161+
162+
it('answers false for a filter about someone or something else, and with no id to compare', () => {
163+
expect(filterNamesCurrentUser([['owner', '=', 'u-other']], USER)).toBe(false);
164+
expect(filterNamesCurrentUser([['status', '=', 'open']], USER)).toBe(false);
165+
expect(filterNamesCurrentUser([['owner', '=', '']], '')).toBe(false);
166+
expect(filterNamesCurrentUser(undefined, USER)).toBe(false);
167+
expect(filterNamesCurrentUser([['note', '=', 'user-{current_user_id}']], USER)).toBe(false);
168+
});
169+
});

0 commit comments

Comments
 (0)