diff --git a/views/cypress/README.md b/views/cypress/README.md deleted file mode 100644 index fe12a12e..00000000 --- a/views/cypress/README.md +++ /dev/null @@ -1,117 +0,0 @@ -# E2E testing - -Please refer to the readme file placed at `tao/views/cypress` for generic info about E2E. This file is aimed at describing the E2E for the extension `ltiDeliveryProvider`. - -Development of end-to-end tests in TAO is based on the principle of storing the test specs in each relevant extension, while the common and shared features with respect to TAO are stored in `tao-core`. The base engine as well as the very common features are supplied through the dependency `@oat-sa/e2e-runner`. - -The local structure, in `tao-core` is a reduced form of the classic Cypress project structure: - -
-tao
-|-- views
-  |-- cypress.json        # project config
-  |-- cypress/            #
-    |-- envs/             # environment configs
-    |-- fixtures/         # static data used in tests
-    |-- tests/            # root folder of the tests
-    |-- plugins/          # folder for the plugins
-  |  -- support/          # support commands, imports, global setup
-
- -The env files are to be placed in `tao/views/cypress/env`. - -The plugins and command must be stored in respectively `tao/views/cypress/plugins` and `tao/views/cypress/support`. - -> **Note:** For the time being, there is no way to store plugins or commands in each extension. If they are generic enough, say not related to any specific extension, they can be placed in `tao-core`. -> -> Otherwise, the only way to have shared feature for a specific extension is to use local helpers. Often you will see a `utils` folder aside the tests, this is where such helpers will take place. Then can be imported the usual manner thanks to the ES module management. - -## Configuration - -Because tests may be run against various envs (local, demo, staging, etc), we need to have multiple env files. They are stored in `cypress/envs/`, and loaded into the main config according to the key `env.configFile` defined in the `cypress.json`. - -Create `envs/env*.json` file and set it in the `tao/views/cypress.json`: - -```json -{ - "env": { - "configFile": "cypress/envs/env-local.json" - } -} -``` - -> **Note:** The base configuration as described in the extensions `tao-core` and `taoQtiTest` should be done first. -> -> The E2E test from `ltiDeliveryProvider` are relying on `taoQtiTest`, so this extension needs to be properly setup for E2E. - -For `ltiDeliveryProvider`, the following additional config can be added in any `env*.json` file: -```json -{ - "ltiLocale": "en-US", - "ltiKey": "e2e_key", - "ltiSecret": "2e2_secret", - "ltiDeliveryIds": { - "basicLinearTest": "lti_key" - } -} -``` - -The sample file `ltiDeliveryProvider/views/cypress/env/env.sample` contains an example. - -### Environment setup -In order to have the E2E tests working properly, it is needed to follow these instructions: -- The E2E instruction must have been followed for the extension `taoQtiTest`. -- A specific LTI provider must be created to give access to the tests, the ltiKey usually have the name `e2e_key` -- The env file must contain the key and secret for the LTI provider (`ltiKey` and `ltiSecret`). -- The env file must contain the `ltiDeliveryIds` property, filled with the list of LTI keys for each delivery. The key is the URL part that comes after the launch URL. For example, with the launch URL `http://tao.local/ltiDeliveryProvider/DeliveryTool/launch/THIS_IS_THE_LTI_KEY`, the key to extract is `THIS_IS_THE_LTI_KEY`. - -## Commands - -[Commands](https://docs.cypress.io/api/cypress-api/custom-commands.html) are a key part of Cypress. For now commands can be registered to `Cypress.Commands` in `tao/views/cypress/support/commands` file. -There's no ability to register them within the extensions yet. - -> When registering a local or global command, take care to avoid name collisions with any command you might have imported. - -> **Note:** For the time being, there is no way to store commands in each extension. If they are generic enough, say not related to any specific extension, they can be placed in `tao-core`. -> -> Otherwise, the only way to have shared commands for a specific extension is to use local helpers instead, so not a command actually. Often you will see a `utils` folder aside the tests, this is where such helpers will take place. Then can be imported the usual manner thanks to the ES module management. - -## Plugins - -Plugins can be created in `tao/views/cypress/plugins` directory. -Some plugins also register commands. You can import these files (for their side effects) in the `tao/views/cypress/support/index.js`. - -> **Note:** For the time being, there is no way to store plugins in each extension. If they are generic enough, say not related to any specific extension, they can be placed in `tao-core`. -> -> Otherwise, the only way to have shared features for a specific extension is to use local helpers instead, so not a plugin actually. Often you will see a `utils` folder aside the tests, this is where such helpers will take place. Then can be imported the usual manner thanks to the ES module management. - - -## Fixtures - -Any generic data needed in tests (and not hard-coded) should be placed in `tao/views/cypress/fixtures/`. Can be JSON, JavaScript, zip files, whatever is needed. - -> **Note:** For the time being, there is no way to store fixture in each extension. If they are generic enough, say not related to any specific extension, they can be placed in `tao-core`. -> -> Otherwise, the only way to have shared fixture for a specific extension is to use local helpers instead. Often you will see a `utils` folder aside the tests, this is where such helpers will take place. Then can be imported the usual manner thanks to the ES module management. -> If the fixture is a data packages that doesn't need to get directly accessed from inside the test, it can be placed in the `ltiDeliveryProvider/cypress/fixtures` folder. This is how the test packages to import in TAO are supplied in `taoQtiTest`. - -## How to run the tests - -To run the tests there's a single entry point in tao core. - -In your tao installation folder: -* `cd tao/views` -* `npm install` -* `npm run cy:open` - to open cypress UI and browser - - or - - `npm run cy:run` - to run the tests headless - -## How to create your tests - -Add .spec files to the `ltiDeliveryProvider/views/cypress/tests` folder. - -> Feel free to use common commands from the tao core (located in `tao/views/cypress/support`) - -> For any local feature that needs to be shared, you may create a `utils` folder and add some regular JavaScript module. There is already a bunch of them you can use in `ltiDeliveryProvider/views/cypress/tests/utils`. diff --git a/views/cypress/env/env.sample b/views/cypress/env/env.sample deleted file mode 100644 index 023c683b..00000000 --- a/views/cypress/env/env.sample +++ /dev/null @@ -1,8 +0,0 @@ -{ - "ltiLocale": "en-US", - "ltiKey": "e2e_key", - "ltiSecret": "2e2_secret", - "ltiDeliveryIds": { - "basicLinearTest": "lti_key" - } -} diff --git a/views/cypress/tests/delivery/basic-linear-test.spec.js b/views/cypress/tests/delivery/basic-linear-test.spec.js deleted file mode 100644 index 49b5d2b3..00000000 --- a/views/cypress/tests/delivery/basic-linear-test.spec.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; under version 2 - * of the License (non-upgradable). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (c) 2021 Open Assessment Technologies SA ; - */ - -/** - * Note: this test requires the following: - * - the extension `oat-sa/extension-tao-ltideliveryprovider` is installed - * - the test `taoQtiTest/views/cypress/fixtures/testPackages/basic-linear-test.zip` is imported - * - the test is published - * - a LTI provider is created - * - the LTI credentials are supplied through the cypress env file from the properties ltiKey and ltiSecret - * - the LTI launch key is supplied through the cypress env file from the property ltiDeliveryIds.basicLinearTest - */ - -import { launchLtiDelivery1p0, checkLtiReturnPage } from '../utils/lti.js' -import { basicLinearTestSpecs } from '../../../../../taoQtiTest/views/cypress/tests/delivery/shared/basic-linear-test.js'; - -describe('LTI launch of the basic linear test with 4 items', () => { - const deliveryKey = 'basicLinearTest'; - - describe('LTI launch', () => { - it('successfully launches', () => { - launchLtiDelivery1p0(deliveryKey); - }); - }); - - describe('Basic linear test with 4 items', () => { - basicLinearTestSpecs(); - }); - - describe('LTI end', () => { - it('redirects the page', () => { - checkLtiReturnPage(); - }); - }); -}); diff --git a/views/cypress/tests/delivery/basic-nonlinear-test.spec.js b/views/cypress/tests/delivery/basic-nonlinear-test.spec.js deleted file mode 100644 index fcb9a779..00000000 --- a/views/cypress/tests/delivery/basic-nonlinear-test.spec.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; under version 2 - * of the License (non-upgradable). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (c) 2021 Open Assessment Technologies SA ; - */ - -/** - * Note: this test requires the following: - * - the extension `oat-sa/extension-tao-ltideliveryprovider` is installed - * - the test `taoQtiTest/views/cypress/fixtures/testPackages/basic-nonlinear-test.zip` (extension `oat-sa/extension-tao-testqti`) - * - the test is published - * - a LTI provider is created - * - the LTI credentials are supplied through the cypress env file from the properties ltiKey and ltiSecret - * - the LTI launch key is supplied through the cypress env file from the property ltiDeliveryIds.basicNonLinearTest - */ - -import { launchLtiDelivery1p0, checkLtiReturnPage } from '../utils/lti.js'; -import { - basicNonLinearFirstLaunchSpecs, - basicNonLinearSecondLaunchSpecs -} from '../../../../../taoQtiTest/views/cypress/tests/delivery/shared/basic-nonlinear-test.js'; - -describe('Basic non-linear test navigation (LTI launch)', () => { - const deliveryKey = 'basicNonLinearTest'; - - describe('Next/Previous/End navigation', () => { - before(() => { - launchLtiDelivery1p0(deliveryKey); - }); - after(() => { - checkLtiReturnPage(); - }); - - basicNonLinearFirstLaunchSpecs(); - }); - - describe('Skip/Skip-and-end navigation', () => { - before(() => { - launchLtiDelivery1p0(deliveryKey); - }); - after(() => { - checkLtiReturnPage(); - }); - - basicNonLinearSecondLaunchSpecs(); - }); -}); diff --git a/views/cypress/tests/delivery/student-tool-test.spec.js b/views/cypress/tests/delivery/student-tool-test.spec.js deleted file mode 100644 index 2874a7dd..00000000 --- a/views/cypress/tests/delivery/student-tool-test.spec.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; under version 2 - * of the License (non-upgradable). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (c) 2021 Open Assessment Technologies SA ; - */ - -import {studentToolTest} from '../../../../../taoQtiTest/views/cypress/tests/delivery/shared/student-tool-test.js'; -import { launchLtiDelivery1p0 } from '../utils/lti.js'; - -describe('Basic behavior of student tools', () => { - before(() => { - launchLtiDelivery1p0('studentToolTest'); - }); - studentToolTest(); -}); diff --git a/views/cypress/tests/delivery/warning-messages-test.spec.js b/views/cypress/tests/delivery/warning-messages-test.spec.js deleted file mode 100644 index aee89ef1..00000000 --- a/views/cypress/tests/delivery/warning-messages-test.spec.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; under version 2 - * of the License (non-upgradable). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (c) 2021 Open Assessment Technologies SA ; - */ - -/** - * Note: this test requires the following: - * - the extension `oat-sa/extension-tao-ltideliveryprovider` is installed - * - the test `taoQtiTest/views/cypress/fixtures/testPackages/warning-messages-test.zip` (extension `oat-sa/extension-tao-testqti`) - * - the test is published - * - a LTI provider is created - * - the LTI credentials are supplied through the cypress env file from the properties ltiKey and ltiSecret - * - the LTI launch key is supplied through the cypress env file from the property ltiDeliveryIds.warningMessagesTest - */ - -import { launchLtiDelivery1p0, checkLtiReturnPage } from '../utils/lti.js'; -import { - warningMessagesFirstLaunchSpecs, - warningMessagesSecondLaunchSpecs -} from '../../../../../taoQtiTest/views/cypress/tests/delivery/shared/warning-messages-test.js'; - -describe('Test warning messages', () => { - const deliveryKey = 'warningMessagesTest'; - - describe('Test warning messages (part 1)', () => { - before(() => { - launchLtiDelivery1p0(deliveryKey); - }); - after(() => { - checkLtiReturnPage(); - }); - - warningMessagesFirstLaunchSpecs(); - }); - - describe('Test warning messages (part 2)', () => { - before(() => { - launchLtiDelivery1p0(deliveryKey); - }); - after(() => { - checkLtiReturnPage(); - }); - - warningMessagesSecondLaunchSpecs(); - }); -}); diff --git a/views/cypress/tests/utils/lti.js b/views/cypress/tests/utils/lti.js deleted file mode 100644 index a0e4d5cf..00000000 --- a/views/cypress/tests/utils/lti.js +++ /dev/null @@ -1,96 +0,0 @@ -/** - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; under version 2 - * of the License (non-upgradable). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (c) 2021 Open Assessment Technologies SA ; - */ - -import { getFullUrl } from '../../../../../tao/views/cypress/utils/helpers.js'; -import urls from './urls.js'; - -/** - * List the default values for some LTI parameters - * @type {Object} - */ -const ltiDefault = { - ltiRole: 'Learner', - ltiLocale: 'en-US', - ltiBaseLaunchUrl: urls.launch, - ltiReturnUrl: urls.thankYou, -}; - -/** - * Gets the value for a LTI parameter. It will come either from: - * - the supplied options - * - the Cypress env config - * - the ltiDefault - * @param {String} name - The name of the parameter for which get the value - * @param {Object} [options] - A list of options in which the value may be defined - * @returns {*} - */ -export function getLtiParameter(name, options = null) { - if (options && options[name]) { - return options[name]; - } - return Cypress.env(name) || ltiDefault[name]; -} - -/** - * Gets the LTI BaseLaunch URL - * @param {Object} [options] - A list of options in which the value may be defined - * @returns {String} - */ -export function getLtiBaseLaunchUrl(options = null) { - return getFullUrl(getLtiParameter('ltiBaseLaunchUrl', options), '/'); -} - -/** - * Gets the LTI Return URL - * @param {Object} [options] - A list of options in which the value may be defined - * @returns {String} - */ -export function getLtiReturnUrl(options = null) { - return getFullUrl(getLtiParameter('ltiReturnUrl', options)); -} - -/** - * Launches a delivery by LTI 1.1 request, using the method appropriate to the environment - * @param {String} deliveryKey - the key in the env.deliveryIds object for accessing the deliveryId - * @param {Object} [options] - * @param {String} [options.ltiRole] - default is 'Learner' - * @param {String} [options.ltiLocale] - default comes from global cypress config - * @param {String} [options.ltiBaseLaunchUrl] - default comes from global cypress config, or from the `urls` collection - * @param {String} [options.ltiReturnUrl] - default comes from global cypress config, or from the `urls` collection - */ -export function launchLtiDelivery1p0(deliveryKey, options) { - cy.ltiLaunch({ - ltiVersion: '1p0', - ltiKey: Cypress.env('ltiKey'), - ltiSecret: Cypress.env('ltiSecret'), - ltiResourceId: Cypress.env('ltiDeliveryIds')[deliveryKey], - ltiBaseLaunchUrl: getLtiBaseLaunchUrl(options), - ltiReturnUrl: getLtiReturnUrl(options), - ltiLocale: getLtiParameter('ltiLocale', options), - ltiRole: getLtiParameter('ltiRole', options) - }); -} - -/** - * Checks the return page at the end of the LTI session - */ -export function checkLtiReturnPage() { - cy.location().should(location => { - expect(`${location.origin}${location.pathname}`).to.equal(getLtiReturnUrl()); - }); -} diff --git a/views/cypress/tests/utils/urls.js b/views/cypress/tests/utils/urls.js deleted file mode 100644 index 8a71e0ab..00000000 --- a/views/cypress/tests/utils/urls.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; under version 2 - * of the License (non-upgradable). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright (c) 2021 Open Assessment Technologies SA ; - */ - -/** - * A list of well known URLS in the context of the delivery - * @type {Object} - */ -export default { - launch: "ltiDeliveryProvider/DeliveryTool/launch", - thankYou: "ltiDeliveryProvider/DeliveryRunner/thankYou", -};