1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00
market/tests/unit/components/DateRange.test.tsx

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-05-07 08:03:30 +02:00
import React from 'react'
2020-06-30 14:19:27 +02:00
import { render, act } from '@testing-library/react'
2020-05-07 08:03:30 +02:00
import DateRangeWidget, {
getWidgetValue
} from '../../../src/components/atoms/FormWidgets/DateRangeWidget'
import { PublishFormSchema } from '../../../src/models/PublishForm'
describe('Date Range Widget', () => {
it('renders without crashing', () => {
act(() => {
const { container } = render(
<DateRangeWidget
schema={PublishFormSchema}
id="1"
autofocus={false}
disabled={false}
label="Date Range"
formContext={{}}
readonly={false}
value={'["2020-03-15T15:13:30Z", "2020-03-18T15:13:30Z"]'}
onBlur={() => {
/* */
}}
onFocus={() => {
/* */
}}
onChange={() => {
/* */
}}
options={{}}
required={false}
/>
)
expect(container.firstChild).toBeInTheDocument()
})
})
it('getWidgetValue returns a correctly encoded string', () => {
expect(
getWidgetValue(
new Date('2020-03-15T15:13:30.123Z'),
new Date('2020-03-18T15:13:30.456Z'),
false
)
).toEqual('["2020-03-15T15:13:30Z","2020-03-15T15:13:30Z"]')
expect(
getWidgetValue(
new Date('2020-03-15T15:13:30.123Z'),
new Date('2020-03-18T18:13:30.456Z'),
true
)
).toEqual('["2020-03-15T15:13:30Z","2020-03-18T18:13:30Z"]')
})
})