MOBILE-4245 Credentials: Fix NullInjectorError when provide HttpClient
parent
7a78bb9375
commit
1506228c74
|
@ -65,9 +65,14 @@ export class CoreShowPasswordComponent implements OnInit, AfterViewInit {
|
||||||
*/
|
*/
|
||||||
async ngAfterViewInit(): Promise<void> {
|
async ngAfterViewInit(): Promise<void> {
|
||||||
if (this.ionInput) {
|
if (this.ionInput) {
|
||||||
|
try {
|
||||||
// It's an ion-input, use it to get the native element.
|
// It's an ion-input, use it to get the native element.
|
||||||
this.input = await this.ionInput.getInputElement();
|
this.input = await this.ionInput.getInputElement();
|
||||||
this.setData(this.input);
|
this.setData(this.input);
|
||||||
|
} catch (error) {
|
||||||
|
// This should never fail, but it does in some testing environment because Ionic elements are not
|
||||||
|
// rendered properly. So in case this fails, we'll just ignore the error.
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,17 +18,26 @@ import { CoreLoginError } from '@classes/errors/loginerror';
|
||||||
import { CoreLoginComponentsModule } from '@features/login/components/components.module';
|
import { CoreLoginComponentsModule } from '@features/login/components/components.module';
|
||||||
import { CoreLoginCredentialsPage } from '@features/login/pages/credentials/credentials';
|
import { CoreLoginCredentialsPage } from '@features/login/pages/credentials/credentials';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
|
import { Http } from '@singletons';
|
||||||
|
import { of } from 'rxjs';
|
||||||
|
import { CoreLoginHelper } from '../services/login-helper';
|
||||||
|
|
||||||
describe('Credentials page', () => {
|
describe('Credentials page', () => {
|
||||||
|
|
||||||
|
const siteUrl = 'https://campus.example.edu';
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
mockSingleton(Http, { get: () => of(null as any) });
|
||||||
|
});
|
||||||
|
|
||||||
it('renders', async () => {
|
it('renders', async () => {
|
||||||
// Arrange.
|
// Arrange.
|
||||||
const siteUrl = 'https://campus.example.edu';
|
|
||||||
|
|
||||||
mockSingleton(CoreSites, {
|
mockSingleton(CoreSites, {
|
||||||
getPublicSiteConfigByUrl: async () => ({
|
getPublicSiteConfigByUrl: async () => ({
|
||||||
wwwroot: 'https://campus.example.edu',
|
wwwroot: siteUrl,
|
||||||
httpswwwroot: 'https://campus.example.edu',
|
httpswwwroot: siteUrl,
|
||||||
sitename: 'Example Campus',
|
sitename: 'Example Campus',
|
||||||
guestlogin: 0,
|
guestlogin: 0,
|
||||||
rememberusername: 0,
|
rememberusername: 0,
|
||||||
|
@ -45,6 +54,8 @@ describe('Credentials page', () => {
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mockSingleton(CoreLoginHelper, { getAvailableSites: async () => [{ url: siteUrl, name: 'Example Campus' }] });
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
const fixture = await renderPageComponent(CoreLoginCredentialsPage, {
|
const fixture = await renderPageComponent(CoreLoginCredentialsPage, {
|
||||||
routeParams: { siteUrl },
|
routeParams: { siteUrl },
|
||||||
|
@ -58,7 +69,7 @@ describe('Credentials page', () => {
|
||||||
expect(findElement(fixture, '.core-siteurl', siteUrl)).not.toBeNull();
|
expect(findElement(fixture, '.core-siteurl', siteUrl)).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('suggests contacting support after multiple failed attempts', async () => {
|
it('suggests contacting support after multiple failed attempts', async (done) => {
|
||||||
// Arrange.
|
// Arrange.
|
||||||
mockSingleton(CoreSites, {
|
mockSingleton(CoreSites, {
|
||||||
getUserToken: () => {
|
getUserToken: () => {
|
||||||
|
@ -69,17 +80,15 @@ describe('Credentials page', () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mockSingleton(CoreLoginHelper, { getAvailableSites: async () => [] });
|
||||||
|
|
||||||
const fixture = await renderPageComponent(CoreLoginCredentialsPage, {
|
const fixture = await renderPageComponent(CoreLoginCredentialsPage, {
|
||||||
routeParams: {
|
routeParams: { siteUrl, siteConfig: { supportpage: '' } },
|
||||||
siteUrl: 'https://campus.example.edu',
|
imports: [CoreSharedModule, CoreLoginComponentsModule],
|
||||||
siteConfig: { supportpage: '' },
|
|
||||||
},
|
|
||||||
imports: [
|
|
||||||
CoreSharedModule,
|
|
||||||
CoreLoginComponentsModule,
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
done();
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
const form = requireElement<HTMLFormElement>(fixture, 'form');
|
const form = requireElement<HTMLFormElement>(fixture, 'form');
|
||||||
const formControls = fixture.componentInstance.credForm.controls;
|
const formControls = fixture.componentInstance.credForm.controls;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
import { mock, mockSingleton } from '@/testing/utils';
|
import { mock, mockSingleton } from '@/testing/utils';
|
||||||
import { CoreSite } from '@classes/site';
|
import { CoreSite } from '@classes/site';
|
||||||
import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate';
|
import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate';
|
||||||
|
import { CoreLoginHelper } from '@features/login/services/login-helper';
|
||||||
import { CoreSiteHomeIndexLinkHandlerService } from '@features/sitehome/services/handlers/index-link';
|
import { CoreSiteHomeIndexLinkHandlerService } from '@features/sitehome/services/handlers/index-link';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
|
@ -33,6 +34,8 @@ describe('Site Home link handlers', () => {
|
||||||
getSiteIdsFromUrl: () => Promise.resolve([siteId]),
|
getSiteIdsFromUrl: () => Promise.resolve([siteId]),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
mockSingleton(CoreLoginHelper, { getAvailableSites: async () => [{ url: siteUrl, name: 'Example Campus' }] });
|
||||||
|
|
||||||
CoreContentLinksDelegate.registerHandler(new CoreSiteHomeIndexLinkHandlerService());
|
CoreContentLinksDelegate.registerHandler(new CoreSiteHomeIndexLinkHandlerService());
|
||||||
|
|
||||||
// Act.
|
// Act.
|
||||||
|
|
Loading…
Reference in New Issue