Files
supabase/apps/studio/tests/components/Grid/Grid.utils.test.js
T
Joshen LimandTzeYiing d025e0f739 chore/fix studio jest tests (#25872)
* Fix tests in tests/unit, tests/components and files under tests, looking into tests/pages

* Fix tests under pages/projects root

* Fix

* Comment out broken tests that im stuck with

* Fix api-report.test

* Fix storage-report-test

* chore: fix some tests

* chore: remove logging

* Fix LogsPreviewer.test.js

* Fix most of logs-query-test

* Skip broken tests instead of false positiving them

---------

Co-authored-by: TzeYiing <ty@tzeyiing.com>
2024-05-11 12:05:25 +02:00

78 lines
2.4 KiB
JavaScript

import { formatSortURLParams, formatFilterURLParams } from 'components/grid/SupabaseGrid.utils'
// Sort URL syntax: `column:order`
describe('SupabaseGrid.utils: formatSortURLParams', () => {
test('should return an array of sort options based on URL params', () => {
const mockInput = ['id:asc', 'name:desc']
const output = formatSortURLParams(mockInput)
expect(output).toStrictEqual([
{
column: 'id',
ascending: true,
},
{
column: 'name',
ascending: false,
},
])
})
test('should reject any malformed sort options based on URL params', () => {
const mockInput = ['id', 'name:asc', ':asc']
const output = formatSortURLParams(mockInput)
expect(output).toStrictEqual([
{
column: 'name',
ascending: true,
},
])
})
})
// Filter URL syntax: `column:operatorAbbreviation:value`
describe('SupabaseGrid.utils: formatFilterURLParams', () => {
test('should return an array of filter options based on URL params', () => {
const mockInput = ['id:gte:20', 'id:lte:40']
const output = formatFilterURLParams(mockInput)
expect(output).toHaveLength(2)
expect(output[0]).toStrictEqual({
column: 'id',
operator: '>=',
value: '20',
})
expect(output[1]).toStrictEqual({
column: 'id',
operator: '<=',
value: '40',
})
})
test('should format filters for timestamps correctly', () => {
const mockInput = ['created_at:gte:2022-05-30 03:00:00']
const output = formatFilterURLParams(mockInput)
expect(output[0]).toStrictEqual({
column: 'created_at',
operator: '>=',
value: '2022-05-30 03:00:00',
})
})
test('should reject any malformed filter options based on URL params', () => {
const mockInput = ['id', ':gte', ':50', 'id:eq:10']
const output = formatFilterURLParams(mockInput)
expect(output).toHaveLength(1)
})
test('should reject any filter options with unrecognized operator', () => {
const mockInput = ['id:meme:40', 'name:eq:town']
const output = formatFilterURLParams(mockInput)
expect(output).toHaveLength(1)
})
test('should allow filter options to have empty value based on URL params', () => {
const mockInput = ['id:ilike:']
const output = formatFilterURLParams(mockInput)
expect(output).toHaveLength(1)
expect(output[0]).toStrictEqual({
column: 'id',
operator: '~~*',
value: '',
})
})
})