Mobile app automated testing
Detox is used to implement end-to-end automated testing. Detox utilises apollo-server-express
 to implement the mock data for the API responses.
Detox setup
Below you can find the guidance you need to setup Detox. You will need to install the following:
- NodeÂ
12.0.0
 or above - AppleSimulatorUtilsÂ
Install Detox command-line tools
To install the Detox command-line tool you will need to ensure detox-cli
 is installed globally.
npm install -g detox-cli
Configure
The project should have config.detox.ts
located in src/totara/lib/
. This is required for the automated tests to run successfully.
config.detox.ts
must contain the following content:
const localConfig = { mobileApi: { persistentQuery: false }, disableConsoleYellowBox: true }; export default localConfig;
Mock server
Detox automated testing starts the node server for mocking API requests. It downloads GraphQL schema from the server after app installation using the get-graphql-schema
library. Here is the custom command to download and save the schema to the e2e/graphql/schema.json
 file:
yarn mock:schema:setup
Start the mock server with default data using the following command:
node server
To launch the GraphQL playground, where you can play with queries, go to the URL:Â
http://127.0.0.1:8089/totara/mobile/api.php
Â
Build and run the tests
Prior to running tests with Detox, you will need to integrate the Detox server configuration with the app.Â
Use the following command to make configuration changes and execute Detox tests:
yarn detox:run
This script will replace src/totara/lib/config.local.ts with src/totara/lib/config.detox.ts (before the test starts to run). Â
After the Detox test has been completed, it will replace src/totara/lib/config.local.ts with the original file.Â
Troubleshooting
Below you can find some common troubleshooting guidance.
Cache data
In case you run into dependency issues, you can try running the following command to clear all the cache, modules & pods then reinstall:
yarn clear:all