Merge pull request #3954 from NoelDeMartin/MOBILE-4470

MOBILE-4470: Improve lazy loading and fix tests
main
Dani Palou 2024-03-05 13:54:27 +01:00 committed by GitHub
commit 4677ce5c3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 45 additions and 79 deletions

View File

@ -15,6 +15,7 @@ Feature: Test basic usage of chat in app
| user | course | role | | user | course | role |
| student1 | C1 | student | | student1 | C1 | student |
| student2 | C1 | student | | student2 | C1 | student |
And I enable "chat" "mod" plugin
And the following "activities" exist: And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode | | activity | name | intro | course | idnumber | groupmode |
| chat | Test chat name | Test chat | C1 | chat | 0 | | chat | Test chat name | Test chat | C1 | chat | 0 |

View File

@ -13,6 +13,7 @@ Feature: Test chat navigation
| user | course | role | | user | course | role |
| student1 | C1 | student | | student1 | C1 | student |
| student2 | C1 | student | | student2 | C1 | student |
And I enable "chat" "mod" plugin
And the following "activities" exist: And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode | | activity | name | intro | course | idnumber | groupmode |
| chat | Test chat name | Test chat | C1 | chat | 0 | | chat | Test chat name | Test chat | C1 | chat | 0 |

View File

@ -16,6 +16,7 @@ Feature: Test basic usage of survey activity in app
| user | course | role | | user | course | role |
| student1 | C1 | student | | student1 | C1 | student |
| teacher1 | C1 | editingteacher | | teacher1 | C1 | editingteacher |
And I enable "survey" "mod" plugin
And the following "activities" exist: And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode | | activity | name | intro | course | idnumber | groupmode |
| survey | Test survey name | Test survey | C1 | survey | 0 | | survey | Test survey name | Test survey | C1 | survey | 0 |

View File

@ -35,13 +35,6 @@ export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerLazyService
extends AddonModWorkshopAssessmentStrategyAccumulativeHandlerService extends AddonModWorkshopAssessmentStrategyAccumulativeHandlerService
implements AddonWorkshopAssessmentStrategyHandler { implements AddonWorkshopAssessmentStrategyHandler {
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
/** /**
* @inheritdoc * @inheritdoc
*/ */

View File

@ -20,11 +20,19 @@ import {
} from '@addons/mod/workshop/assessment/constants'; } from '@addons/mod/workshop/assessment/constants';
import type { AddonModWorkshopAssessmentStrategyAccumulativeHandlerLazyService } from './handler-lazy'; import type { AddonModWorkshopAssessmentStrategyAccumulativeHandlerLazyService } from './handler-lazy';
export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerService { export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerService
implements Partial<AddonWorkshopAssessmentStrategyHandler> {
name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_NAME; name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_NAME;
strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_STRATEGY_NAME; strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_STRATEGY_NAME;
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
} }
/** /**
@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS
lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyAccumulativeHandlerService()); lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyAccumulativeHandlerService());
lazyHandler.setLazyInstanceMethods([ lazyHandler.setLazyInstanceMethods([
'isEnabled',
'getComponent', 'getComponent',
'getOriginalValues', 'getOriginalValues',
'hasDataChanged', 'hasDataChanged',

View File

@ -34,13 +34,6 @@ export class AddonModWorkshopAssessmentStrategyCommentsHandlerLazyService
extends AddonModWorkshopAssessmentStrategyCommentsHandlerService extends AddonModWorkshopAssessmentStrategyCommentsHandlerService
implements AddonWorkshopAssessmentStrategyHandler { implements AddonWorkshopAssessmentStrategyHandler {
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
/** /**
* @inheritdoc * @inheritdoc
*/ */

View File

@ -20,11 +20,19 @@ import {
} from '@addons/mod/workshop/assessment/constants'; } from '@addons/mod/workshop/assessment/constants';
import type { AddonModWorkshopAssessmentStrategyCommentsHandlerLazyService } from './handler-lazy'; import type { AddonModWorkshopAssessmentStrategyCommentsHandlerLazyService } from './handler-lazy';
export class AddonModWorkshopAssessmentStrategyCommentsHandlerService { export class AddonModWorkshopAssessmentStrategyCommentsHandlerService
implements Partial<AddonWorkshopAssessmentStrategyHandler> {
name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_NAME; name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_NAME;
strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_STRATEGY_NAME; strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_STRATEGY_NAME;
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
} }
/** /**
@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS
lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyCommentsHandlerService()); lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyCommentsHandlerService());
lazyHandler.setLazyInstanceMethods([ lazyHandler.setLazyInstanceMethods([
'isEnabled',
'getComponent', 'getComponent',
'getOriginalValues', 'getOriginalValues',
'hasDataChanged', 'hasDataChanged',

View File

@ -34,13 +34,6 @@ export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerLazyService
extends AddonModWorkshopAssessmentStrategyNumErrorsHandlerService extends AddonModWorkshopAssessmentStrategyNumErrorsHandlerService
implements AddonWorkshopAssessmentStrategyHandler { implements AddonWorkshopAssessmentStrategyHandler {
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
/** /**
* @inheritdoc * @inheritdoc
*/ */

