|
| 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 | + * Kanban conditional formatting accepts CEL (#1584). |
| 11 | + * |
| 12 | + * Since kanban card styling moved onto the shared CEL evaluator, the kanban |
| 13 | + * schema's type + zod contract must match the runtime: a rule may be the native |
| 14 | + * `{ field, operator, value }` shape OR the spec `{ condition, style }` CEL |
| 15 | + * shape. This locks both so the two can't drift back apart. |
| 16 | + */ |
| 17 | +import { describe, it, expect } from 'vitest'; |
| 18 | +import { ObjectKanbanSchema } from '../zod/index.zod'; |
| 19 | +import type { KanbanConditionalFormattingRule } from '../objectql'; |
| 20 | + |
| 21 | +describe('kanban conditionalFormatting — zod contract', () => { |
| 22 | + const base = { type: 'object-kanban', objectName: 'task', groupField: 'status' }; |
| 23 | + |
| 24 | + it('accepts the native { field, operator, value } rule (back-compat)', () => { |
| 25 | + const parsed = ObjectKanbanSchema.safeParse({ |
| 26 | + ...base, |
| 27 | + conditionalFormatting: [ |
| 28 | + { field: 'priority', operator: 'equals', value: 'high', backgroundColor: '#fee2e2' }, |
| 29 | + ], |
| 30 | + }); |
| 31 | + expect(parsed.success).toBe(true); |
| 32 | + }); |
| 33 | + |
| 34 | + it('accepts the spec { condition, style } CEL rule (new)', () => { |
| 35 | + const parsed = ObjectKanbanSchema.safeParse({ |
| 36 | + ...base, |
| 37 | + conditionalFormatting: [ |
| 38 | + { condition: "record.status == 'done'", style: { backgroundColor: '#e0ffe0' } }, |
| 39 | + ], |
| 40 | + }); |
| 41 | + expect(parsed.success).toBe(true); |
| 42 | + }); |
| 43 | + |
| 44 | + it('accepts a mix of both shapes in one rule list', () => { |
| 45 | + const parsed = ObjectKanbanSchema.safeParse({ |
| 46 | + ...base, |
| 47 | + conditionalFormatting: [ |
| 48 | + { condition: "record.blocked == true", style: { borderColor: 'red' } }, |
| 49 | + { field: 'priority', operator: 'in', value: ['high', 'urgent'], backgroundColor: '#fef9c3' }, |
| 50 | + ], |
| 51 | + }); |
| 52 | + expect(parsed.success).toBe(true); |
| 53 | + }); |
| 54 | +}); |
| 55 | + |
| 56 | +describe('kanban conditionalFormatting — type contract', () => { |
| 57 | + it('KanbanConditionalFormattingRule admits both shapes at compile time', () => { |
| 58 | + const native: KanbanConditionalFormattingRule = { |
| 59 | + field: 'priority', |
| 60 | + operator: 'equals', |
| 61 | + value: 'high', |
| 62 | + backgroundColor: '#fee2e2', |
| 63 | + }; |
| 64 | + const cel: KanbanConditionalFormattingRule = { |
| 65 | + condition: "record.status == 'done'", |
| 66 | + style: { backgroundColor: '#e0ffe0' }, |
| 67 | + }; |
| 68 | + expect(native).toBeTruthy(); |
| 69 | + expect(cel).toBeTruthy(); |
| 70 | + }); |
| 71 | +}); |
0 commit comments