Skip to content

Commit 4677ce5

Browse files
authored
Merge pull request #3954 from NoelDeMartin/MOBILE-4470
MOBILE-4470: Improve lazy loading and fix tests
2 parents 5936cda + fee90d4 commit 4677ce5

File tree

16 files changed

+45
-79
lines changed

16 files changed

+45
-79
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Feature: Test basic usage of chat in app
1515
| user | course | role |
1616
| student1 | C1 | student |
1717
| student2 | C1 | student |
18+
And I enable "chat" "mod" plugin
1819
And the following "activities" exist:
1920
| activity | name | intro | course | idnumber | groupmode |
2021
| chat | Test chat name | Test chat | C1 | chat | 0 |

src/addons/mod/chat/tests/behat/navigation.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Feature: Test chat navigation
1313
| user | course | role |
1414
| student1 | C1 | student |
1515
| student2 | C1 | student |
16+
And I enable "chat" "mod" plugin
1617
And the following "activities" exist:
1718
| activity | name | intro | course | idnumber | groupmode |
1819
| chat | Test chat name | Test chat | C1 | chat | 0 |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Feature: Test basic usage of survey activity in app
1616
| user | course | role |
1717
| student1 | C1 | student |
1818
| teacher1 | C1 | editingteacher |
19+
And I enable "survey" "mod" plugin
1920
And the following "activities" exist:
2021
| activity | name | intro | course | idnumber | groupmode |
2122
| survey | Test survey name | Test survey | C1 | survey | 0 |

