Files
windmill/frontend/src/lib/components/dbTableFormat.test.ts
T
Diego ImbertandClaude Opus 5.5 4fd7d62bd0 feat: rework the db manager: native grid, tabs, sql editor, joined columns (#11340)
* feat: replace ag-grid in the db manager table viewer with a native grid

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: add user-managed data, diagram and sql editor tabs to the db manager

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: add schema autocomplete to the db manager sql editor and polish its layout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: add joined foreign key columns and draggable tabs to the db manager

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: move db manager tabs on drop instead of mid-drag

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: open followed foreign keys in a new db manager tab

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: scroll large tables, drop stale joins and return to the last tab on close

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: tolerate the db manager tabs going away while switching data table

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep saved joined columns while metadata loads, test joins in every dialect

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: put the db manager grid on the input surface in dark mode

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: address db manager review nits on joins, boolean keys and sql quoting

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: keep the dark border color on the left pinned column edge

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: tone down the db manager tree menu icons

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: write json and jsonb values from the db manager through a text cast

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: dim unrelated diagram tables less on hover

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: match json columns as text when deleting a db manager row

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: compare postgres json columns as text in exact db manager filters

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: pick the columns the db manager grid shows

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: toggle every db manager column from one checkbox

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: word joined columns as a view in the db manager

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: keep data table roles and access visible when unavailable, with the reason

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: keep data table and instance roles visible in settings when unavailable

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: hide a db manager column from its header menu

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: format db manager columns with a unit, significant digits and color rules

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: drop the before/after hints from the db manager unit picker

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: write the euro after the amount and keep units off non-numeric values

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: color rule presets, bold and italic, layered and reorderable rules in the db manager

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: decimals, thousands separator, compact notation and alignment in db manager column formats

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat: compact db manager format controls, a notation toggle group and a reset button

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix: db manager format and filter nits

Keep the value's scale when decimals are auto, read boolean color-rule conditions as
booleans, let a rule's text color reach foreign-key links, close the formatter when the
columns picker opens, and filter BigQuery complex columns through TO_JSON_STRING.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 15:58:25 +02:00

62 lines
2.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { cellStyle, formatValue, UNIT_PRESETS } from './dbTableFormat'
describe('formatValue', () => {
it('sets the decimals, groups thousands and compacts', () => {
expect(formatValue('1234567.891', { decimals: 2 })).toBe('1234567.89')
expect(formatValue('1234567.891', { decimals: 2, notation: 'thousands' })).toBe('1,234,567.89')
expect(formatValue(3, { decimals: 2 })).toBe('3.00')
expect(formatValue('1234.50', { notation: 'thousands' })).toBe('1,234.50')
expect(formatValue('35412345', { notation: 'compact', decimals: 1 })).toBe('35.4M')
// Past what a float holds: numeric columns arrive as text and keep every digit.
expect(formatValue('12345678901234567890.5', { notation: 'thousands' })).toBe(
'12,345,678,901,234,567,890.5'
)
})
it('places the unit on its side, the sign before a leading one', () => {
expect(formatValue('12.5', { unit: { symbol: '%', position: 'after' } })).toBe('12.5%')
expect(formatValue(-5000, { unit: { symbol: '$', position: 'before' } })).toBe('-$5000')
expect(
formatValue('35412345', { notation: 'compact', decimals: 1, unit: UNIT_PRESETS[2] })
).toBe('35.4M\u00A0€')
})
it('leaves a value untouched when nothing applies to it', () => {
expect(formatValue('1234', { align: 'left' })).toBeUndefined()
expect(formatValue('N/A', { unit: { symbol: '$', position: 'before' } })).toBeUndefined()
expect(formatValue(null, { unit: { symbol: '$', position: 'before' } })).toBeUndefined()
})
})
describe('cellStyle', () => {
it('layers every matching rule, a later one overriding what it sets', () => {
const format = {
rules: [
{ condition: '', bold: true, bg: '#f3f4f6' },
{ condition: '>= 10', bg: '#fef9c3' },
{ condition: '>= 100', bg: '#fee2e2', text: '#991b1b' }
]
}
expect(cellStyle('150', 'int4', format)).toEqual({
bold: true,
bg: '#fee2e2',
text: '#991b1b'
})
expect(cellStyle('50', 'int4', format)).toEqual({ bold: true, bg: '#fef9c3' })
expect(cellStyle('5', 'int4', format)).toEqual({ bold: true, bg: '#f3f4f6' })
const bools = {
rules: [
{ condition: '=true', bg: 'green' },
{ condition: 'f', bg: 'red' }
]
}
expect(cellStyle('t', 'bool', bools)?.bg).toBe('green')
expect(cellStyle(false, 'bool', bools)?.bg).toBe('red')
expect(cellStyle(null, 'bool', bools)).toBeUndefined()
expect(cellStyle('refunded', 'text', { rules: [{ condition: '=paid', bold: true }] })).toBe(
undefined
)
})
})