Skip to content

Commit 1b56572

Browse files
authored
Merge pull request #3543 from dpalou/MOBILE-4069
Mobile 4069
2 parents de60a89 + 0732722 commit 1b56572

File tree

9 files changed

+242
-29
lines changed

9 files changed

+242
-29
lines changed

local_moodleappbehat/tests/behat/behat_app.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,21 @@ public function i_load_more_items_in_the_app(bool $not = false) {
237237
/**
238238
* Trigger swipe gesture.
239239
*
240-
* @When /^I swipe to the (left|right) in the app$/
240+
* @When /^I swipe to the (left|right) (in (".+") )?in the app$/
241241
* @param string $direction Swipe direction
242+
* @param bool $hasLocator Whether a reference locator is used.
243+
* @param string $locator Reference locator.
242244
*/
243-
public function i_swipe_in_the_app(string $direction) {
244-
$method = 'swipe' . ucwords($direction);
245+
public function i_swipe_in_the_app(string $direction, bool $hasLocator = false, string $locator = '') {
246+
if ($hasLocator) {
247+
$locator = $this->parse_element_locator($locator);
248+
}
249+
250+
$result = $this->zone_js("swipe('$direction'" . ($hasLocator ? ", $locator" : '') . ')');
245251

246-
$this->zone_js("getAngularInstance('ion-content', 'CoreSwipeNavigationDirective').$method()");
252+
if ($result !== 'OK') {
253+
throw new DriverException('Error when swiping - ' . $result);
254+
}
247255

248256
$this->wait_for_pending_js();
249257

src/addons/block/timeline/tests/behat/basic_usage.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ Feature: Timeline block.
2525
| assign | C1 | assign03 | Assignment 03 | ##tomorrow## |
2626
| assign | C2 | assign04 | Assignment 04 | ##+2 days## |
2727
| assign | C1 | assign05 | Assignment 05 | ##+5 days## |
28-
| assign | C2 | assign06 | Assignment 06 | ##+1 month## |
29-
| assign | C2 | assign07 | Assignment 07 | ##+1 month## |
30-
| assign | C3 | assign08 | Assignment 08 | ##+1 month## |
31-
| assign | C2 | assign09 | Assignment 09 | ##+1 month## |
32-
| assign | C1 | assign10 | Assignment 10 | ##+1 month## |
28+
| assign | C2 | assign06 | Assignment 06 | ##+31 days## |
29+
| assign | C2 | assign07 | Assignment 07 | ##+31 days## |
30+
| assign | C3 | assign08 | Assignment 08 | ##+31 days## |
31+
| assign | C2 | assign09 | Assignment 09 | ##+31 days## |
32+
| assign | C1 | assign10 | Assignment 10 | ##+31 days## |
3333
| assign | C1 | assign11 | Assignment 11 | ##+6 months## |
3434
| assign | C1 | assign12 | Assignment 12 | ##+6 months## |
3535
| assign | C1 | assign13 | Assignment 13 | ##+6 months## |

src/addons/mod/book/components/index/addon-mod-book-index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ <h2>{{ 'addon.mod_book.toc' | translate }}</h2>
2424
(click)="openBook(chapter.id)">
2525
<ion-label>
2626
<p [class.ion-padding-start]="addPadding && chapter.level == 1 ? true : null">
27-
<span *ngIf="showNumbers" class="addon-mod-book-number">{{chapter.indexNumber}}&nbsp;</span>
28-
<span *ngIf="showBullets" class="addon-mod-book-bullet">&bull;&nbsp;</span>
27+
<span *ngIf="showNumbers" class="addon-mod-book-number">{{chapter.indexNumber}} </span>
28+
<span *ngIf="showBullets" class="addon-mod-book-bullet">&bull; </span>
2929
<core-format-text [text]="chapter.title" contextLevel="module" [contextInstanceId]="module.id" [courseId]="courseId">
3030
</core-format-text>
3131
</p>

src/addons/mod/book/components/index/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
6060
]);
6161
}
6262

