|
13 | 13 | import { describe, it, expect } from 'vitest'; |
14 | 14 | import { exactRecordListFilter, recordListPath } from '../useOpenRecordList'; |
15 | 15 | import { parseUrlFilterTriples } from '../drillUrlFilters'; |
| 16 | +import { convertFiltersToAST } from '@object-ui/core'; |
16 | 17 |
|
17 | 18 | const readAll = () => true; |
18 | 19 | const PARENT = { record_id: 'C-1' }; |
@@ -69,17 +70,92 @@ describe('exactRecordListFilter — the AND of the sources, written exactly or n |
69 | 70 | ]); |
70 | 71 | }); |
71 | 72 |
|
| 73 | + it('writes the spellings objectstack#30743 added: a boolean, a negation, the text operators, both sets', () => { |
| 74 | + const filter = exactRecordListFilter( |
| 75 | + [ |
| 76 | + PARENT, |
| 77 | + [ |
| 78 | + ['done', '=', true], |
| 79 | + ['archived', '=', false], |
| 80 | + ['status', 'in', ['paid', 'sent']], |
| 81 | + ['stage', 'nin', ['lost']], |
| 82 | + ['owner', '!=', 'u1'], |
| 83 | + ['name', 'contains', 'acme'], |
| 84 | + ['name', 'notcontains', 'test'], |
| 85 | + ['code', 'startswith', 'INV'], |
| 86 | + ['code', 'endswith', '-X'], |
| 87 | + ['email', 'icontains', 'ACME'], |
| 88 | + ], |
| 89 | + ], |
| 90 | + readAll, |
| 91 | + ); |
| 92 | + expect(roundTrip(filter)).toEqual([ |
| 93 | + ['record_id', '=', 'C-1'], |
| 94 | + ['done', '=', true], |
| 95 | + ['archived', '=', false], |
| 96 | + ['status', 'in', ['paid', 'sent']], |
| 97 | + ['stage', 'nin', ['lost']], |
| 98 | + ['owner', '!=', 'u1'], |
| 99 | + ['name', 'contains', 'acme'], |
| 100 | + ['name', 'notcontains', 'test'], |
| 101 | + ['code', 'startswith', 'INV'], |
| 102 | + ['code', 'endswith', '-X'], |
| 103 | + ['email', 'icontains', 'ACME'], |
| 104 | + ]); |
| 105 | + }); |
| 106 | + |
| 107 | + it('reads each of those back as the node the drill drawer queries, comparand type included', () => { |
| 108 | + // The drawer lowers the drill's object filter through `convertFiltersToAST`; |
| 109 | + // the list lowers nothing, it reads triples. The two must be one question. |
| 110 | + const cases: Record<string, unknown>[] = [ |
| 111 | + { done: true }, |
| 112 | + { done: false }, |
| 113 | + { status: { $in: ['paid', 'sent'] } }, |
| 114 | + { stage: { $nin: ['lost'] } }, |
| 115 | + { owner: { $ne: 'u1' } }, |
| 116 | + { name: { $contains: 'acme' } }, |
| 117 | + { name: { $notContains: 'test' } }, |
| 118 | + { code: { $startsWith: 'INV' } }, |
| 119 | + { code: { $endsWith: '-X' } }, |
| 120 | + { email: { $icontains: 'ACME' } }, |
| 121 | + ]; |
| 122 | + for (const condition of cases) { |
| 123 | + expect(roundTrip(exactRecordListFilter([condition], readAll))).toEqual([convertFiltersToAST(condition)]); |
| 124 | + } |
| 125 | + }); |
| 126 | + |
| 127 | + it('a set of numbers reads back as its members\' text, the posture equality and the bounds already have', () => { |
| 128 | + expect(roundTrip(exactRecordListFilter([{ priority: { $in: [1, 2] } }], readAll))).toEqual([ |
| 129 | + ['priority', 'in', ['1', '2']], |
| 130 | + ]); |
| 131 | + }); |
| 132 | + |
| 133 | + it('a set and an equality on one field are two params, both kept', () => { |
| 134 | + expect(roundTrip(exactRecordListFilter([{ status: { $in: ['a', 'b'] } }, { status: 'a' }], readAll))).toEqual([ |
| 135 | + ['status', 'in', ['a', 'b']], |
| 136 | + ['status', '=', 'a'], |
| 137 | + ]); |
| 138 | + }); |
| 139 | + |
| 140 | + it('a repeated set that agrees is written once', () => { |
| 141 | + const set = { status: { $in: ['a', 'b'] } }; |
| 142 | + expect(roundTrip(exactRecordListFilter([set, set], readAll))).toEqual([['status', 'in', ['a', 'b']]]); |
| 143 | + }); |
| 144 | + |
72 | 145 | it('a repeated condition that agrees is written once', () => { |
73 | 146 | const filter = exactRecordListFilter([PARENT, [['record_id', '=', 'C-1']]], readAll); |
74 | 147 | expect(roundTrip(filter)).toEqual([['record_id', '=', 'C-1']]); |
75 | 148 | }); |
76 | 149 |
|
77 | 150 | it.each([ |
78 | 151 | ['an `or`', ['or', ['status', '=', 'a'], ['status', '=', 'b']]], |
79 | | - ['a set operator', [['status', 'in', ['a', 'b']]]], |
80 | | - ['a negation', [['status', '!=', 'a']]], |
81 | | - ['a text operator', [['name', 'contains', 'x']]], |
82 | | - ['a boolean comparand', [['done', '=', true]]], |
| 152 | + ['an empty set', { status: { $in: [] } }], |
| 153 | + ['a set holding an empty string', { status: { $in: ['a', ''] } }], |
| 154 | + ['a set holding a boolean', { status: { $in: ['a', true] } }], |
| 155 | + ['two different sets on one field', { $and: [{ status: { $in: ['a', 'b'] } }, { status: { $in: ['a'] } }] }], |
| 156 | + ['a negation of a boolean', [['done', '!=', true]]], |
| 157 | + ['a text operator with a number', { name: { $contains: 5 } }], |
| 158 | + ['a `$between`', { amount: { $between: [1, 9] } }], |
83 | 159 | ['an empty-string comparand', [['status', '=', '']]], |
84 | 160 | ['a field-reference comparand', { amount: { $eq: { $field: 'budget' } } }], |
85 | 161 | ['a second, different comparand for the relationship', [['record_id', '=', 'C-2']]], |
|
0 commit comments