Files
start-os/ui/test/config.test.ts
Matt Hill 5741cf084f Subnav (#391)
* begin subnav implementation

* implement subnav AND angular forms for comparison

* unions working-ish, list of enums working

* new form approach almost complete

* finish new forms approach for action inputs and config

* expandable list items and handlebars display

* Config animation (#394)

* config cammel

* config animation

Co-authored-by: Drew Ansbacher <drew.ansbacher@spiredigital.com>

* improve server settings inputs, still needs work

* delete all notifications, styling, and bugs

* contracted by default

Co-authored-by: Drew Ansbacher <drew.ansbacher@gmail.com>
Co-authored-by: Drew Ansbacher <drew.ansbacher@spiredigital.com>
2022-01-21 20:35:52 -07:00

264 lines
7.3 KiB
TypeScript

import { displayUniqueBy } from '../src/app/app-config/config-cursor'
function assert (predicate: boolean, message: string) {
if (!predicate) {
throw new Error('Assertion Failed: ' + message)
}
}
function assertEq (a: any, b: any, message: string) {
assert(a === b, message)
}
function test () {
assertEq(
displayUniqueBy(
'foo',
{
type: 'object',
name: 'Object',
spec: {
'foo': {
type: 'string',
name: 'Foo',
nullable: true,
copyable: false,
masked: false,
},
},
nullByDefault: false,
nullable: false,
uniqueBy: 'foo',
},
{
foo: 'foo-val',
},
),
'Foo',
'base string uses name mapping',
)
assertEq(
displayUniqueBy(
{
any: [
'foo',
'bar',
],
},
{
type: 'object',
name: 'Object',
spec: {
'foo': {
type: 'string',
name: 'Foo',
nullable: true,
copyable: false,
masked: false,
},
'bar': {
type: 'string',
name: 'Bar',
nullable: true,
copyable: false,
masked: false,
},
},
nullByDefault: false,
nullable: false,
uniqueBy: {
any: [
'foo',
'bar',
],
},
},
{
foo: 'foo-val',
bar: 'bar-val',
},
),
'Foo and Bar',
'`any` must be joined with `and`',
)
assertEq(
displayUniqueBy(
{
all: [
'foo',
'bar',
],
},
{
type: 'object',
name: 'Object',
spec: {
'foo': {
type: 'string',
name: 'Foo',
nullable: true,
copyable: false,
masked: false,
},
'bar': {
type: 'string',
name: 'Bar',
nullable: true,
copyable: false,
masked: false,
},
},
nullByDefault: false,
nullable: false,
uniqueBy: {
all: [
'foo',
'bar',
],
},
},
{
foo: 'foo-val',
bar: 'bar-val',
},
),
'Foo or Bar',
'`all` must be joined with `or`',
)
assertEq(
displayUniqueBy(
{
any: [
'foo',
{
all: [
'bar',
'baz',
],
},
],
},
{
type: 'object',
name: 'Object',
spec: {
'foo': {
type: 'string',
name: 'Foo',
nullable: true,
copyable: false,
masked: false,
},
'bar': {
type: 'string',
name: 'Bar',
nullable: true,
copyable: false,
masked: false,
},
'baz': {
type: 'string',
name: 'Baz',
nullable: true,
copyable: false,
masked: false,
},
},
nullByDefault: false,
nullable: false,
uniqueBy: {
any: [
'foo',
{
all: [
'bar',
'baz',
],
},
],
},
},
{
foo: 'foo-val',
bar: 'bar-val',
baz: 'baz-val',
},
),
'Foo and (Bar or Baz)',
'`any` of `all` is correct',
)
assertEq(
displayUniqueBy(
{
any: [
'foo',
{
all: [
'bar',
'baz',
],
},
],
},
{
type: 'union',
name: 'Union',
tag: {
id: 'variant',
name: 'Variant',
'variant-names': {
'variant-a': 'Variant A',
'variant-b': 'Variant B',
},
},
variants: {
'variant-a': {
'foo': {
type: 'string',
name: 'Foo',
nullable: true,
copyable: false,
masked: false,
},
'bar': {
type: 'string',
name: 'Bar',
nullable: true,
copyable: false,
masked: false,
},
'baz': {
type: 'string',
name: 'Baz',
nullable: true,
copyable: false,
masked: false,
},
},
'variant-b': { },
},
uniqueBy: {
any: [
'foo',
{
all: [
'bar',
'baz',
],
},
],
},
default: 'variant-a',
},
{
variant: 'variant-a',
foo: 'foo-val',
bar: 'bar-val',
baz: 'baz-val',
},
),
'Foo and (Bar or Baz)',
'union is correct',
)
}