-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
93403 add more tests and refactor with util
- Loading branch information
1 parent
52526b7
commit 8c62b85
Showing
3 changed files
with
168 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/applications/disability-benefits/all-claims/tests/unit.helpers.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import sinon from 'sinon'; | ||
import { render } from '@testing-library/react'; | ||
import { expect } from 'chai'; | ||
import { DefinitionTester } from '@department-of-veterans-affairs/platform-testing/schemaform-utils'; | ||
|
||
/** | ||
* Helper to verify a page submits or does not submit successfully based on given form data | ||
* | ||
* @param {object} schemaDefinition - page schema | ||
* @param {object} formData - form data for the page | ||
* @param {boolean} isSuccessfulSubmit - true if the submit should be successful, false otherwise | ||
*/ | ||
export function pageSubmitTest(schemaDefinition, formData, isSuccessfulSubmit) { | ||
const onSubmit = sinon.spy(); | ||
const { getByText } = render( | ||
<DefinitionTester | ||
schema={schemaDefinition?.schema} | ||
uiSchema={schemaDefinition?.uiSchema} | ||
data={formData} | ||
onSubmit={onSubmit} | ||
/>, | ||
); | ||
|
||
userEvent.click(getByText('Submit')); | ||
|
||
if (isSuccessfulSubmit) { | ||
expect(onSubmit.calledOnce).to.be.true; | ||
} else { | ||
expect(onSubmit.calledOnce).to.be.false; | ||
} | ||
} |