|
| 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 | + * The FLOOR itself (objectui#8496 — director seat, decision batch #86). |
| 11 | + * |
| 12 | + * This file pins the cheap half: the four members, and the ⛔ that keeps them |
| 13 | + * four. The EXPENSIVE half — that no surface's deliberate disagreement was |
| 14 | + * flattened into the floor — is pinned next to each surface: |
| 15 | + * `emptinessFloorExtensions-8496.test.tsx` in `@object-ui/fields` and in |
| 16 | + * `@object-ui/plugin-detail`, `galleryEmptinessFloor-8496.test.tsx` in |
| 17 | + * `@object-ui/plugin-list`, `kanbanEmptinessFloor-8496.test.tsx` in |
| 18 | + * `@object-ui/plugin-kanban`. |
| 19 | + * |
| 20 | + * ⚠️ A suite that only proves the floor works proves the half that was never |
| 21 | + * in doubt. Read the four files above as one pin. |
| 22 | + */ |
| 23 | + |
| 24 | +import { describe, it, expect } from 'vitest'; |
| 25 | +import { isEmptyValue } from '../emptiness.js'; |
| 26 | +import { isOptionGroupGated, isValueStillOffered } from '../../evaluator/optionRules.js'; |
| 27 | + |
| 28 | +/** The four members, and nothing else is one. */ |
| 29 | +const MEMBERS: Array<[string, unknown]> = [ |
| 30 | + ['null', null], |
| 31 | + ['undefined', undefined], |
| 32 | + ['the empty string', ''], |
| 33 | + ['the empty array', []], |
| 34 | +]; |
| 35 | + |
| 36 | +/** |
| 37 | + * Every candidate FIFTH member, each with the measurement that refused it. |
| 38 | + * These are values, and the floor calling any of them empty is the failure |
| 39 | + * this table exists to catch. |
| 40 | + */ |
| 41 | +const REFUSED_FIFTH_MEMBERS: Array<[string, unknown, string]> = [ |
| 42 | + ['a whitespace-only string', ' ', |
| 43 | + 'EMPTY only on record:details and RelatedList (objectui#8350) — an extension, not a member'], |
| 44 | + ['an empty object literal', {}, |
| 45 | + 'measured a VALUE and pinned (objectui#8474): a type-aware renderer draws it'], |
| 46 | + ['a populated object', { a: 1 }, 'a populated object is drawn by a type-aware renderer'], |
| 47 | + ['a one-entry array', [1], 'one entry is one thing to draw'], |
| 48 | + ['an array of one undefined', [undefined], 'length 1: the container has an entry'], |
| 49 | + ['zero', 0, 'a stored zero is a value on every surface'], |
| 50 | + ['false', false, 'BooleanCellRenderer keeps false a value (objectui#8582)'], |
| 51 | + ['the numeric epoch', 0, "DateCellRenderer's `!value` calls it empty — that is its extension"], |
| 52 | + ['the Date epoch', new Date(0), |
| 53 | + 'Object.keys(new Date(0)).length === 0, which is why that shape is not the test'], |
| 54 | + ['a populated Map', new Map([['a', 1]]), |
| 55 | + 'Object.keys() is empty on it — a false-empty the floor must not have'], |
| 56 | + ['a populated Set', new Set([1]), 'same false-empty shape as Map'], |
| 57 | + ['a class instance behind getters', new (class { get a() { return 1; } })(), |
| 58 | + 'same false-empty shape: state that Object.keys() cannot see'], |
| 59 | + ['the string "0"', '0', 'a non-empty string is a value however falsy it coerces'], |
| 60 | + ['NaN', NaN, 'falsy, but not one of the four members'], |
| 61 | +]; |
| 62 | + |
| 63 | +describe('objectui#8496 — the emptiness floor in @object-ui/core', () => { |
| 64 | + describe('THE FLOOR — exactly four members', () => { |
| 65 | + for (const [label, value] of MEMBERS) { |
| 66 | + it(`${label} is EMPTY`, () => { |
| 67 | + expect(isEmptyValue(value), `${label} must be a floor member`).toBe(true); |
| 68 | + }); |
| 69 | + } |
| 70 | + }); |
| 71 | + |
| 72 | + describe('⛔ THE FLOOR NEVER GROWS — every candidate fifth member is a VALUE', () => { |
| 73 | + for (const [label, value, why] of REFUSED_FIFTH_MEMBERS) { |
| 74 | + it(`${label} is a VALUE — ${why}`, () => { |
| 75 | + expect( |
| 76 | + isEmptyValue(value), |
| 77 | + `${label}: the floor grew a fifth member. ${why}`, |
| 78 | + ).toBe(false); |
| 79 | + }); |
| 80 | + } |
| 81 | + }); |
| 82 | + |
| 83 | + describe('THE MEMBER COUNT — stated as a number, so a widening cannot pass unnoticed', () => { |
| 84 | + it('exactly 4 of the probed shapes are empty', () => { |
| 85 | + const probes: unknown[] = [ |
| 86 | + ...MEMBERS.map(([, v]) => v), |
| 87 | + ...REFUSED_FIFTH_MEMBERS.map(([, v]) => v), |
| 88 | + ]; |
| 89 | + expect( |
| 90 | + probes.filter((v) => isEmptyValue(v)).length, |
| 91 | + 'the floor answered EMPTY for something outside its four members', |
| 92 | + ).toBe(MEMBERS.length); |
| 93 | + }); |
| 94 | + }); |
| 95 | + |
| 96 | + /** |
| 97 | + * The floor was not invented: it was PROMOTED out of this package's own |
| 98 | + * private copy in `evaluator/optionRules.ts`, which had spelled the same four |
| 99 | + * members since before the card. These two exports are that copy's only |
| 100 | + * readers, so their answers are the promotion's non-regression evidence. |
| 101 | + */ |
| 102 | + describe('THE PROMOTION — core’s own former private copy still answers the same', () => { |
| 103 | + for (const [label, value] of MEMBERS) { |
| 104 | + it(`a dependency holding ${label} gates the option list`, () => { |
| 105 | + expect( |
| 106 | + isOptionGroupGated('parent', { parent: value }), |
| 107 | + `${label}: an unmet dependency must still gate`, |
| 108 | + ).toBe(true); |
| 109 | + }); |
| 110 | + } |
| 111 | + |
| 112 | + it('a dependency holding a value does NOT gate', () => { |
| 113 | + expect(isOptionGroupGated('parent', { parent: 'cn' })).toBe(false); |
| 114 | + expect(isOptionGroupGated('parent', { parent: 0 })).toBe(false); |
| 115 | + expect(isOptionGroupGated('parent', { parent: false })).toBe(false); |
| 116 | + }); |
| 117 | + |
| 118 | + it('an empty value is always still offered (nothing to clear)', () => { |
| 119 | + for (const [label, value] of MEMBERS) { |
| 120 | + expect( |
| 121 | + isValueStillOffered(value, [{ label: 'A', value: 'a' }]), |
| 122 | + `${label}: an empty value has no stale choice to clear`, |
| 123 | + ).toBe(true); |
| 124 | + } |
| 125 | + expect(isValueStillOffered('gone', [{ label: 'A', value: 'a' }])).toBe(false); |
| 126 | + }); |
| 127 | + }); |
| 128 | +}); |
0 commit comments