63+
/**
64+
* @inheritdoc
65+
*/
66+
protected async invalidateContent(): Promise<void> {
67+
await AddonModBook.invalidateContent(this.module.id, this.courseId);
68+
}
69+
6370
/**
6471
* Load book data.
6572
*

src/addons/mod/book/components/toc/toc.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ <h2>{{ 'addon.mod_book.toc' | translate }}</h2>
1717
[attr.aria-current]="selected == chapter.id ? 'page' : 'false'" button [class.item-dimmed]="chapter.hidden" detail="false">
1818
<ion-label>
1919
<p [class.ion-padding-start]="addPadding && chapter.level == 1 ? true : null" class="item-heading">
20-
<span *ngIf="showNumbers" class="addon-mod-book-number">{{chapter.indexNumber}}&nbsp;</span>
21-
<span *ngIf="showBullets" class="addon-mod-book-bullet">&bull;&nbsp;</span>
20+
<span *ngIf="showNumbers" class="addon-mod-book-number">{{chapter.indexNumber}} </span>
21+
<span *ngIf="showBullets" class="addon-mod-book-bullet">&bull; </span>
2222
<core-format-text [text]="chapter.title" contextLevel="module" [contextInstanceId]="moduleId" [courseId]="courseId">
2323
</core-format-text>
2424
</p>

src/addons/mod/book/services/book.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ export class AddonModBookProvider {
291291
});
292292
}
293293

294-
chapterNumber++;
294+
if (!parseInt(chapter.hidden, 10)) {
295+
chapterNumber++;
296+
}
295297
});
296298

297299
return chapters;

src/addons/mod/book/tests/behat/basic_usage.feature

Lines changed: 128 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Feature: Test basic usage of book activity in app
2727
| Basic book | Hidden chapter | This is a hidden chapter | 0 | 1 | 4 |
2828
| Basic book | Hidden subchapter | This is a hidden subchapter | 1 | 1 | 5 |
2929
| Basic book | Chapt 3 | This is the third chapter | 0 | 0 | 6 |
30+
| Basic book | Last hidden | Another hidden subchapter | 1 | 1 | 7 |
3031

3132
Scenario: View book table of contents (student)
3233
Given I entered the course "Course 1" as "student1" in the app
@@ -39,6 +40,7 @@ Feature: Test basic usage of book activity in app
3940
And I should find "Start" in the app
4041
But I should not find "Hidden chapter" in the app
4142
And I should not find "Hidden subchapter" in the app
43+
And I should not find "Last hidden" in the app
4244
And I should not find "This is the first chapter" in the app
4345

4446
When I press "Start" in the app
@@ -49,6 +51,7 @@ Feature: Test basic usage of book activity in app
4951
And I should find "Chapt 3" in the app
5052
But I should not find "Hidden chapter" in the app
5153
And I should not find "Hidden subchapter" in the app
54+
And I should not find "Last hidden" in the app
5255

5356
Scenario: View book table of contents (teacher)
5457
Given I entered the course "Course 1" as "teacher1" in the app
@@ -60,6 +63,7 @@ Feature: Test basic usage of book activity in app
6063
And I should find "Hidden chapter" in the app
6164
And I should find "Hidden subchapter" in the app
6265
And I should find "Chapt 3" in the app
66+
And I should find "Last hidden" in the app
6367
And I should find "Start" in the app
6468
And I should not find "This is the first chapter" in the app
6569

@@ -71,6 +75,7 @@ Feature: Test basic usage of book activity in app
7175
And I should find "Hidden chapter" in the app
7276
And I should find "Hidden subchapter" in the app
7377
And I should find "Chapt 3" in the app
78+
And I should find "Last hidden" in the app
7479

7580
Scenario: Open chapters from table of contents
7681
Given I entered the course "Course 1" as "student1" in the app
@@ -127,65 +132,177 @@ Feature: Test basic usage of book activity in app
127132
And I should find "4 / 4" in the app
128133
But I should not find "This is the first chapter" in the app
129134

130-
# TODO: Test navigate using swipe.
135+
# Navigate using swipe.
136+
When I swipe to the left in "Chapt 3" "ion-slides" in the app
137+
Then I should find "Chapt 3" in the app
138+
And I should find "This is the third chapter" in the app
139+
And I should find "4 / 4" in the app
140+
141+
When I swipe to the right in "Chapt 3" "ion-slides" in the app
142+
Then I should find "Chapt 2" in the app
143+
And I should find "This is the second chapter" in the app
144+
And I should find "3 / 4" in the app
145+
146+
When I swipe to the right in "Chapt 2" "ion-slides" in the app
147+
Then I should find "Chapt 1.1" in the app
148+
And I should find "This is a subchapter" in the app
149+
And I should find "2 / 4" in the app
150+
151+
When I swipe to the left in "Chapt 1.1" "ion-slides" in the app
152+
Then I should find "Chapt 2" in the app
153+
And I should find "This is the second chapter" in the app
154+
And I should find "3 / 4" in the app
131155

132156
Scenario: View and navigate book contents (teacher)
133157
Given I entered the course "Course 1" as "teacher1" in the app
134158
And I press "Basic book" in the app
135159
And I press "Start" in the app
136160
Then I should find "Chapt 1" in the app
137161
And I should find "This is the first chapter" in the app
138-
And I should find "1 / 6" in the app
162+
And I should find "1 / 7" in the app
139163

140164
When I press "Next" in the app
141165
Then I should find "Chapt 1.1" in the app
142166
And I should find "This is a subchapter" in the app
143-
And I should find "2 / 6" in the app
167+
And I should find "2 / 7" in the app
144168
But I should not find "This is the first chapter" in the app
145169

146170
When I press "Next" in the app
147171
Then I should find "Chapt 2" in the app
148172
And I should find "This is the second chapter" in the app
149-
And I should find "3 / 6" in the app
173+
And I should find "3 / 7" in the app
150174
But I should not find "This is a subchapter" in the app
151175

152176
When I press "Next" in the app
153177
Then I should find "Hidden chapter" in the app
154178
And I should find "This is a hidden chapter" in the app
155-
And I should find "4 / 6" in the app
179+
And I should find "4 / 7" in the app
156180
But I should not find "This is the second chapter" in the app
157181

158182
When I press "Next" in the app
159183
Then I should find "Hidden subchapter" in the app
160184
And I should find "This is a hidden subchapter" in the app
161-
And I should find "5 / 6" in the app
185+
And I should find "5 / 7" in the app
162186
But I should not find "This is a hidden chapter" in the app
163187

164188
When I press "Previous" in the app
165189
Then I should find "Hidden chapter" in the app
166190
And I should find "This is a hidden chapter" in the app
167-
And I should find "4 / 6" in the app
191+
And I should find "4 / 7" in the app
168192
But I should not find "This is a hidden subchapter" in the app
169193

170194
# Navigate using TOC.
171195
When I press "Table of contents" in the app
172196
And I press "Chapt 1" in the app
173197
Then I should find "Chapt 1" in the app
174198
And I should find "This is the first chapter" in the app
175-
And I should find "1 / 6" in the app
199+
And I should find "1 / 7" in the app
176200
But I should not find "This is a hidden chapter" in the app
177201

178202
When I press "Table of contents" in the app
179203
And I press "Hidden subchapter" in the app
180204
Then I should find "Hidden subchapter" in the app
181205
And I should find "This is a hidden subchapter" in the app
182-
And I should find "5 / 6" in the app
206+
And I should find "5 / 7" in the app
183207
But I should not find "This is the first chapter" in the app
184208

185-
# TODO: Test navigate using swipe.
209+
# Navigate using swipe.
210+
When I swipe to the left in "Hidden subchapter" "ion-slides" in the app
211+
Then I should find "Chapt 3" in the app
212+
And I should find "This is the third chapter" in the app
213+
And I should find "6 / 7" in the app
214+
215+
When I swipe to the left in "Chapt 3" "ion-slides" in the app
216+
Then I should find "Last hidden" in the app
217+
And I should find "Another hidden subchapter" in the app
218+
And I should find "7 / 7" in the app
219+
220+
When I swipe to the left in "Last hidden" "ion-slides" in the app
221+
Then I should find "Last hidden" in the app
222+
And I should find "Another hidden subchapter" in the app
223+
And I should find "7 / 7" in the app
224+
225+
When I swipe to the right in "Last hidden" "ion-slides" in the app
226+
Then I should find "Chapt 3" in the app
227+
And I should find "This is the third chapter" in the app
228+
And I should find "6 / 7" in the app
186229

187230
Scenario: Link to book opens chapter content
188231
Given I entered the book activity "Basic book" on course "Course 1" as "student1" in the app
189232
Then I should find "This is the first chapter" in the app
190233

191-
# TODO: Scenario to test book numbering (numbers, bullets, etc.).
234+
Scenario: Test numbering (student)
235+
Given the following "activities" exist:
236+
| activity | name | intro | course | idnumber | numbering |
237+
| book | Bull book | Test book description | C1 | book2 | 2 |
238+
| book | Ind book | Test book description | C1 | book2 | 3 |
239+
| book | None book | Test book description | C1 | book2 | 0 |
240+
And the following "mod_book > chapter" exist:
241+
| book | title | content | subchapter | hidden | pagenum |
242+
| Bull book | Chapt 1 | This is the first chapter | 0 | 0 | 1 |
243+
| Ind book | Chapt 1 | This is the first chapter | 0 | 0 | 1 |
244+
| None book | Chapt 1 | This is the first chapter | 0 | 0 | 1 |
245+
And I entered the course "Course 1" as "student1" in the app
246+
And I press "Basic book" in the app
247+
Then I should find "1. Chapt 1" in the app
248+
And I should find "1.1. Chapt 1.1" in the app
249+
And I should find "2. Chapt 2" in the app
250+
And I should find "3. Chapt 3" in the app
251+
252+
When I press "Start" in the app
253+
And I press "Table of contents" in the app
254+
Then I should find "1. Chapt 1" in the app
255+
And I should find "1.1. Chapt 1.1" in the app
256+
And I should find "2. Chapt 2" in the app
257+
And I should find "3. Chapt 3" in the app
258+
259+
When I press "Close" in the app
260+
And I press the back button in the app
261+
And I press the back button in the app
262+
And I press "Bull book" in the app
263+
Then I should find "• Chapt 1" in the app
264+
But I should not find "1. Chapt 1" in the app
265+
266+
When I press "Start" in the app
267+
And I press "Table of contents" in the app
268+
Then I should find "• Chapt 1" in the app
269+
But I should not find "1. Chapt 1" in the app
270+
271+
When I press "Close" in the app
272+
And I press the back button in the app
273+
And I press the back button in the app
274+
And I press "Ind book" in the app
275+
Then I should find "Chapt 1" in the app
276+
But I should not find "• Chapt 1" in the app
277+
And I should not find "1. Chapt 1" in the app
278+
279+
When I press "Start" in the app
280+
And I press "Table of contents" in the app
281+
Then I should find "Chapt 1" in the app
282+
But I should not find "• Chapt 1" in the app
283+
And I should not find "1. Chapt 1" in the app
284+
285+
When I press "Close" in the app
286+
And I press the back button in the app
287+
And I press the back button in the app
288+
And I press "None book" in the app
289+
Then I should find "Chapt 1" in the app
290+
But I should not find "• Chapt 1" in the app
291+
And I should not find "1. Chapt 1" in the app
292+
293+
When I press "Start" in the app
294+
And I press "Table of contents" in the app
295+
Then I should find "Chapt 1" in the app
296+
But I should not find "• Chapt 1" in the app
297+
And I should not find "1. Chapt 1" in the app
298+
299+
Scenario: Test numbering (teacher)
300+
Given I entered the course "Course 1" as "teacher1" in the app
301+
And I press "Basic book" in the app
302+
Then I should find "1. Chapt 1" in the app
303+
And I should find "1.1. Chapt 1.1" in the app
304+
And I should find "2. Chapt 2" in the app
305+
And I should find "x. Hidden chapter" in the app
306+
And I should find "x.x. Hidden subchapter" in the app
307+
And I should find "3. Chapt 3" in the app
308+
And I should find "3.x. Last hidden" in the app

src/testing/services/behat-dom.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { TestingBehatElementLocator, TestingBehatFindOptions } from './behat-run
2424
@Injectable({ providedIn: 'root' })
2525
export class TestingBehatDomUtilsService {
2626

27+
protected static readonly MULTI_ELEM_ALLOWED = ['P', 'SPAN', 'ION-LABEL'];
28+
2729
/**
2830
* Check if an element is clickable.
2931
*
@@ -154,6 +156,7 @@ export class TestingBehatDomUtilsService {
154156
},
155157
);
156158

159+
let fallbackCandidates: ElementsWithExact[] = [];
157160
let currentNode: Node | null = null;
158161
// eslint-disable-next-line no-cond-assign
159162
while (currentNode = treeWalker.nextNode()) {
@@ -202,9 +205,24 @@ export class TestingBehatDomUtilsService {
202205
elements.push(...this.findElementsBasedOnTextWithinWithExact(childNode, text, options));
203206
}
204207
}
208+
209+
// Allow searching text split into different elements in some cases.
210+
if (
211+
elements.length === 0 &&
212+
currentNode instanceof HTMLElement &&
213+
TestingBehatDomUtilsService.MULTI_ELEM_ALLOWED.includes(currentNode.tagName) &&
214+
currentNode.innerText.includes(text)
215+
) {
216+
// Only keep the child elements in the candidates list.
217+
fallbackCandidates = fallbackCandidates.filter(entry => !entry.element.contains(currentNode));
218+
fallbackCandidates.push({
219+
element: currentNode,
220+
exact: currentNode.innerText.trim() == text,
221+
});
222+
}
205223
}
206224

207-
return elements;
225+
return elements.length > 0 ? elements : fallbackCandidates;
208226
}
209227

210228
/**

0 commit comments

Comments
 (0)