Skip to content

Commit

Permalink
add simple test , refs UISER-148
Browse files Browse the repository at this point in the history
  • Loading branch information
CalamityC committed Sep 18, 2024
1 parent 5584705 commit 5a6e90a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/components/SimpleDateForm/SimpleDateForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { Form, Field } from 'react-final-form';
import { Button, Datepicker } from '@folio/stripes/components';
import { requiredValidator } from '@folio/stripes-erm-components';

const SimpleDateForm = () => {
return (
<Form
onSubmit={() => { }}
render={({ handleSubmit, submitting, pristine, invalid }) => (
<form onSubmit={handleSubmit}>
<Field
component={Datepicker}
id="ruleset-start-date"
label="Start Date"
name="startDate"
required
usePortal
validate={requiredValidator}
/>
<Button
disabled={submitting || invalid || pristine}
id="submit-button"
type="submit"
>
Submit
</Button>
</form>
)}
/>
);
};

export default SimpleDateForm;
23 changes: 23 additions & 0 deletions src/components/SimpleDateForm/SimpleDateForm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { renderWithIntl, Datepicker, Button } from '@folio/stripes-erm-testing';
import { waitFor, screen } from '@folio/jest-config-stripes/testing-library/react';
import SimpleDateForm from './SimpleDateForm';

describe('SimpleDateForm', () => {
test('Button should be enabled when date is valid', async () => {
renderWithIntl(<SimpleDateForm />);

await waitFor(async () => {
const dateInput = Datepicker({ id: 'ruleset-start-date' });
await dateInput.focus();
await dateInput.fillIn('01/30/2024');
await dateInput.blur();
screen.debug();
});

await Datepicker({ id: 'ruleset-start-date' }).has({ inputValue: '01/30/2024' });

await Button({ id: 'submit-button' }).has({ disabled: false });
// screen.debug();
});
});
1 change: 1 addition & 0 deletions src/components/SimpleDateForm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './SimpleDateForm';

0 comments on commit 5a6e90a

Please sign in to comment.