src/addons/mod/workshop/assessment/accumulative/services/handler-lazy.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerLazyService
3535
extends AddonModWorkshopAssessmentStrategyAccumulativeHandlerService
3636
implements AddonWorkshopAssessmentStrategyHandler {
3737

38-
/**
39-
* @inheritdoc
40-
*/
41-
async isEnabled(): Promise<boolean> {
42-
return true;
43-
}
44-
4538
/**
4639
* @inheritdoc
4740
*/

src/addons/mod/workshop/assessment/accumulative/services/handler.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ import {
2020
} from '@addons/mod/workshop/assessment/constants';
2121
import type { AddonModWorkshopAssessmentStrategyAccumulativeHandlerLazyService } from './handler-lazy';
2222

23-
export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerService {
23+
export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerService
24+
implements Partial<AddonWorkshopAssessmentStrategyHandler> {
2425

2526
name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_NAME;
2627
strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_STRATEGY_NAME;
2728

29+
/**
30+
* @inheritdoc
31+
*/
32+
async isEnabled(): Promise<boolean> {
33+
return true;
34+
}
35+
2836
}
2937

3038
/**
@@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS
4452

4553
lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyAccumulativeHandlerService());
4654
lazyHandler.setLazyInstanceMethods([
47-
'isEnabled',
4855
'getComponent',
4956
'getOriginalValues',
5057
'hasDataChanged',

src/addons/mod/workshop/assessment/comments/services/handler-lazy.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ export class AddonModWorkshopAssessmentStrategyCommentsHandlerLazyService
3434
extends AddonModWorkshopAssessmentStrategyCommentsHandlerService
3535
implements AddonWorkshopAssessmentStrategyHandler {
3636

37-
/**
38-
* @inheritdoc
39-
*/
40-
async isEnabled(): Promise<boolean> {
41-
return true;
42-
}
43-
4437
/**
4538
* @inheritdoc
4639
*/

src/addons/mod/workshop/assessment/comments/services/handler.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ import {
2020
} from '@addons/mod/workshop/assessment/constants';
2121
import type { AddonModWorkshopAssessmentStrategyCommentsHandlerLazyService } from './handler-lazy';
2222

23-
export class AddonModWorkshopAssessmentStrategyCommentsHandlerService {
23+
export class AddonModWorkshopAssessmentStrategyCommentsHandlerService
24+
implements Partial<AddonWorkshopAssessmentStrategyHandler> {
2425

2526
name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_NAME;
2627
strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_STRATEGY_NAME;
2728

29+
/**
30+
* @inheritdoc
31+
*/
32+
async isEnabled(): Promise<boolean> {
33+
return true;
34+
}
35+
2836
}
2937

3038
/**
@@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS
4452

4553
lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyCommentsHandlerService());
4654
lazyHandler.setLazyInstanceMethods([
47-
'isEnabled',
4855
'getComponent',
4956
'getOriginalValues',
5057
'hasDataChanged',

src/addons/mod/workshop/assessment/numerrors/services/handler-lazy.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerLazyService
3434
extends AddonModWorkshopAssessmentStrategyNumErrorsHandlerService
3535
implements AddonWorkshopAssessmentStrategyHandler {
3636

37-
/**
38-
* @inheritdoc
39-
*/
40-
async isEnabled(): Promise<boolean> {
41-
return true;
42-
}
43-
4437
/**
4538
* @inheritdoc
4639
*/

src/addons/mod/workshop/assessment/numerrors/services/handler.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ import {
2020
} from '@addons/mod/workshop/assessment/constants';
2121
import type { AddonModWorkshopAssessmentStrategyNumErrorsHandlerLazyService } from './handler-lazy';
2222

23-
export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerService {
23+
export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerService
24+
implements Partial<AddonWorkshopAssessmentStrategyHandler> {
2425

2526
name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_NAME;
2627
strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_STRATEGY_NAME;
2728

29+
/**
30+
* @inheritdoc
31+
*/
32+
async isEnabled(): Promise<boolean> {
33+
return true;
34+
}
35+
2836
}
2937

3038
/**
@@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS
4452

4553
lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyNumErrorsHandlerService());
4654
lazyHandler.setLazyInstanceMethods([
47-
'isEnabled',
4855
'getComponent',
4956
'getOriginalValues',
5057
'hasDataChanged',

src/addons/mod/workshop/assessment/rubric/services/handler-lazy.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ export class AddonModWorkshopAssessmentStrategyRubricHandlerLazyService
3434
extends AddonModWorkshopAssessmentStrategyRubricHandlerService
3535
implements AddonWorkshopAssessmentStrategyHandler {
3636

37-
/**
38-
* @inheritdoc
39-
*/
40-
async isEnabled(): Promise<boolean> {
41-
return true;
42-
}
43-
4437
/**
4538
* @inheritdoc
4639
*/

src/addons/mod/workshop/assessment/rubric/services/handler.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ import {
2020
} from '@addons/mod/workshop/assessment/constants';
2121
import type { AddonModWorkshopAssessmentStrategyRubricHandlerLazyService } from './handler-lazy';
2222

23-
export class AddonModWorkshopAssessmentStrategyRubricHandlerService {
23+
export class AddonModWorkshopAssessmentStrategyRubricHandlerService
24+
implements Partial<AddonWorkshopAssessmentStrategyHandler> {
2425

2526
name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_NAME;
2627
strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_STRATEGY_NAME;
2728

29+
/**
30+
* @inheritdoc
31+
*/
32+
async isEnabled(): Promise<boolean> {
33+
return true;
34+
}
35+
2836
}
2937

3038
/**
@@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS
4452

4553
lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyRubricHandlerService());
4654
lazyHandler.setLazyInstanceMethods([
47-
'isEnabled',
4855
'getComponent',
4956
'getOriginalValues',
5057
'hasDataChanged',

src/app/app-routing.module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import { InjectionToken, Injector, ModuleWithProviders, NgModule, Type } from '@angular/core';
1616
import {
17-
PreloadAllModules,
1817
RouterModule,
1918
Route,
2019
Routes,
@@ -224,7 +223,7 @@ export const APP_ROUTES = new InjectionToken('APP_ROUTES');
224223

225224
@NgModule({
226225
imports: [
227-
RouterModule.forRoot([], { preloadingStrategy: PreloadAllModules }),
226+
RouterModule.forRoot([]),
228227
],
229228
providers: [
230229
{ provide: ROUTES, multi: true, useFactory: buildAppRoutes, deps: [Injector] },

src/core/features/course/tests/behat/basic_usage.feature

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Feature: Test basic usage of one course in app
1717
| user | course | role |
1818
| teacher1 | C1 | editingteacher |
1919
| student1 | C1 | student |
20+
And I enable "chat" "mod" plugin
21+
And I enable "survey" "mod" plugin
2022
And the following "activities" exist:
2123
| activity | name | intro | course | idnumber | option | section |
2224
| choice | Choice course 1 | Test choice description | C1 | choice1 | Option 1, Option 2, Option 3 | 1 |
@@ -345,7 +347,7 @@ Feature: Test basic usage of one course in app
345347
Scenario: Navigation between sections using the bottom arrows
346348
When I entered the course "Course 1" as "student1" in the app
347349
Then the header should be "Course 1" in the app
348-
And I should find "Test forum name" in the app
350+
And I should find "Test forum name" in the app
349351
And I should find "Test wiki name" in the app
350352
And I should find "Choice course 1" in the app
351353
And I should find "assignment" in the app

src/core/features/mainmenu/mainmenu-tab-routing.module.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,6 @@ import { Route, Routes } from '@angular/router';
1818
import { ModuleRoutesConfig, isEmptyRoute, resolveModuleRoutes } from '@/app/app-routing.module';
1919

2020
const MAIN_MENU_TAB_ROUTES = new InjectionToken('MAIN_MENU_TAB_ROUTES');
21-
const modulesPaths: Record<string, Set<string>> = {};
22-
23-
/**
24-
* Get the name of the module the injector belongs to.
25-
*
26-
* @param injector Injector.
27-
* @returns Injector module name.
28-
*/
29-
function getInjectorModule(injector: Injector): string | null {
30-
if (!('source' in injector) || typeof injector.source !== 'string') {
31-
return null;
32-
}
33-
34-
// Get module name from R3Injector source.
35-
// See https://github.com/angular/angular/blob/16.2.0/packages/core/src/di/r3_injector.ts#L161C8
36-
return injector.source;
37-
}
38-
39-
/**
40-
* Get module paths.
41-
*
42-
* @param injector Injector.
43-
* @returns Module paths.
44-
*/
45-
function getModulePaths(injector: Injector): Set<string> | null {
46-
const module = getInjectorModule(injector);
47-
48-
if (!module) {
49-
return null;
50-
}
51-
52-
return modulesPaths[module] ??= new Set();
53-
}
5421

5522
/**
5623
* Build module routes.
@@ -61,23 +28,18 @@ function getModulePaths(injector: Injector): Set<string> | null {
6128
*/
6229
export function buildTabMainRoutes(injector: Injector, mainRoute: Route): Routes {
6330
const path = mainRoute.path ?? '';
64-
const modulePaths = getModulePaths(injector);
65-
const isRootRoute = modulePaths && !modulePaths.has(path);
6631
const routes = resolveModuleRoutes(injector, MAIN_MENU_TAB_ROUTES);
6732

6833
mainRoute.path = path;
69-
modulePaths?.add(path);
7034

71-
if (isRootRoute && !('redirectTo' in mainRoute)) {
35+
if (!('redirectTo' in mainRoute)) {
7236
mainRoute.children = mainRoute.children || [];
7337
mainRoute.children = mainRoute.children.concat(routes.children);
7438
} else if (isEmptyRoute(mainRoute)) {
7539
return [];
7640
}
7741

78-
return isRootRoute
79-
? [mainRoute, ...routes.siblings]
80-
: [mainRoute];
42+
return [mainRoute, ...routes.siblings];
8143
}
8244

8345
@NgModule()

0 commit comments

Comments
 (0)