|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +import { describe, it, expect } from 'vitest'; |
| 4 | +import { SysSharingRule } from './sys-sharing-rule.object.js'; |
| 5 | +import * as SharingObjects from './index.js'; |
| 6 | + |
| 7 | +/** |
| 8 | + * [#24701] No sharing list view groups on a field whose stored value is an |
| 9 | + * object's API name. |
| 10 | + * |
| 11 | + * The console (objectui at this repository's `.objectui-sha`) heads each group |
| 12 | + * with the grouping value as text: its group formatter turns a select value |
| 13 | + * into its option label and a boolean into Yes / No, and draws anything else |
| 14 | + * as stored. An `object-ref` field's CELL draws the object's icon and label, |
| 15 | + * but its group header drew the API name (`crm_account`), so `by_object` read |
| 16 | + * one machine name per group. #24611 removed the same grouping from |
| 17 | + * `sys_record_share.by_object`, where the field is a pointer pair's type half. |
| 18 | + * |
| 19 | + * A field stores an object's API name when it declares the `object-ref` |
| 20 | + * widget (the object picker) or when it is the `referenceVia` sibling of a |
| 21 | + * pointer pair. Enumerated over every object this package ships |
| 22 | + * (`objects/index.ts`), so a view added later is judged without anyone |
| 23 | + * listing it here. |
| 24 | + */ |
| 25 | +describe('sharing list views — no grouping on a field that stores an object API name (#24701)', () => { |
| 26 | + type ViewDef = { |
| 27 | + columns?: ReadonlyArray<string | { field: string }>; |
| 28 | + sort?: ReadonlyArray<{ field: string; order?: string }>; |
| 29 | + grouping?: { fields?: ReadonlyArray<{ field: string }> }; |
| 30 | + }; |
| 31 | + type ObjectDef = { |
| 32 | + name: string; |
| 33 | + fields: Record<string, { widget?: unknown; referenceVia?: unknown } | undefined>; |
| 34 | + listViews?: Record<string, ViewDef>; |
| 35 | + }; |
| 36 | + |
| 37 | + const objects = Object.values(SharingObjects) as unknown as ObjectDef[]; |
| 38 | + |
| 39 | + /** The fields of `object` whose stored value is an object's API name. */ |
| 40 | + function apiNameFields(object: ObjectDef): string[] { |
| 41 | + const names = new Set<string>(); |
| 42 | + for (const [name, def] of Object.entries(object.fields)) { |
| 43 | + if (def?.widget === 'object-ref') names.add(name); |
| 44 | + if (typeof def?.referenceVia === 'string') names.add(def.referenceVia); |
| 45 | + } |
| 46 | + return [...names].sort(); |
| 47 | + } |
| 48 | + |
| 49 | + it('finds the API-name field on every sharing object, so the case below cannot pass on an empty set', () => { |
| 50 | + const found = Object.fromEntries(objects.map((o) => [o.name, apiNameFields(o)])); |
| 51 | + expect(found).toEqual({ |
| 52 | + sys_record_share: ['object_name'], |
| 53 | + sys_sharing_rule: ['object_name'], |
| 54 | + sys_share_link: ['object_name'], |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + it('no list view groups on a field that stores an object API name', () => { |
| 59 | + const hits = objects.flatMap((o) => { |
| 60 | + const apiNames = new Set(apiNameFields(o)); |
| 61 | + return Object.entries(o.listViews ?? {}).flatMap(([view, def]) => |
| 62 | + (def.grouping?.fields ?? []) |
| 63 | + .filter((g) => apiNames.has(g.field)) |
| 64 | + .map((g) => `${o.name}.${view}: ${g.field}`)); |
| 65 | + }); |
| 66 | + expect(hits).toEqual([]); |
| 67 | + }); |
| 68 | + |
| 69 | + it('control: sys_sharing_rule.by_object still keeps one object\'s rules together and shows the Object column', () => { |
| 70 | + const view = (SysSharingRule.listViews as Record<string, ViewDef> | undefined)?.by_object; |
| 71 | + expect(view?.sort?.[0]).toEqual({ field: 'object_name', order: 'asc' }); |
| 72 | + expect(view?.columns?.[0]).toBe('object_name'); |
| 73 | + const fields = SysSharingRule.fields as Record<string, { widget?: unknown }>; |
| 74 | + expect(fields.object_name.widget).toBe('object-ref'); |
| 75 | + }); |
| 76 | +}); |
0 commit comments