This repository was archived by the owner on Nov 4, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathObjectView.tableColumnsForwarding.test.tsx
More file actions
298 lines (272 loc) · 12.5 KB
/
Copy pathObjectView.tableColumnsForwarding.test.tsx
File metadata and controls
298 lines (272 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/**
* ObjectUI
* Copyright (c) 2024-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* objectui#5269 — `table.columns` reaches the NON-grid paths too.
*
* `ObjectViewSchema.table` is `Partial< Omit< ObjectGridSchema, 'type' |
* 'objectName' > >`, where `columns` is the canonical spelling and `fields`
* carries "@deprecated Use columns instead". `ObjectView` does not spread
* `table`; it forwards a hand-written whitelist, and that whitelist had ONE
* read of `table.columns` in the whole file — the grid one. Both other field-
* list read points took the deprecated key alone:
*
* generateViewSchema `baseProps` `table.fields` only
* delegated `renderListView` schema `table.fields` only
*
* So `table: { columns: [...] }` — the shape the type recommends — produced an
* empty field list off the grid path, from a schema that compiled and read
* correctly. Same silent-success shape as objectui#5102; different mechanism:
* not a whitelist that knows only legacy spellings, but one that disagreed
* with itself between two rendering paths.
*
* ## What this file pins, and on which surface
*
* Both changed sites are pinned where a CONSUMER can be observed, not merely
* where the value is emitted:
*
* `baseProps` -> `object-kanban` consumed as `cardFields`
* (`ObjectKanban` reads `schema.cardFields`)
* `baseProps` -> `object-tree` consumed as `fields`
* (`ObjectTree.getTreeConfig` reads `schema.fields`)
* delegated -> `list-view` consumed as `columns` (`ListView`'s column set)
*
* ## The surfaces that get NO test here, deliberately
*
* `baseProps` also feeds `object-gallery`, `object-calendar`, `object-timeline`,
* `object-gantt` and `object-map`. Measured on this tree, none of those five
* renderers reads a field list off its schema at all — every `.fields` in them
* is `objectDef.fields` (object METADATA) or gallery's `schema.grouping.fields`.
* So the value this fix forwards is inert on those five, before the fix and
* after it. Asserting `fields` on their generated schema would pin the emit
* and prove nothing about the surface, so it is stated here instead of tested.
* (The card objectui#5269 names kanban / gallery / calendar as the affected
* surfaces; the measurable set is kanban / tree / delegated.)
*
* ## One asymmetry between the two changed sites
*
* `table.columns` is `string[] | ListColumn[]`. The delegated `list-view`
* slot declares that same union and `ListView` reads both, so it takes the
* value RAW — flattening there would throw away the width/label the author
* wrote. The non-grid `baseProps` slot is a names slot (both segments ahead of
* `table` declare `string[]`; `ObjectKanban` indexes records by each entry), so
* the `ListColumn[]` half is resolved to names with `columnIdentity` — the
* same fold `ObjectGrid` applies to this very value. Both halves are pinned.
*
* ## Precedence
*
* Unchanged, and pinned below: the two segments ahead of `table`
* (`listViews` entry, then `activeView`) still outrank it. Within the `table`
* segment the canonical key wins and the deprecated one keeps working — the
* same rule objectui#5102 applied to its four pairs.
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, waitFor } from '@testing-library/react';
import { ObjectView } from '../ObjectView';
import type { ObjectViewSchema } from '@object-ui/types';
/** Every schema the view hands to SchemaRenderer, in order. */
const rendered: any[] = [];
vi.mock('@object-ui/react', async (importOriginal) => {
const React = await import('react');
return {
...(await importOriginal<Record<string, unknown>>()),
SchemaRenderer: ({ schema }: any) => {
rendered.push(schema);
return <div data-testid="schema-renderer">{schema?.type}</div>;
},
SchemaRendererContext: React.createContext(null),
subscribeDataChanges: () => () => {},
notifyDataChanged: () => {},
};
});
/** The grid the view delegates to, replaced by a probe that records its schema. */
const gridSchemas: any[] = [];
vi.mock('@object-ui/plugin-grid', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
ObjectGrid: ({ schema }: any) => {
gridSchemas.push(schema);
return <div data-testid="object-grid" />;
},
}));
vi.mock('@object-ui/plugin-form', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
ObjectForm: () => <div data-testid="object-form" />,
}));
const mockDataSource = () => ({
find: vi.fn().mockResolvedValue({ data: [], total: 0 }),
findOne: vi.fn(),
create: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
getObjectSchema: vi.fn().mockResolvedValue({ name: 'task', fields: {} }),
});
/**
* Render a non-grid view and return the schema `generateViewSchema` produced.
* `views` drives the view types `defaultViewType` cannot spell (`tree`).
*/
async function generatedSchema(
schema: Partial<ObjectViewSchema>,
views?: any[],
): Promise<any> {
rendered.length = 0;
render(
<ObjectView
schema={{ type: 'object-view', objectName: 'task', ...schema } as ObjectViewSchema}
views={views}
dataSource={mockDataSource() as any}
/>,
);
await waitFor(() => expect(rendered.length).toBeGreaterThan(0));
return rendered[rendered.length - 1];
}
/** Render through the delegated `renderListView` slot and return its schema. */
function delegatedSchema(schema: Partial<ObjectViewSchema>): any {
const seen: any[] = [];
render(
<ObjectView
schema={{ type: 'object-view', objectName: 'task', ...schema } as ObjectViewSchema}
dataSource={mockDataSource() as any}
renderListView={({ schema: s }: any) => { seen.push(s); return <div data-testid="delegated" />; }}
/>,
);
return seen[0];
}
/** Render on the grid path and return the schema ObjectGrid was handed. */
function forwardedGridSchema(schema: Partial<ObjectViewSchema>): any {
gridSchemas.length = 0;
render(
<ObjectView
schema={{ type: 'object-view', objectName: 'task', ...schema } as ObjectViewSchema}
dataSource={mockDataSource() as any}
/>,
);
return gridSchemas[0];
}
const KANBAN = { defaultViewType: 'kanban' as const };
const TREE_VIEWS = [{ id: 'tree-1', label: 'Tree', type: 'tree' as const }];
beforeEach(() => {
vi.clearAllMocks();
rendered.length = 0;
gridSchemas.length = 0;
});
describe('kanban: a canonical table.columns reaches the cards (objectui#5269)', () => {
it('forwards table.columns as the kanban card fields', async () => {
// Before the fix this arrived as `cardFields: []` — the card fields the
// author declared were dropped at the forwarding hop, not at the renderer.
const s = await generatedSchema({ ...KANBAN, table: { columns: ['stage', 'owner'] } as any });
expect(s.type).toBe('object-kanban');
expect(s.cardFields).toEqual(['stage', 'owner']);
expect(s.fields).toEqual(['stage', 'owner']);
});
it('still forwards the deprecated table.fields', async () => {
// The alias must keep working — every view authored against today's docs
// writes it. (Green before AND after the fix: this pins the half that must
// NOT change, not the defect.)
const s = await generatedSchema({ ...KANBAN, table: { fields: ['stage'] } as any });
expect(s.cardFields).toEqual(['stage']);
});
it('prefers the canonical table.columns over the deprecated table.fields', async () => {
const s = await generatedSchema({
...KANBAN,
table: { columns: ['stage'], fields: ['owner'] } as any,
});
expect(s.cardFields).toEqual(['stage']);
});
it('resolves the ListColumn[] form of table.columns to field NAMES', async () => {
// `ObjectGridSchema.columns` is `string[] | ListColumn[]`, but this slot is
// a names slot: `resolveKanbanCardFields` casts to `string[]` and the card
// loop indexes the record by each entry. Forwarding the objects raw would
// produce a non-empty card field list naming nothing — and a non-empty list
// suppresses ObjectKanban's `highlightFields` fallback, so the cards would
// come out emptier than before this card. Resolved at the boundary with
// `columnIdentity`, the same fold ObjectGrid applies to this very value.
const s = await generatedSchema({
...KANBAN,
table: { columns: [{ field: 'stage', label: 'Stage', width: 120 }] } as any,
});
expect(s.cardFields).toEqual(['stage']);
});
it('falls through to table.fields when no column entry names a field', async () => {
// The empty-array trap: `[] || x` is `[]`, so a `columns` whose entries all
// fail to resolve must yield `undefined`, not an empty list that stops the
// chain on a falsy-looking truthy value.
const s = await generatedSchema({
...KANBAN,
table: { columns: [{ label: 'no identity here' }], fields: ['owner'] } as any,
});
expect(s.cardFields).toEqual(['owner']);
});
it('keeps a named view outranking the table segment', async () => {
// Precedence is unchanged by this card and must stay that way: the two
// segments ahead of `table` still win. (Green on both legs — a guard on
// the fix, not evidence of it.)
const s = await generatedSchema({
...KANBAN,
listViews: { mine: { label: 'Mine', columns: ['assignee'] } },
defaultListView: 'mine',
table: { columns: ['stage'] } as any,
} as any);
expect(s.cardFields).toEqual(['assignee']);
});
});
describe('tree: a canonical table.columns reaches the flat columns (objectui#5269)', () => {
it('forwards table.columns as the tree view fields', async () => {
const s = await generatedSchema({ table: { columns: ['stage', 'owner'] } as any }, TREE_VIEWS);
expect(s.type).toBe('object-tree');
expect(s.fields).toEqual(['stage', 'owner']);
});
it('still forwards the deprecated table.fields', async () => {
const s = await generatedSchema({ table: { fields: ['stage'] } as any }, TREE_VIEWS);
expect(s.fields).toEqual(['stage']);
});
});
describe('delegated renderListView: canonical first, alias still working (objectui#5269)', () => {
it('hands over a canonical table.columns as the list-view columns', () => {
expect(delegatedSchema({ table: { columns: ['stage', 'owner'] } as any }).columns)
.toEqual(['stage', 'owner']);
});
it('hands over the ListColumn[] form of table.columns unchanged', () => {
// `ObjectGridSchema.columns` (and `list-view`'s own `columns`) are both
// `string[] | ListColumn[]`, so the object form is a declared shape on
// this slot and must not be flattened on the way through.
const cols = [{ field: 'stage', label: 'Stage', width: 200 }];
expect(delegatedSchema({ table: { columns: cols } as any }).columns).toEqual(cols);
});
it('still hands over the deprecated table.fields', () => {
expect(delegatedSchema({ table: { fields: ['stage'] } as any }).columns).toEqual(['stage']);
});
it('prefers the canonical table.columns over the deprecated table.fields', () => {
expect(delegatedSchema({ table: { columns: ['stage'], fields: ['owner'] } as any }).columns)
.toEqual(['stage']);
});
it('keeps a named view outranking the table segment', () => {
const s = delegatedSchema({
listViews: { mine: { label: 'Mine', columns: ['assignee'] } },
defaultListView: 'mine',
table: { columns: ['stage'] } as any,
} as any);
expect(s.columns).toEqual(['assignee']);
});
});
describe('grid path: unchanged by this card — the control', () => {
it('keeps emitting table.columns and table.fields in their own slots', () => {
// The grid path forwards BOTH slots and lets `ObjectGrid` arbitrate
// (objectui#5102's shape). This card does not touch it; the assertion is
// here so a future "make all three sites identical" tidy-up cannot
// collapse the two slots without a red test.
//
// The `undefined` half is counter-probed by the populated half in the same
// render: `fields: undefined` alone would also be what a probe that saw no
// grid schema at all would report.
const canonicalOnly = forwardedGridSchema({ table: { columns: ['stage'] } as any });
expect(canonicalOnly.columns).toEqual(['stage']);
expect(canonicalOnly.fields).toBeUndefined();
const legacyOnly = forwardedGridSchema({ table: { fields: ['owner'] } as any });
expect(legacyOnly.fields).toEqual(['owner']);
expect(legacyOnly.columns).toBeUndefined();
});
});