MOBILE-4061 behat: Native handle of skip on boarding

main
Pau Ferrer Ocaña 2022-05-09 10:40:57 +02:00
parent 92d4a6a16b
commit 97862f40f5
3 changed files with 43 additions and 24 deletions

View File

@ -470,7 +470,6 @@ class behat_app extends behat_base {
*/
protected function prepare_browser(array $options = []) {
$restart = $options['restart'] ?? true;
$skiponboarding = $options['skiponboarding'] ?? true;
if ($restart) {
if ($this->apprunning) {
@ -509,32 +508,23 @@ class behat_app extends behat_base {
try {
// Init Behat JavaScript runtime.
$this->execute_script('window.behatInit();');
$initOptions = new StdClass();
$initOptions->skipOnBoarding = $options['skiponboarding'] ?? true;
$initOptions->configOverrides = $this->appconfig;
$this->execute_script('window.behatInit(' . json_encode($initOptions) . ');');
} catch (Exception $error) {
throw new DriverException('Moodle app not running or not running on Automated mode.');
}
if ($restart) {
// Assert initial page.
$this->spin(function($context) use ($skiponboarding) {
$this->spin(function($context) {
$page = $context->getSession()->getPage();
$element = $page->find('xpath', '//page-core-login-site//input[@name="url"]');
if ($element) {
if (!$skiponboarding) {
return true;
}
// Wait for the onboarding modal to open, if any.
$this->wait_for_pending_js();
$element = $page->find('xpath', '//core-login-site-onboarding');
if ($element) {
$this->i_press_in_the_app('"Skip"');
}
// Login screen found.
return true;
}
@ -548,12 +538,6 @@ class behat_app extends behat_base {
}, false, 60);
}
// Prepare testing config.
$configoverrides = json_encode($this->appconfig);
$this->evaluate_script("document.cookie='MoodleAppConfig=$configoverrides'");
$this->evaluate_script("configProvider.patchEnvironment($configoverrides)");
// Continue only after JS finishes.
$this->wait_for_pending_js();
}

View File

@ -17,6 +17,14 @@ Feature: Test basic usage of login in app
| student2 | C1 | student |
| teacher1 | C1 | editingteacher |
Scenario: Skip on boarding
When I launch the app runtime
Then I should find "Welcome to the Moodle App!" in the app
When I press "Skip" in the app
Then I should not find "Skip" in the app
And I should find "Connect to Moodle" in the app
Scenario: Add a new account in the app & Site name in displayed when adding a new account
When I enter the app
And I press the back button in the app

View File

@ -15,13 +15,21 @@
import { TestsBehatDomUtils } from './behat-dom';
import { TestsBehatBlocking } from './behat-blocking';
import { CoreCustomURLSchemes } from '@services/urlschemes';
import { CoreLoginHelperProvider } from '@features/login/services/login-helper';
import { CoreConfig } from '@services/config';
import { EnvironmentConfig } from '@/types/config';
/**
* Behat runtime servive with public API.
*/
export class TestsBehatRuntime {
static init(): void {
/**
* Init behat functions and set options like skipping onboarding.
*
* @param options Options to set on the app.
*/
static init(options?: TestsBehatInitOptions): void {
TestsBehatBlocking.init();
(window as BehatTestsWindow).behat = {
@ -38,6 +46,20 @@ export class TestsBehatRuntime {
setField: TestsBehatRuntime.setField,
handleCustomURL: TestsBehatRuntime.handleCustomURL,
};
if (!options) {
return;
}
if (options.skipOnBoarding === true) {
CoreConfig.set(CoreLoginHelperProvider.ONBOARDING_DONE, 1);
}
if (options.configOverrides) {
// Set the cookie so it's maintained between reloads.
document.cookie = 'MoodleAppConfig=' + JSON.stringify(options.configOverrides);
CoreConfig.patchEnvironment(options.configOverrides);
}
}
/**
@ -407,3 +429,8 @@ export type TestBehatElementLocator = {
near?: TestBehatElementLocator;
selector?: string;
};
export type TestsBehatInitOptions = {
skipOnBoarding?: boolean;
configOverrides?: Partial<EnvironmentConfig>;
};