View File

@ -20,11 +20,19 @@ import {
} from '@addons/mod/workshop/assessment/constants'; } from '@addons/mod/workshop/assessment/constants';
import type { AddonModWorkshopAssessmentStrategyNumErrorsHandlerLazyService } from './handler-lazy'; import type { AddonModWorkshopAssessmentStrategyNumErrorsHandlerLazyService } from './handler-lazy';
export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerService { export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerService
implements Partial<AddonWorkshopAssessmentStrategyHandler> {
name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_NAME; name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_NAME;
strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_STRATEGY_NAME; strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_STRATEGY_NAME;
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
} }
/** /**
@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS
lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyNumErrorsHandlerService()); lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyNumErrorsHandlerService());
lazyHandler.setLazyInstanceMethods([ lazyHandler.setLazyInstanceMethods([
'isEnabled',
'getComponent', 'getComponent',
'getOriginalValues', 'getOriginalValues',
'hasDataChanged', 'hasDataChanged',

View File

@ -34,13 +34,6 @@ export class AddonModWorkshopAssessmentStrategyRubricHandlerLazyService
extends AddonModWorkshopAssessmentStrategyRubricHandlerService extends AddonModWorkshopAssessmentStrategyRubricHandlerService
implements AddonWorkshopAssessmentStrategyHandler { implements AddonWorkshopAssessmentStrategyHandler {
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
/** /**
* @inheritdoc * @inheritdoc
*/ */

View File

