Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Initial date range widget
Browse files Browse the repository at this point in the history
  • Loading branch information
ilsanchez committed Oct 5, 2023
1 parent b1c6657 commit 217ff07
Show file tree
Hide file tree
Showing 9 changed files with 18,939 additions and 1,717 deletions.
8 changes: 7 additions & 1 deletion .nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
"statements": 90,
"lines": 90,
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["cypress/**/*.*", "**/*.d.ts", "**/*.cy.tsx", "**/*.cy.ts","src/utils"]
"exclude": [
"cypress/**/*.*",
"**/*.d.ts",
"**/*.cy.tsx",
"**/*.cy.ts",
"src/utils"
]
}
14 changes: 14 additions & 0 deletions __tests__/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,17 @@ export const getStringChoiceWidgetConfiguration = () => {
type: 'StringChoiceWidget' as const
}
}

export const getDateRangeWidgetConfiguration = () => ({
type: 'DateRangeWidget' as const,
help: null,
label: 'Date range',
name: 'date_range',
required: true,
details: {
defaultStart: '2023-10-12',
defaultEnd: '2023-10-24',
minStart: '2023-09-09',
maxEnd: '2024-03-20'
}
})
66 changes: 66 additions & 0 deletions cypress/component/DateRangeWidget.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { getDateRangeWidgetConfiguration } from '../../__tests__/factories'
import { DateRangeWidget } from '../../src'

const Form = ({
children,
handleSubmit
}: {
children: React.ReactNode
handleSubmit: (...args: any) => void
}) => {
return (
<form
onSubmit={ev => {
ev.preventDefault()
const formData = new FormData(ev.currentTarget)
handleSubmit([...formData.entries()])
}}
>
{children}
<button>submit</button>
</form>
)
}

describe('<DateRangeWidget />', () => {
afterEach(() => {
cy.clearLocalStorage()
})

it('test', () => {
const stubbedHandleSubmit = cy.stub().as('stubbedHandleSubmit')

cy.viewport(700, 600)

localStorage.setItem(
'formSelection',
JSON.stringify({
dataset: 'fake',
inputs: {
date_range_start: '2023-09-30',
date_range_end: '2025-02-10'
}
})
)

cy.mount(
<Form handleSubmit={stubbedHandleSubmit}>
<DateRangeWidget
configuration={getDateRangeWidgetConfiguration()}
constraints={['2023-10-05', '2023-10-11', '2023-10-30']}
error='Start date and End date are required'
/>
</Form>
)
// cy.get('[data-trigger="true"]').first().click()
// cy.findByText('15').click()
// cy.findByText('submit').trigger('pointerdown', {
// pointerId: 0
// })

// cy.get('@stubbedHandleSubmit').should('have.been.calledWith', [
// ['date_range_start', '2023-09-15'],
// ['date_range_end', '2025-02-10']
// ])
})
})
Loading

0 comments on commit 217ff07

Please sign in to comment.