6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
153 lines
4.8 KiB
TypeScript
153 lines
4.8 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
resolveFilterSelectValues,
|
|
resolvePredicateSelectValues,
|
|
selectValueToNames,
|
|
} from '@/lib/table/select-values'
|
|
import type { ColumnDefinition } from '@/lib/table/types'
|
|
|
|
const status: ColumnDefinition = {
|
|
id: 'col_status',
|
|
name: 'status',
|
|
type: 'select',
|
|
options: [
|
|
{ id: 'opt_open', name: 'Open' },
|
|
{ id: 'opt_closed', name: 'Closed' },
|
|
],
|
|
}
|
|
|
|
const tags: ColumnDefinition = {
|
|
id: 'col_tags',
|
|
name: 'tags',
|
|
type: 'select',
|
|
multiple: true,
|
|
options: [
|
|
{ id: 'opt_a', name: 'Alpha' },
|
|
{ id: 'opt_b', name: 'Beta' },
|
|
],
|
|
}
|
|
|
|
const title: ColumnDefinition = { id: 'col_title', name: 'title', type: 'string' }
|
|
|
|
describe('selectValueToNames', () => {
|
|
it('maps a single option id to its name', () => {
|
|
expect(selectValueToNames(status, 'opt_open')).toBe('Open')
|
|
})
|
|
|
|
it('returns null for an empty single value', () => {
|
|
expect(selectValueToNames(status, null)).toBeNull()
|
|
expect(selectValueToNames(status, '')).toBeNull()
|
|
})
|
|
|
|
it('drops a single id with no matching option', () => {
|
|
expect(selectValueToNames(status, 'gone')).toBeNull()
|
|
})
|
|
|
|
it('maps multi ids to a names array in order', () => {
|
|
expect(selectValueToNames(tags, ['opt_b', 'opt_a'])).toEqual(['Beta', 'Alpha'])
|
|
})
|
|
|
|
it('drops orphaned ids in a multi value', () => {
|
|
expect(selectValueToNames(tags, ['opt_a', 'gone'])).toEqual(['Alpha'])
|
|
})
|
|
|
|
it('returns an empty array for an empty multi value', () => {
|
|
expect(selectValueToNames(tags, [])).toEqual([])
|
|
})
|
|
})
|
|
|
|
// Row-level select resolution now lives in `__tests__/cell-format.test.ts`,
|
|
// fused with the column key translation.
|
|
|
|
describe('resolveFilterSelectValues', () => {
|
|
const columns = [title, status, tags]
|
|
|
|
it('resolves an equality-shorthand option name to its id', () => {
|
|
expect(resolveFilterSelectValues({ col_status: 'Open' }, columns)).toEqual({
|
|
col_status: 'opt_open',
|
|
})
|
|
})
|
|
|
|
it('resolves names inside $eq/$ne/$in/$nin operators', () => {
|
|
expect(
|
|
resolveFilterSelectValues(
|
|
{ col_status: { $ne: 'Closed' }, col_tags: { $in: ['Alpha', 'Beta'] } },
|
|
columns
|
|
)
|
|
).toEqual({ col_status: { $ne: 'opt_closed' }, col_tags: { $in: ['opt_a', 'opt_b'] } })
|
|
})
|
|
|
|
it('accepts an id verbatim (idempotent) and leaves unknown values as-is', () => {
|
|
expect(resolveFilterSelectValues({ col_status: 'opt_open' }, columns)).toEqual({
|
|
col_status: 'opt_open',
|
|
})
|
|
expect(resolveFilterSelectValues({ col_status: 'Nope' }, columns)).toEqual({
|
|
col_status: 'Nope',
|
|
})
|
|
})
|
|
|
|
it('resolves names under $contains/$ncontains (multi-select membership)', () => {
|
|
expect(
|
|
resolveFilterSelectValues(
|
|
{ col_tags: { $contains: 'Alpha' }, col_status: { $ncontains: 'Closed' } },
|
|
columns
|
|
)
|
|
).toEqual({ col_tags: { $contains: 'opt_a' }, col_status: { $ncontains: 'opt_closed' } })
|
|
})
|
|
|
|
it('recurses into $and/$or and leaves non-select fields untouched', () => {
|
|
expect(
|
|
resolveFilterSelectValues({ $or: [{ col_status: 'Open' }, { col_title: 'x' }] }, columns)
|
|
).toEqual({ $or: [{ col_status: 'opt_open' }, { col_title: 'x' }] })
|
|
})
|
|
})
|
|
|
|
/**
|
|
* The block builder serializes without schema access, so an option NAME that
|
|
* looks numeric or boolean arrives scalar-coerced ("123" → 123). Resolution
|
|
* must still find the option, or a correctly-authored builder filter compares
|
|
* a number against the stored id string and matches nothing.
|
|
*/
|
|
describe('resolvePredicateSelectValues — scalar-coerced option names', () => {
|
|
const numericStatus: ColumnDefinition = {
|
|
id: 'col_code',
|
|
name: 'code',
|
|
type: 'select',
|
|
options: [
|
|
{ id: 'opt_123', name: '123' },
|
|
{ id: 'opt_true', name: 'true' },
|
|
],
|
|
}
|
|
const columns = [numericStatus]
|
|
|
|
it('resolves a coerced numeric name to its option id', () => {
|
|
expect(
|
|
resolvePredicateSelectValues({ all: [{ field: 'col_code', op: 'eq', value: 123 }] }, columns)
|
|
).toEqual({ all: [{ field: 'col_code', op: 'eq', value: 'opt_123' }] })
|
|
})
|
|
|
|
it('resolves a coerced boolean name, including inside in/contains', () => {
|
|
expect(
|
|
resolvePredicateSelectValues(
|
|
{ any: [{ field: 'col_code', op: 'in', value: [true, 123] }] },
|
|
columns
|
|
)
|
|
).toEqual({ any: [{ field: 'col_code', op: 'in', value: ['opt_true', 'opt_123'] }] })
|
|
expect(
|
|
resolvePredicateSelectValues(
|
|
{ all: [{ field: 'col_code', op: 'contains', value: 123 }] },
|
|
columns
|
|
)
|
|
).toEqual({ all: [{ field: 'col_code', op: 'contains', value: 'opt_123' }] })
|
|
})
|
|
|
|
it('leaves a scalar with no matching option name as-is', () => {
|
|
expect(
|
|
resolvePredicateSelectValues({ all: [{ field: 'col_code', op: 'eq', value: 999 }] }, columns)
|
|
).toEqual({ all: [{ field: 'col_code', op: 'eq', value: 999 }] })
|
|
})
|
|
})
|