@ -20,11 +20,19 @@ import {
} from '@addons/mod/workshop/assessment/constants'; } from '@addons/mod/workshop/assessment/constants';
import type { AddonModWorkshopAssessmentStrategyRubricHandlerLazyService } from './handler-lazy'; import type { AddonModWorkshopAssessmentStrategyRubricHandlerLazyService } from './handler-lazy';
export class AddonModWorkshopAssessmentStrategyRubricHandlerService { export class AddonModWorkshopAssessmentStrategyRubricHandlerService
implements Partial<AddonWorkshopAssessmentStrategyHandler> {
name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_NAME; name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_NAME;
strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_STRATEGY_NAME; strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_STRATEGY_NAME;
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
} }
/** /**
@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS
lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyRubricHandlerService()); lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyRubricHandlerService());
lazyHandler.setLazyInstanceMethods([ lazyHandler.setLazyInstanceMethods([
'isEnabled',
'getComponent', 'getComponent',
'getOriginalValues', 'getOriginalValues',
'hasDataChanged', 'hasDataChanged',

View File

@ -14,7 +14,6 @@
import { InjectionToken, Injector, ModuleWithProviders, NgModule, Type } from '@angular/core'; import { InjectionToken, Injector, ModuleWithProviders, NgModule, Type } from '@angular/core';
import { import {
PreloadAllModules,
RouterModule, RouterModule,
Route, Route,
Routes, Routes,
@ -224,7 +223,7 @@ export const APP_ROUTES = new InjectionToken('APP_ROUTES');
@NgModule({ @NgModule({
imports: [ imports: [
RouterModule.forRoot([], { preloadingStrategy: PreloadAllModules }), RouterModule.forRoot([]),
], ],
providers: [ providers: [
{ provide: ROUTES, multi: true, useFactory: buildAppRoutes, deps: [Injector] }, { provide: ROUTES, multi: true, useFactory: buildAppRoutes, deps: [Injector] },

View File

@ -17,6 +17,8 @@ Feature: Test basic usage of one course in app
| user | course | role | | user | course | role |
| teacher1 | C1 | editingteacher | | teacher1 | C1 | editingteacher |
| student1 | C1 | student | | student1 | C1 | student |
And I enable "chat" "mod" plugin
And I enable "survey" "mod" plugin
And the following "activities" exist: And the following "activities" exist:
| activity | name | intro | course | idnumber | option | section | | activity | name | intro | course | idnumber | option | section |
| choice | Choice course 1 | Test choice description | C1 | choice1 | Option 1, Option 2, Option 3 | 1 | | 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
Scenario: Navigation between sections using the bottom arrows Scenario: Navigation between sections using the bottom arrows
When I entered the course "Course 1" as "student1" in the app When I entered the course "Course 1" as "student1" in the app
Then the header should be "Course 1" in the app Then the header should be "Course 1" in the app
And I should find "Test forum name" in the app And I should find "Test forum name" in the app
And I should find "Test wiki name" in the app And I should find "Test wiki name" in the app
And I should find "Choice course 1" in the app And I should find "Choice course 1" in the app
And I should find "assignment" in the app And I should find "assignment" in the app

View File

@ -18,39 +18,6 @@ import { Route, Routes } from '@angular/router';
import { ModuleRoutesConfig, isEmptyRoute, resolveModuleRoutes } from '@/app/app-routing.module'; import { ModuleRoutesConfig, isEmptyRoute, resolveModuleRoutes } from '@/app/app-routing.module';
const MAIN_MENU_TAB_ROUTES = new InjectionToken('MAIN_MENU_TAB_ROUTES'); const MAIN_MENU_TAB_ROUTES = new InjectionToken('MAIN_MENU_TAB_ROUTES');
const modulesPaths: Record<string, Set<string>> = {};
/**
* Get the name of the module the injector belongs to.
*
* @param injector Injector.
* @returns Injector module name.
*/
function getInjectorModule(injector: Injector): string | null {
if (!('source' in injector) || typeof injector.source !== 'string') {
return null;
}
// Get module name from R3Injector source.
// See https://github.com/angular/angular/blob/16.2.0/packages/core/src/di/r3_injector.ts#L161C8
return injector.source;
}
/**
* Get module paths.
*
* @param injector Injector.
* @returns Module paths.
*/
function getModulePaths(injector: Injector): Set<string> | null {
const module = getInjectorModule(injector);
if (!module) {
return null;
}
return modulesPaths[module] ??= new Set();
}
/** /**
* Build module routes. * Build module routes.
@ -61,23 +28,18 @@ function getModulePaths(injector: Injector): Set<string> | null {
*/ */
export function buildTabMainRoutes(injector: Injector, mainRoute: Route): Routes { export function buildTabMainRoutes(injector: Injector, mainRoute: Route): Routes {
const path = mainRoute.path ?? ''; const path = mainRoute.path ?? '';
const modulePaths = getModulePaths(injector);
const isRootRoute = modulePaths && !modulePaths.has(path);
const routes = resolveModuleRoutes(injector, MAIN_MENU_TAB_ROUTES); const routes = resolveModuleRoutes(injector, MAIN_MENU_TAB_ROUTES);
mainRoute.path = path; mainRoute.path = path;
modulePaths?.add(path);
if (isRootRoute && !('redirectTo' in mainRoute)) { if (!('redirectTo' in mainRoute)) {
mainRoute.children = mainRoute.children || []; mainRoute.children = mainRoute.children || [];
mainRoute.children = mainRoute.children.concat(routes.children); mainRoute.children = mainRoute.children.concat(routes.children);
} else if (isEmptyRoute(mainRoute)) { } else if (isEmptyRoute(mainRoute)) {
return []; return [];
} }
return isRootRoute return [mainRoute, ...routes.siblings];
? [mainRoute, ...routes.siblings]
: [mainRoute];
} }
@NgModule() @NgModule()