-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add jest + react testing library for unit testing (#802)
* add testing libraries * add test bypass for axios * first test case * fix jest dom import * cleanup babel config * remove babel config * add window.env setup * update linter rules * make eslint happy * add mock test calling * wrap up test cases * remove babel present-env * change no op function * add babel preset-env back
- Loading branch information
Showing
5 changed files
with
1,302 additions
and
10 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
50 changes: 50 additions & 0 deletions
50
src/components/CTEPubListScreen/components/NewEPubModal.test.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,50 @@ | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { LanguageConstants } from 'components/CTPlayer'; | ||
import NewEPubModal from './NewEPubModal'; | ||
|
||
const mockSelect = jest.fn(); | ||
jest.mock("../../../layout/CTForm/Select/index.js", () => (props) => { | ||
mockSelect(props); | ||
return <div />; | ||
}) | ||
|
||
describe('New EPubModal', () => { | ||
const baseProps = { | ||
open: true, | ||
onClose: jest.fn(), | ||
onCreate: jest.fn(), | ||
defaultTitle: "" | ||
} | ||
test('it renders with no languages', () => { | ||
render(<NewEPubModal {...baseProps} />); | ||
|
||
expect(screen.getByText("CREATE NEW I-Note")).toBeVisible(); | ||
expect(screen.getByText("I-Note Title")).toBeVisible(); | ||
|
||
expect(mockSelect).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
options: [] | ||
}) | ||
); | ||
}); | ||
|
||
test('it renders given list of languages and uniquely', () => { | ||
const languages = [ | ||
LanguageConstants.English, | ||
LanguageConstants.English, | ||
LanguageConstants.French, | ||
LanguageConstants.Spanish, | ||
LanguageConstants.French | ||
] | ||
render(<NewEPubModal languages={languages} {...baseProps} />); | ||
|
||
expect(mockSelect).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
options: [ | ||
{"text": "English", "value": LanguageConstants.English}, | ||
{"text": "French", "value": LanguageConstants.French}, | ||
{"text": "Spanish", "value": LanguageConstants.Spanish}] | ||
}) | ||
); | ||
}); | ||
}); |
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,16 @@ | ||
// react-testing-library renders your components to document.body, | ||
// this adds jest-dom's custom assertions | ||
// https://create-react-app.dev/docs/running-tests/ | ||
import '@testing-library/jest-dom'; | ||
|
||
// Similar to config.template but we put in placeholders for required fields | ||
window.env={} | ||
window.env.TEST_SIGN_IN='true' | ||
// window.env.REACT_APP_FRONTEND_COMMIT_ENDPOINT="$REACT_APP_FRONTEND_COMMIT_ENDPOINT" | ||
window.env.AUTH0_CLIENT_ID="" | ||
window.env.AUTH0_DOMAIN="" | ||
window.env.CILOGON_CLIENT_ID="" | ||
// window.env.APPLICATION_INSIGHTS_KEY="" | ||
// window.env.BRANCH="" | ||
// window.env.BUILDNUMBER="" | ||
// window.env.GITSHA1="" |
Oops, something went wrong.