diff --git a/src/views/create-dataset/CreateDataset.tsx b/src/views/create-dataset/CreateDataset.tsx index eecc93df1..b92765201 100644 --- a/src/views/create-dataset/CreateDataset.tsx +++ b/src/views/create-dataset/CreateDataset.tsx @@ -25,6 +25,8 @@ export function CreateDataset() { const { isLoading } = useDataset() const { t } = useTranslation('createDataset') const [submitting, setSubmitting] = useState(false) + const [submitStatus, setSubmitStatus] = useState(false) + useEffect(() => { setIsLoading(isLoading) }, [isLoading]) @@ -42,17 +44,20 @@ export function CreateDataset() { setState({ ...state, [e.target.id]: value }) } + // TODO: Connect to API when ready const handleCreateDatasetSubmit = (event: FormEvent) => { setSubmitting(true) event.preventDefault() setTimeout(() => { setSubmitting(false) console.log('Form Submitted!') + setSubmitStatus(true) }, 3000) console.log(state) // TODO: Callback for form submission should be here. } + // TODO: Probably replace this with a FormSkeleton or remove entirely if (isLoading) { return } @@ -66,11 +71,13 @@ export function CreateDataset() { {submitting &&
Submtting Form...
}
+ {submitStatus &&
Form Submitted!
} {t('datasetForm.title')} */} - - + diff --git a/tests/component/views/create-dataset/CreateDataset.spec.tsx b/tests/component/views/create-dataset/CreateDataset.spec.tsx new file mode 100644 index 000000000..29c3c4101 --- /dev/null +++ b/tests/component/views/create-dataset/CreateDataset.spec.tsx @@ -0,0 +1,24 @@ +import { CreateDataset } from '../../../../src/views/create-dataset/CreateDataset' + +describe('Form component', () => { + it('should render all form fields', () => { + cy.customMount() + cy.get('[data-cy=datasetFormInputTitle]').should('be.visible') + cy.get('[data-cy=datasetFormSubmit]').should('be.visible') + cy.get('[data-cy=datasetFormCancel]').should('be.visible') + }) + + it('should submit the form with correct values', () => { + cy.customMount() + + cy.get('[data-cy=datasetFormInputTitle]').type('Test Dataset Title') + + cy.get('[data-cy=datasetFormSubmit]').click() + + // Wait for the form submission to complete (adjust the timeout as needed) + cy.wait(4000) + + // Assert that the form was successfully submitted + cy.contains('Form Submitted!') + }) +})