From 0399881d8fd1d749e181c47476c47fd81754f608 Mon Sep 17 00:00:00 2001 From: Github Date: Thu, 21 Nov 2024 09:41:20 +0100 Subject: [PATCH 1/4] Add unit testing guide and example tests --- README.md | 1 + tests/README.md | 134 ++++++++++++++++++++++ tests/ui/components/Button.tsx | 86 ++++++++++++++ tests/ui/components/CheckboxWithLabel.tsx | 78 +++++++++++++ 4 files changed, 299 insertions(+) create mode 100644 tests/ui/components/Button.tsx create mode 100644 tests/ui/components/CheckboxWithLabel.tsx diff --git a/README.md b/README.md index 6b75fbed1b2c..f75ac9558bc2 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,7 @@ Often times in order to write a unit test, you may need to mock data, a componen to help run our Unit tests. * To run the **Jest unit tests**: `npm run test` +* UI tests guidelines can be found [here](tests/README.md) ## Performance tests We use Reassure for monitoring performance regression. More detailed information can be found [here](tests/perf-test/README.md): diff --git a/tests/README.md b/tests/README.md index 890697d80719..b1d8081c22d9 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,3 +1,137 @@ +# Getting Started + +## What are UI Tests? + +UI (User Interface) tests validate the visible and interactive parts of an application. They ensure that components render correctly, handle user interactions as expected, and provide a reliable user experience. + +### Why are UI tests important? + +- Catch regressions early: Ensure that existing functionality remains intact after changes. +- Validate that the application works as intended: Confirm that the app behaves as expected from the user’s perspective. +- Increase confidence when refactoring code: When you need to change or improve the codebase, tests help verify that changes don’t break existing features. +- Improve user experience: UI tests ensure that components interact properly, making your app more robust and user-friendly. + +### Prerequisites + +- Familiarity with the React Native Testing Library [RNTL](https://callstack.github.io/react-native-testing-library/). +- Basic understanding of [Jest](https://jestjs.io/). + +## Best practices + +### When to Add UI Tests: + +1. **User Interactions**: +- Why: When the component responds to user actions, it's essential to verify that the interactions are correctly handled. +- Example: Testing if a button calls its `onPress` handler correctly. + +``` javascript +test('calls onPress when button is clicked', () => { + render(