Skip to content

Commit 8329bc3

Browse files
committed
MOBILE-4842 behat: Add the ability to change language
1 parent 17d0602 commit 8329bc3

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

.github/workflows/acceptance.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ jobs:
4141
working-directory: app
4242
run: npm ci --no-audit
4343

44+
- name: Install languages
45+
working-directory: app
46+
run: |
47+
npx gulp lang
48+
npm run lang:update-langpacks
49+
4450
- name: Build app
4551
working-directory: app
4652
run: npm run build:test

local_moodleappbehat/tests/behat/behat_app.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,27 @@ public function i_open_the_calendar_for($month, $year) {
13481348
$this->zone_js("navigator.navigateToSitePath('/calendar/index', $options)");
13491349
}
13501350

1351+
/**
1352+
* Change language in the app
1353+
*
1354+
* @When /^I change language to "(.+)" in the app$/
1355+
* @param string $language Language code.
1356+
*/
1357+
public function i_change_language(string $langcode) {
1358+
$this->spin(function() use ($langcode) {
1359+
$result = $this->runtime_js("changeLanguage('$langcode')");
1360+
1361+
if ($result !== 'OK') {
1362+
throw new DriverException('Error changing language - ' . $result);
1363+
}
1364+
1365+
return true;
1366+
});
1367+
1368+
// Wait the app to be restarted.
1369+
$this->prepare_browser();
1370+
}
1371+
13511372
/**
13521373
* Change the viewport size in the browser running the Moodle App.
13531374
*
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@core_lang @app @javascript
2+
Feature: Test language changes
3+
4+
Background:
5+
Given the following "users" exist:
6+
| username |
7+
| student1 |
8+
9+
Scenario: User can change language
10+
Given I entered the app as "student1"
11+
When I press the more menu button in the app
12+
And I press "App settings" in the app
13+
And I press "General" in the app
14+
And I press "Language" in the app
15+
And I press "Català" in the app
16+
And I press "Canvia a Català" in the app
17+
And I wait the app to restart
18+
19+
Then I should find "Els meus cursos" in the app
20+
21+
When I change language to "es" in the app
22+
Then I should find "Mis cursos" in the app

src/testing/services/behat-runtime.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import { LocalNotificationsMock } from '@features/emulator/services/local-notifi
3333
import { GetClosureArgs } from '@/core/utils/types';
3434
import { CoreIframeComponent } from '@components/iframe/iframe';
3535
import { CorePromiseUtils } from '@singletons/promise-utils';
36+
import { CoreLang } from '@services/lang';
37+
import { CoreEvents } from '@singletons/events';
3638

3739
/**
3840
* Behat runtime servive with public API.
@@ -902,6 +904,28 @@ export class TestingBehatRuntimeService {
902904
return 'OK';
903905
}
904906

907+
/**
908+
* Change app language.
909+
*
910+
* @param language Language code to set.
911+
* @returns OK if successful.
912+
*/
913+
async changeLanguage(language: string): Promise<string> {
914+
this.log(`Action - Change language to: ${language}`);
915+
await CoreLang.changeCurrentLanguage(language);
916+
917+
const sites = await CoreSites.getSitesInstances();
918+
await CorePromiseUtils.ignoreErrors(Promise.all(sites.map((site) => site.invalidateWsCache())));
919+
920+
CoreEvents.trigger(CoreEvents.LANGUAGE_CHANGED, language);
921+
922+
CoreNavigator.navigate('/reload', {
923+
reset: true,
924+
});
925+
926+
return 'OK';
927+
}
928+
905929
/**
906930
* Wait for toast to be dismissed in the app.
907931
*

0 commit comments

Comments
 (0)