Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Add Jest testing framework and some tests #43

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

nf679
Copy link
Collaborator

@nf679 nf679 commented Nov 27, 2024

  • Information on how to run the tests can be found in README.md in the jest-test-framework branch.
  • __mocks__/react-bootstrap-notify.js is mocking the useNotifications function as we don't want to actually send notifications when testing.
  • babel.config.js is setting some presets to get the tests working properly.
  • cssTransformer.js is processing CSS files during testing to fix some issues with the tests throwing errors.
  • jest.config.js is setting some configuration settings for jest.
  • jest.setup.js is making sure all tests can find the jest testing library.
  • We are currently using version 29.7.0 for Jest.
  • When the tests run they create snapshot files with the .snap extension - snapshot tests are used to check the UI doesn't change unexpectedly. Jest renders a UI component, takes a snapshot, then compares it to the reference snapshot stored alongside the test and will fail if they don't match.

Finished tests:

  • src/Components/Home.test.js
  • src/Components/NotFound.test.js
  • src/Components/utils.test.js
  • src/Components/Project/InvitationListItems.test.js
  • src/Components/Project/StatusIcon.test.js

Future tests to add:

  • src/Components/AllProjects/List.js
  • src/Components/Consortium/Detail.js
  • src/Components/Consortium/List.js
  • src/Components/Consortium/OverviewPane.js
  • src/Components/Consortium/ProjectSummaryPane.js
  • src/Components/Consortium/ProjectsPane.js
  • src/Components/Consortium/QuotaProgressBar.js
  • src/Components/Project/CardItems.js
  • src/Components/Project/CollaboratorsLink.js
  • src/Components/Project/CollaboratorsListItem.js
  • src/Components/Project/Detail.js
  • src/Components/Project/List.js
  • src/Components/Project/MetaCard.js
  • src/Components/Project/OverviewPane.js
  • src/Components/Project/ProjectCreateButton.js
  • src/Components/Project/ProjectJoinButton.js
  • src/Components/Project/Requirement.js
  • src/Components/Project/RequirementApproveButton.js
  • src/Components/Project/RequirementDeleteButton.js
  • src/Components/Project/RequirementEditButton.js
  • src/Components/Project/RequirementsTable.js
  • src/Components/Project/ServiceCard.js
  • src/Components/Project/ServiceCreateButton.js
  • src/Components/Project/ServicesPane.js
  • src/Components/Project/actions.js
  • src/Components/App.js
  • src/Components/Navbar.js
  • src/Components/index.js

Tips for writing tests:

  • Start by looking at the code for the component - know where on the screen you see it (render the UI and take a look), know the expected behaviour.
  • Pick out some text or a component you can see on the screen and start by testing that.
  • Build up the tests until you are testing every component and every possible value for them (or as much as possible)
  • Check the coverage of tests to see which lines are uncovered.

nf679 and others added 17 commits July 10, 2024 14:56
Created the tests for StatusIcon.js.
This checks that 'StatusIcon's and 'StatusIconWithText' are correctly rendered for the statuses REQUESTED, REJECTED, APPROVED, AWAITING_PROVISIONING, PROVISIONED, DECOMMISSIONED and UNKNOWN. (UNKNOWN and REQUESTED only apply to icons.)
Wrote the test for utils.js, and corrected an intentional bug to make the text field mutable. Added css support to Jest.
Removed an unnecessary comment from utils.js.

Set up the test for NotFound.test.js, and updated NotFound.js from class to className to reflect the latest version of React.
Changed NotFound.test.js Line 9 Col 34 out of placeholder text so that test succeeds.
Utils.test.js and NotFound.test.js updated so tests succeed
Add NotFound.test.js to jest-test-framework branch
@nf679 nf679 changed the title Add Jest testing framework and some tests Draft: Add Jest testing framework and some tests Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants