Files
baserow/web-frontend/test/unit/core/utils/samplePreview.spec.js
Peter Evans a0e3591f9f feat: show the values of previous steps in the automation data explorer (#6718)
* feat: show the values of previous steps in the automation data explorer

* fix: hide placeholder sample values and hint untested current node in the data explorer

* fix: shorten the untested step hint and show it inline in the data explorer

* fix: keep the untested step hint visible next to a long node name
2026-11-17 09:18:25 +00:00

88 lines
2.6 KiB
JavaScript

import {
getSamplePreview,
isPlaceholderSampleData,
} from '@baserow/modules/core/utils/samplePreview'
describe('getSamplePreview', () => {
test('has nothing to show when no value is known', () => {
expect(getSamplePreview(undefined)).toBeNull()
})
test('tells a known empty value apart from an unknown one', () => {
expect(getSamplePreview(null)).toStrictEqual({ kind: 'empty' })
expect(getSamplePreview('')).toStrictEqual({ kind: 'empty' })
expect(getSamplePreview(' \n ')).toStrictEqual({ kind: 'empty' })
})
test('keeps falsy values that are real values', () => {
expect(getSamplePreview(0)).toStrictEqual({ kind: 'text', text: '0' })
expect(getSamplePreview(false)).toStrictEqual({
kind: 'text',
text: 'false',
})
})
test('summarises lists and objects', () => {
expect(getSamplePreview([1, 2, 3])).toStrictEqual({
kind: 'items',
count: 3,
})
expect(getSamplePreview([])).toStrictEqual({ kind: 'items', count: 0 })
expect(getSamplePreview({ a: 1, b: 2 })).toStrictEqual({
kind: 'fields',
count: 2,
})
})
test('puts text on one line and cuts it when too long', () => {
expect(getSamplePreview('Hello\n world')).toStrictEqual({
kind: 'text',
text: 'Hello world',
})
expect(getSamplePreview('abcdef', 3)).toStrictEqual({
kind: 'text',
text: 'abc…',
})
})
})
describe('isPlaceholderSampleData', () => {
test('recognises data holding placeholders only', () => {
expect(
isPlaceholderSampleData({
results: [
{
id: 0,
order: 'Example',
Name: 'Example',
Paid: false,
Notes: null,
},
],
has_next_page: false,
})
).toBe(true)
expect(isPlaceholderSampleData({ id: 0, Amount: 0.0, tags: [] })).toBe(true)
expect(isPlaceholderSampleData('Example')).toBe(true)
})
test('does not take real values for placeholders', () => {
expect(
isPlaceholderSampleData({ id: 0, Name: 'Example', Paid: true })
).toBe(false)
expect(isPlaceholderSampleData({ id: 7, Name: 'Example' })).toBe(false)
expect(
isPlaceholderSampleData({ results: [{ id: 0, Name: 'Acme' }] })
).toBe(false)
})
test('does not count data without any value', () => {
expect(isPlaceholderSampleData(null)).toBe(false)
expect(isPlaceholderSampleData(undefined)).toBe(false)
expect(isPlaceholderSampleData({})).toBe(false)
expect(isPlaceholderSampleData({ results: [], deleted_at: null })).toBe(
false
)
})
})