From 412b28368eda7dc1b1eeacd944fb421d52790108 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Wed, 30 Nov 2022 12:48:29 +0100 Subject: [PATCH] Test for the settings-rollback location (#5065) --- .github/workflows/functional_tests.yaml | 8 +-- .github/workflows/wasm.yaml | 8 +-- scripts/addon/generate_all_tests.py | 34 ++++++++++ .../tutorial_01/manifest.json | 36 ++++++++++ tests/functional/servers/addon.js | 4 +- tests/functional/testAddons.js | 65 +++++++++++++++++++ 6 files changed, 139 insertions(+), 16 deletions(-) create mode 100755 scripts/addon/generate_all_tests.py create mode 100644 tests/functional/addons/05_settings_rollback/tutorial_01/manifest.json diff --git a/.github/workflows/functional_tests.yaml b/.github/workflows/functional_tests.yaml index 821b897f86..d4a9211332 100644 --- a/.github/workflows/functional_tests.yaml +++ b/.github/workflows/functional_tests.yaml @@ -130,13 +130,7 @@ jobs: - name: Build addons shell: bash - if: steps.cache-build.outputs.cache-hit != 'true' - run: | - for i in tests/functional/addons/*; do - if ! [ -f $i/manifest.json ]; then - ./scripts/addon/generate_all.py -p $i - fi - done + run: ./scripts/addon/generate_all_tests.py - name: Running ${{matrix.test.name}} Tests id: runTests diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index 46ba7d6b73..e5c75e67ac 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -128,13 +128,7 @@ jobs: - name: Build addons shell: bash - if: steps.cache-build.outputs.cache-hit != 'true' - run: | - for i in tests/functional/addons/*; do - if ! [ -f $i/manifest.json ]; then - ./scripts/addon/generate_all.py -p $i -q /opt/$QTVERSION/gcc_64/bin - fi - done + run: ./scripts/addon/generate_all_tests.py -q /opt/$QTVERSION/gcc_64/bin - name: Running ${{matrix.test.name}} Tests id: runTests diff --git a/scripts/addon/generate_all_tests.py b/scripts/addon/generate_all_tests.py new file mode 100755 index 0000000000..798a3a0c32 --- /dev/null +++ b/scripts/addon/generate_all_tests.py @@ -0,0 +1,34 @@ +#! /usr/bin/env python3 +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import argparse +import os +import subprocess +import sys + +parser = argparse.ArgumentParser(description="Generate an addon package") +parser.add_argument( + "-q", + "--qt_path", + default=None, + dest="qtpath", + help="The QT binary path. If not set, we try to guess.", +) +args = parser.parse_args() + +generateall_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "generate_all.py") +addons_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "tests", "functional", "addons") + +for file in os.listdir(addons_path): + manifest_path = os.path.join(addons_path, file, "manifest.json") + if os.path.exists(manifest_path): + print(f"Ignoring path {file} because the manifest already exists.") + continue + + build_cmd = [sys.executable, generateall_path, "-p", os.path.join(addons_path, file)] + if args.qtpath: + build_cmd.append("-q") + build_cmd.append(args.qtpath) + subprocess.call(build_cmd) diff --git a/tests/functional/addons/05_settings_rollback/tutorial_01/manifest.json b/tests/functional/addons/05_settings_rollback/tutorial_01/manifest.json new file mode 100644 index 0000000000..d1ebd3d608 --- /dev/null +++ b/tests/functional/addons/05_settings_rollback/tutorial_01/manifest.json @@ -0,0 +1,36 @@ +{ + "api_version": "0.1", + "id": "tutorial_01", + "name": "Tutorial: 01", + "type": "tutorial", + "tutorial": { + "id": "01", + "highlighted": true, + "settings_rollback_needed": true, + "image": "qrc:/addons/tutorial_01/image.svg", + "title": "Tutorial 01", + "subtitle": "Tutorial 01 sub", + "completion_message": "You’ve successfully completed tutorial 01", + "steps": [ + { + "id": "mainScreen", + "element": "serverListButton-btn", + "tooltip": "Select your location", + "before": [{ + "op": "vpn_off" + },{ + "op": "vpn_location_set", + "exitCountryCode": "at", + "exitCity": "Vienna", + "entryCountryCode": "", + "entryCity": "" + }], + "next": { + "op": "signal", + "qml_emitter": "serverListButton-btn", + "signal": "visibleChanged" + } + } + ] + } +} diff --git a/tests/functional/servers/addon.js b/tests/functional/servers/addon.js index cf6f5a66cf..e4726377f0 100644 --- a/tests/functional/servers/addon.js +++ b/tests/functional/servers/addon.js @@ -16,8 +16,8 @@ function createScenario(scenario, addonPath) { if (!fs.existsSync(generatedPath)) { const manifestPath = path.join(addonPath, 'manifest.json'); if (!fs.existsSync(manifestPath)) { - throw new Error( - `No generated and not manifest file! ${manifestPath} should exist!`); + throw new Error(`No generated and not manifest file! ${ + manifestPath} should exist! Have you executed \`./scripts/addon/generate_all_tests.py'?`); } const obj = {}; diff --git a/tests/functional/testAddons.js b/tests/functional/testAddons.js index acf75c5ce9..f0b8b062f9 100644 --- a/tests/functional/testAddons.js +++ b/tests/functional/testAddons.js @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ const assert = require('assert'); +const {navBar, settingsScreen, homeScreen} = require('./elements.js'); const vpn = require('./helper.js'); describe('Addons', function() { @@ -55,4 +56,68 @@ describe('Addons', function() { 10) === 1; }); }); + + it('Settings rollback - location', async () => { + // Loading the custom tutorial + await vpn.resetAddons('05_settings_rollback'); + + await vpn.waitForCondition(async () => { + return parseInt( + await vpn.getElementProperty('VPNAddonManager', 'count'), + 10) === 1; + }); + + const exitCityName = + await vpn.getElementProperty('VPNCurrentServer', 'exitCityName'); + const exitCountryCode = + await vpn.getElementProperty('VPNCurrentServer', 'exitCountryCode'); + + // Let's start the tutorial + await vpn.waitForElementAndClick(navBar.SETTINGS); + await vpn.waitForElementAndClick(settingsScreen.TIPS_AND_TRICKS); + await vpn.waitForElementAndClick(homeScreen.TUTORIAL_LIST_HIGHLIGHT); + + // Confirmation dialog for settings-rollback + await vpn.waitForElementProperty( + homeScreen.TUTORIAL_POPUP_PRIMARY_BUTTON, 'visible', 'true'); + assert( + (await vpn.getElementProperty( + homeScreen.TUTORIAL_POPUP_PRIMARY_BUTTON, 'text')) === 'Continue'); + await vpn.waitForElementAndClick(homeScreen.TUTORIAL_POPUP_PRIMARY_BUTTON); + + await vpn.waitForCondition(async () => { + return await vpn.getElementProperty( + 'VPNCurrentServer', 'exitCityName') === 'Vienna'; + }); + + assert( + await vpn.getElementProperty('VPNCurrentServer', 'exitCityName') === + 'Vienna'); + assert( + await vpn.getElementProperty('VPNCurrentServer', 'exitCountryCode') === + 'at'); + + await vpn.waitForElementAndClick('serverListButton-btn'); + + // Final dialog + await vpn.waitForElementProperty( + homeScreen.TUTORIAL_POPUP_PRIMARY_BUTTON, 'visible', 'true'); + assert( + (await vpn.getElementProperty( + homeScreen.TUTORIAL_POPUP_PRIMARY_BUTTON, 'text')) === 'Let’s go!'); + await vpn.waitForElementAndClick( + homeScreen.TUTORIAL_POPUP_SECONDARY_BUTTON); + + await vpn.waitForCondition(async () => { + return await vpn.getElementProperty( + 'VPNCurrentServer', 'exitCityName') === exitCityName; + }); + + assert( + await vpn.getElementProperty('VPNCurrentServer', 'exitCityName') === + exitCityName); + assert( + await vpn.getElementProperty('VPNCurrentServer', 'exitCountryCode') === + exitCountryCode); + }); });