Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space TDDM and version 1

For the Totara Mobile app, we use Detox for implementing Detox is used to implement end-to-end automated testing. This uses 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:

Install Detox command-line tools

To install the Detox command-line tool you will need to ensure ensure detox-cli  is installed globally.

Code Block
languagebash
titleDetox Installation
npm install -g detox-cli

Configure

...

The project should have config.detox.ts file under  located in src/totara/lib/  folder with . This is required for the automated tests to run successfully.

config.detox.ts must contain the following content.:

Code Block
languagejs
titleDetox configurations
linenumberstrue
const localConfig = {
  mobileApi: {
    persistentQuery: false
  },
  disableConsoleYellowBox: true
};

export default localConfig;

...

Detox automated testing starts the node server for mocking API requests. It downloads GraphQL schema from the server after app installation using using the get-graphql-schema library. Here is the custom command to download and save the schema to the e2e/graphql/schema.json  file:

Code Block
languagebash
titleGraphQL Schema Setup
npmyarn run mock:schema:setup

For testing a Start the mock server , it can be started with default data using the following command:

Code Block
languagebash
titleStart Mock Server
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  

...

Prior to running tests with Detox, you will need to integrate the Detox server configurations to configuration with the app. 

Use the following command to make configuration changes and execute Detox tests:

Code Block
languagebash
titleExecute automate tests
yarn detox:run

This script will replace replace src/totara/lib/config.local.ts   with with src/totara/lib/config.detox.ts   (before it the test if built and starts to run).  

After the Detox test has completebeen completed, it will replace the  src/totara/lib/config.local.ts   with the original file. Use the following command to make configuration changes and execute Detox tests:

Code Block
languagebash
titleExecute automate tests
npm run detox:run

 

Troubleshooting

Below you can find some common troubleshooting guidance.

...

Code Block
languagebash
titleClear app all cache data
npm runyarn clear:all