|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * R5 `relationship/line-items-inline-edit` and R6 |
| 5 | + * `relationship/association-inline-edit` ask one question of a relationship: |
| 6 | + * is it edited inline within the parent's form at all? |
| 7 | + * |
| 8 | + * `FieldSchema.inlineEdit` accepts `true`, `'grid'` and `'form'`, and every |
| 9 | + * reader treats all three as inline-edited (the console's inline subforms, the |
| 10 | + * spec's body-table predicate, the sibling `relationship/inline-edit-needs-bulk` |
| 11 | + * rule). So R5 stays silent on any of the three — telling an author who chose |
| 12 | + * `'grid'` to "consider inlineEdit: true" would replace the mode they picked — |
| 13 | + * and R6 warns on any of the three, because a `'grid'` or `'form'` association |
| 14 | + * clutters the parent's entry form exactly as `true` does. Absent (and `false`) |
| 15 | + * is the control on both sides: R5 suggests, R6 is silent. |
| 16 | + */ |
| 17 | + |
| 18 | +import { describe, expect, it } from 'vitest'; |
| 19 | +import { lintDataModel } from './data-model-rules.js'; |
| 20 | + |
| 21 | +const R5 = 'relationship/line-items-inline-edit'; |
| 22 | +const R6 = 'relationship/association-inline-edit'; |
| 23 | + |
| 24 | +const INLINE_VALUES = [true, 'grid', 'form'] as const; |
| 25 | + |
| 26 | +/** A parent plus one child whose `master_detail` back to it carries `inlineEdit` (omitted when `undefined`). */ |
| 27 | +const stack = (child: string, inlineEdit: unknown): any[] => [ |
| 28 | + { name: 'order', fields: { name: { type: 'text' } } }, |
| 29 | + { |
| 30 | + name: child, |
| 31 | + fields: { |
| 32 | + order: { |
| 33 | + type: 'master_detail', |
| 34 | + reference: 'order', |
| 35 | + required: true, |
| 36 | + deleteBehavior: 'cascade', |
| 37 | + ...(inlineEdit === undefined ? {} : { inlineEdit }), |
| 38 | + }, |
| 39 | + }, |
| 40 | + }, |
| 41 | +]; |
| 42 | + |
| 43 | +const hits = (objects: any[], rule: string) => lintDataModel(objects).filter((i) => i.rule === rule); |
| 44 | + |
| 45 | +describe('R5 relationship/line-items-inline-edit — silent on every inline-edit mode', () => { |
| 46 | + it.each(INLINE_VALUES)('is silent when the line-item relationship declares inlineEdit: %s', (inlineEdit) => { |
| 47 | + expect(hits(stack('order_line', inlineEdit), R5)).toEqual([]); |
| 48 | + }); |
| 49 | + |
| 50 | + it.each([undefined, false])('suggests inline editing when inlineEdit is %s', (inlineEdit) => { |
| 51 | + const [issue, ...rest] = hits(stack('order_line', inlineEdit), R5); |
| 52 | + expect(rest).toEqual([]); |
| 53 | + expect(issue?.severity).toBe('suggestion'); |
| 54 | + expect(issue?.path).toBe('objects[1].fields.order.inlineEdit'); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +describe('R6 relationship/association-inline-edit — warns on every inline-edit mode', () => { |
| 59 | + it.each(INLINE_VALUES)('warns when an association relationship declares inlineEdit: %s', (inlineEdit) => { |
| 60 | + const [issue, ...rest] = hits(stack('order_comment', inlineEdit), R6); |
| 61 | + expect(rest).toEqual([]); |
| 62 | + expect(issue?.severity).toBe('warning'); |
| 63 | + expect(issue?.path).toBe('objects[1].fields.order.inlineEdit'); |
| 64 | + }); |
| 65 | + |
| 66 | + it.each([undefined, false])('is silent when inlineEdit is %s', (inlineEdit) => { |
| 67 | + expect(hits(stack('order_comment', inlineEdit), R6)).toEqual([]); |
| 68 | + }); |
| 69 | +}); |
0 commit comments