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 end-to-end automated testing. This uses 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 detox-cli  is installed globally.

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

Configure mock

Please add config.detox.ts file under src/totara/lib/  folder with the following content. Please change devOrgUrltestUsername  and testPassword  to credentials of the organization.

Code Block
languagejs
titleDetox configurations
linenumberstrue
const localConfig = {
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  apiUri: (host: string) => "http://127.0.0.1:8089/graphql",
  mobileApi: {
    persistentQuery: false
  },
  disableConsoleYellowBox: true,
  devOrgUrl: "REPLACE_ORGANIZATION_URL",
  testUsername: "REPLACE_USERNAME",
 
testPassword: "REPLACE_PASSWORD"
};

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 get-graphql-schema library. Here is the custom command to download and save schema to the e2e/graphql/schema.json  file:

...

To launch the GraphQL playground, where you can play with queries go to the URL: http://localhost127.0.0.1:8089/graphql/totara/mobile/api.php 

Build and run the tests

Prior to running tests with Detox you will need to integrate the Detox server configurations to the app. This will replace src/totara/lib/config.local.ts  with src/totara/lib/config.detox.ts  before it the test if built and run.  After the Detox test has complete, 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.

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:

...