Merge pull request #3420 from NoelDeMartin/MOBILE-4011

MOBILE-4011 sitehome: Fix link handler
main
Dani Palou 2022-10-25 16:40:18 +02:00 committed by GitHub
commit 98e54d05be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 10 deletions

View File

@ -26,7 +26,6 @@ import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils';
import { mock, mockSingleton, RenderConfig, renderTemplate, renderWrapperComponent } from '@/testing/utils';
import { CoreDB } from '@services/db';
describe('CoreFormatTextDirective', () => {
@ -122,12 +121,7 @@ describe('CoreFormatTextDirective', () => {
it('should use external-content directive on images', async () => {
// Arrange
mockSingleton(CoreDB, {
getDB: () => undefined,
});
let site = new CoreSite('42', 'https://mysite.com', 'token');
site = mock(site, {
const site = mock(new CoreSite('42', 'https://mysite.com', 'token'), {
canDownloadFiles: () => true,
});

View File

@ -57,7 +57,7 @@ export class CoreSiteHomeIndexLinkHandlerService extends CoreContentLinksHandler
const courseId = parseInt(params.id, 10);
if (!courseId) {
return url.includes('index.php');
return url.includes('index.php') || url.includes('?redirect=0');
}
const site = await CoreSites.getSite(siteId);

View File

@ -0,0 +1,48 @@
// (C) Copyright 2015 Moodle Pty Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { mock, mockSingleton } from '@/testing/utils';
import { CoreSite } from '@classes/site';
import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate';
import { CoreSiteHomeIndexLinkHandlerService } from '@features/sitehome/services/handlers/index-link';
import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites';
import { CoreCustomURLSchemes } from '@services/urlschemes';
describe('Site Home link handlers', () => {
it('Handles links ending with /?redirect=0', async () => {
// Arrange.
const siteUrl = 'https://school.moodledemo.net';
const siteId = CoreSites.createSiteID(siteUrl, 'student');
mockSingleton(CoreSites, mock({
isStoredRootURL: () => Promise.resolve({ siteIds: [siteId] }),
getSite: () => Promise.resolve(new CoreSite(siteId, siteUrl)),
getSiteIdsFromUrl: () => Promise.resolve([siteId]),
}));
CoreContentLinksDelegate.registerHandler(new CoreSiteHomeIndexLinkHandlerService());
// Act.
await CoreCustomURLSchemes.handleCustomURL(`moodlemobile://link=${siteUrl}/?redirect=0`);
// Assert.
expect(CoreNavigator.navigateToSitePath).toHaveBeenCalledWith('/home/site', {
siteId,
preferCurrentTab: false,
});
});
});

View File

@ -19,13 +19,16 @@ import { Observable, Subject } from 'rxjs';
import { sep } from 'path';
import { CORE_SITE_SCHEMAS } from '@services/sites';
import { CoreSingletonProxy, Translate } from '@singletons';
import { ApplicationInit, CoreSingletonProxy, Translate } from '@singletons';
import { CoreTextUtilsProvider } from '@services/utils/text';
import { TranslatePipeStub } from './stubs/pipes/translate';
import { CoreExternalContentDirectiveStub } from './stubs/directives/core-external-content';
import { CoreNetwork } from '@services/network';
import { CorePlatform } from '@services/platform';
import { CoreDB } from '@services/db';
import { CoreNavigator } from '@services/navigator';
import { CoreDomUtils } from '@services/utils/dom';
abstract class WrapperComponent<U> {
@ -38,13 +41,21 @@ type ServiceInjectionToken = AbstractType<unknown> | Type<unknown> | string;
let testBedInitialized = false;
const textUtils = new CoreTextUtilsProvider();
const DEFAULT_SERVICE_SINGLETON_MOCKS: [CoreSingletonProxy, Record<string, unknown>][] = [
[Translate, mock({ instant: key => key })],
[CoreDB, mock({ getDB: () => mock() })],
[CoreNetwork, mock({ onChange: () => new Observable() })],
[CoreDomUtils, mock({ showModalLoading: () => Promise.resolve(mock({}, ['dismiss'])) })],
[CoreNavigator, mock({ navigateToSitePath: () => Promise.resolve(true) })],
[ApplicationInit, mock({
donePromise: Promise.resolve(),
runInitializers: () => Promise.resolve(),
})],
[CorePlatform, mock({
is: () => false,
isMobile: () => false,
ready: () => Promise.resolve(),
resume: new Subject<void>(),
})],
[CoreNetwork, { onChange: () => new Observable() }],
];
async function renderAngularComponent<T>(component: Type<T>, config: RenderConfig): Promise<ComponentFixture<T>> {