Files
supabase/apps/studio/tests/components/Editor/SpreadsheetImport.utils.test.ts
Jordi Enric 764d10986d vitest & msw integration (#26303)
* 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

* Replace jest with vitest

* Rename all *.test.js to *.test.ts

* Configure vitest to work with jsx

* fix vitest issues, fix tests, skip broken tests, add msw, add next-router-mock

* uncomment file

* add tests for msw and nrm

* Fix failing tests

* fix tests in RowEditor

* fix datepicker tests

* fix type errors and comment out tests that need some refactoring

* leave 1 test so test script works

* rm clog and aaaaa

* rename script

* move msw to studio

* add pckg json which i forgot in last commit

* rm consolelog

* move vitest ui dep

* Move next-router-mock to studio.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: TzeYiing <ty@tzeyiing.com>
Co-authored-by: Kamil Ogórek <kamil.ogorek@gmail.com>
Co-authored-by: Terry Sutton <saltcod@gmail.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2024-05-29 17:31:20 +02:00

67 lines
2.8 KiB
TypeScript

import { inferColumnType } from 'components/interfaces/TableGridEditor/SidePanelEditor/SpreadsheetImport/SpreadsheetImport.utils'
describe('SpreadsheedImport.utils: inferColumnType', () => {
test('should default column type to text if no rows to infer from', () => {
const mockData: any[] = []
const type = inferColumnType('id', mockData)
expect(type).toBe('text')
})
test('should default column type to text if the first row has no data to infer from', () => {
const mockData = [{ name: 'bob', age: '42' }]
const type = inferColumnType('id', mockData)
expect(type).toBe('text')
})
test('should default column type to text if the first row data value is null', () => {
const mockData = [{ id: 'null', name: 'bob', age: '42' }]
const type = inferColumnType('id', mockData)
expect(type).toBe('text')
})
test('should infer integer types correctly', () => {
const mockData = [{ name: 'bob', age: '42' }]
const type = inferColumnType('age', mockData)
expect(type).toBe('int8')
})
test('should infer float types correctly', () => {
const mockData = [{ name: 'bob', height: '161.72' }]
const type = inferColumnType('height', mockData)
expect(type).toBe('float8')
})
test('should infer boolean types correctly', () => {
const mockData1 = [{ name: 'bob', height: '161.72', isWorking: 'true' }]
const type1 = inferColumnType('isWorking', mockData1)
expect(type1).toBe('bool')
const mockData2 = [{ name: 'bob', height: '161.72', isRetired: 'false' }]
const type2 = inferColumnType('isRetired', mockData2)
expect(type2).toBe('bool')
})
test('should infer boolean type for a supposed boolean column if one of the rows has a null value', () => {
const mockData3 = [
{ name: 'bob', height: '161.72', isRetired: 'false' },
{ name: 'bob', height: '161.72', isRetired: 'true' },
{ name: 'bob', height: '161.72', isRetired: null },
]
const type3 = inferColumnType('isRetired', mockData3)
expect(type3).toBe('bool')
})
test('should infer objects as jsonb types correctly', () => {
const mockData = [{ name: 'bob', metadata: '{}' }]
const type = inferColumnType('metadata', mockData)
expect(type).toBe('jsonb')
})
test('should infer date type correctly', () => {
const mockData4 = [
{ event: 'christmas', date: '2022-12-25 17:45:23 UTC' },
{ event: 'christmas', date: '2022-12-25' },
{ event: 'christmas', date: '2022-12-25T12:03:40Z' },
{ event: 'christmas', date: new Date() },
{ event: 'christmas', date: new Date().toISOString() },
{ event: 'christmas', date: 1410715640579 },
{ event: 'christmas', date: '25 Dec 2022' },
{ event: 'christmas', date: 'Dec 25 2022' },
]
const type4 = inferColumnType('date', mockData4)
expect(type4).toBe('timestamptz')
})
})