mirror of
https://github.com/supabase/supabase.git
synced 2026-10-19 16:19:10 +03:00
* chore: cleanup packages - Avoid circular imports - Export API-types as types - pg-format without depending on Node internal Buffer (not browser-compatible) - Avoid importing from barrel files in ui dir * chore: avoid barrel file imports in studio (#27771) * chore: avoid barrel file imports - Removes some unused imports - Avoids barrel file import for faster builds + less memory * add eslint rule * type fixes * delete layouts barrel * delete components/grid barrel file * delete components/grid/utils barrel file * delete components/grid/components/common barrel file * delete components/grid/components/editor barrel file * delete components/grid/components/formatter barrel file * delete components/grid/components/grid barrel file * delete components/grid/components/header/filter barrel file * remote components/grid/store barrel file * remove components/interfaces/Auth/Policies barrel file * delete components/interfaces/Settings/Logs barrel file * delete components/ui/CodeEditor barrel file * delete components/ui/Forms barrel file * delete components/ui/Shimmers barrel file * delete data/analytics barrel file * delete hooks barrel file * cleanup lib/common/fetch barrel file * final * barral files cleanup * global react-data-grid styles * remove console.log --------- Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com> * fix build --------- Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
99 lines
3.1 KiB
TypeScript
99 lines
3.1 KiB
TypeScript
import { screen } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import DatePickers from 'components/interfaces/Settings/Logs/Logs.DatePickers'
|
|
import { PREVIEWER_DATEPICKER_HELPERS } from 'components/interfaces/Settings/Logs/Logs.constants'
|
|
import dayjs from 'dayjs'
|
|
import timezone from 'dayjs/plugin/timezone'
|
|
import utc from 'dayjs/plugin/utc'
|
|
import { vi } from 'vitest'
|
|
import { render } from '../../helpers'
|
|
|
|
dayjs.extend(timezone)
|
|
dayjs.extend(utc)
|
|
|
|
const mockFn = vi.fn()
|
|
|
|
test('renders warning', async () => {
|
|
const from = dayjs().subtract(60, 'days')
|
|
const to = dayjs()
|
|
|
|
render(
|
|
<DatePickers
|
|
helpers={PREVIEWER_DATEPICKER_HELPERS}
|
|
to={to.toISOString()}
|
|
from={from.toISOString()}
|
|
onChange={mockFn}
|
|
/>
|
|
)
|
|
userEvent.click(await screen.findByText(RegExp(from.format('DD MMM'))))
|
|
await screen.findByText(/memory errors/)
|
|
await screen.findByText(RegExp(from.format('MMMM YYYY')))
|
|
})
|
|
|
|
test('renders dates in local time', async () => {
|
|
const from = dayjs().subtract(1, 'days')
|
|
const to = dayjs()
|
|
render(
|
|
<DatePickers
|
|
helpers={PREVIEWER_DATEPICKER_HELPERS}
|
|
to={to.toISOString()}
|
|
from={from.toISOString()}
|
|
onChange={mockFn}
|
|
/>
|
|
)
|
|
// renders time locally
|
|
userEvent.click(await screen.findByText(RegExp(from.format('DD MMM'))))
|
|
await screen.findByText(RegExp(from.format('MMMM YYYY')))
|
|
})
|
|
|
|
test('renders datepicker selected dates in local time', async () => {
|
|
const from = dayjs().date(25)
|
|
const to = dayjs().date(27)
|
|
render(
|
|
<DatePickers
|
|
helpers={PREVIEWER_DATEPICKER_HELPERS}
|
|
to={to.toISOString()}
|
|
from={from.toISOString()}
|
|
onChange={mockFn}
|
|
/>
|
|
)
|
|
// renders time locally
|
|
userEvent.click(await screen.findByText(RegExp(from.format('DD MMM'))))
|
|
// inputs with local time
|
|
await screen.findAllByDisplayValue(from.format('HH'))
|
|
await screen.findAllByDisplayValue(from.format('mm'))
|
|
await screen.findAllByDisplayValue(to.format('HH'))
|
|
await screen.findAllByDisplayValue(to.format('mm'))
|
|
// selected date should be in local time
|
|
await screen.findByText('25', { selector: "*[class*='--selected'" })
|
|
await screen.findByText('27', { selector: "*[class*='--range-end'" })
|
|
})
|
|
|
|
test('datepicker onChange will return ISO string of selected dates', async () => {
|
|
const mockFn = vi.fn()
|
|
render(<DatePickers helpers={PREVIEWER_DATEPICKER_HELPERS} to={''} from={''} onChange={mockFn} />)
|
|
// renders time locally
|
|
userEvent.click(await screen.findByText('Custom'))
|
|
// inputs with local time
|
|
const toHH = await screen.findByDisplayValue('23')
|
|
userEvent.clear(toHH)
|
|
userEvent.type(toHH, '12')
|
|
|
|
// Find and click on the date elements
|
|
const day20 = await screen.findByText('20')
|
|
userEvent.click(day20)
|
|
|
|
const day21 = await screen.findByText('21')
|
|
userEvent.click(day21)
|
|
|
|
userEvent.click(await screen.findByText('Apply'))
|
|
expect(mockFn).toBeCalled()
|
|
|
|
const call = mockFn.mock.calls[0][0]
|
|
|
|
expect(call).toMatchObject({
|
|
from: dayjs().date(20).hour(0).minute(0).second(0).millisecond(0).toISOString(),
|
|
to: dayjs().date(21).hour(12).minute(59).second(59).millisecond(0).toISOString(),
|
|
})
|
|
})
|