commit
98e54d05be
|
@ -26,7 +26,6 @@ import { CoreSites } from '@services/sites';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
|
|
||||||
import { mock, mockSingleton, RenderConfig, renderTemplate, renderWrapperComponent } from '@/testing/utils';
|
import { mock, mockSingleton, RenderConfig, renderTemplate, renderWrapperComponent } from '@/testing/utils';
|
||||||
import { CoreDB } from '@services/db';
|
|
||||||
|
|
||||||
describe('CoreFormatTextDirective', () => {
|
describe('CoreFormatTextDirective', () => {
|
||||||
|
|
||||||
|
@ -122,12 +121,7 @@ describe('CoreFormatTextDirective', () => {
|
||||||
|
|
||||||
it('should use external-content directive on images', async () => {
|
it('should use external-content directive on images', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
mockSingleton(CoreDB, {
|
const site = mock(new CoreSite('42', 'https://mysite.com', 'token'), {
|
||||||
getDB: () => undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
let site = new CoreSite('42', 'https://mysite.com', 'token');
|
|
||||||
site = mock(site, {
|
|
||||||
canDownloadFiles: () => true,
|
canDownloadFiles: () => true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ export class CoreSiteHomeIndexLinkHandlerService extends CoreContentLinksHandler
|
||||||
const courseId = parseInt(params.id, 10);
|
const courseId = parseInt(params.id, 10);
|
||||||
|
|
||||||
if (!courseId) {
|
if (!courseId) {
|
||||||
return url.includes('index.php');
|
return url.includes('index.php') || url.includes('?redirect=0');
|
||||||
}
|
}
|
||||||
|
|
||||||
const site = await CoreSites.getSite(siteId);
|
const site = await CoreSites.getSite(siteId);
|
||||||
|
|
|
@ -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,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -19,13 +19,16 @@ import { Observable, Subject } from 'rxjs';
|
||||||
import { sep } from 'path';
|
import { sep } from 'path';
|
||||||
|
|
||||||
import { CORE_SITE_SCHEMAS } from '@services/sites';
|
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 { CoreTextUtilsProvider } from '@services/utils/text';
|
||||||
|
|
||||||
import { TranslatePipeStub } from './stubs/pipes/translate';
|
import { TranslatePipeStub } from './stubs/pipes/translate';
|
||||||
import { CoreExternalContentDirectiveStub } from './stubs/directives/core-external-content';
|
import { CoreExternalContentDirectiveStub } from './stubs/directives/core-external-content';
|
||||||
import { CoreNetwork } from '@services/network';
|
import { CoreNetwork } from '@services/network';
|
||||||
import { CorePlatform } from '@services/platform';
|
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> {
|
abstract class WrapperComponent<U> {
|
||||||
|
|
||||||
|
@ -38,13 +41,21 @@ type ServiceInjectionToken = AbstractType<unknown> | Type<unknown> | string;
|
||||||
let testBedInitialized = false;
|
let testBedInitialized = false;
|
||||||
const textUtils = new CoreTextUtilsProvider();
|
const textUtils = new CoreTextUtilsProvider();
|
||||||
const DEFAULT_SERVICE_SINGLETON_MOCKS: [CoreSingletonProxy, Record<string, unknown>][] = [
|
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({
|
[CorePlatform, mock({
|
||||||
is: () => false,
|
is: () => false,
|
||||||
isMobile: () => false,
|
isMobile: () => false,
|
||||||
ready: () => Promise.resolve(),
|
ready: () => Promise.resolve(),
|
||||||
resume: new Subject<void>(),
|
resume: new Subject<void>(),
|
||||||
})],
|
})],
|
||||||
[CoreNetwork, { onChange: () => new Observable() }],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
async function renderAngularComponent<T>(component: Type<T>, config: RenderConfig): Promise<ComponentFixture<T>> {
|
async function renderAngularComponent<T>(component: Type<T>, config: RenderConfig): Promise<ComponentFixture<T>> {
|
||||||
|
|
Loading…
Reference in New Issue