-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathmsal.navigation.client.spec.ts
96 lines (84 loc) · 2.65 KB
/
msal.navigation.client.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { TestBed } from "@angular/core/testing";
import { Location } from "@angular/common";
import { Router } from "@angular/router";
import {
InteractionType,
NavigationClient,
NavigationOptions,
PublicClientApplication,
} from "@azure/msal-browser";
import { MsalBroadcastService } from "./msal.broadcast.service";
import { MsalGuard } from "./msal.guard";
import { MsalCustomNavigationClient } from "./msal.navigation.client";
import { MsalModule, MsalService } from "./public-api";
let authService: MsalService;
let navigationClient: MsalCustomNavigationClient;
let routerMock = {
navigateByUrl: jasmine.createSpy("navigateByUrl").and.resolveTo(),
};
const msalInstance = new PublicClientApplication({
auth: {
clientId: "b5c2e510-4a17-4feb-b219-e55aa5b74144",
redirectUri: "http://localhost:4200",
},
});
describe("MsalCustomNaviationClient", () => {
beforeEach(() => {
TestBed.resetTestingModule();
TestBed.configureTestingModule({
imports: [
MsalModule.forRoot(msalInstance, null, {
interactionType: InteractionType.Popup,
protectedResourceMap: new Map(),
}),
],
providers: [
MsalBroadcastService,
{ provide: Router, useValue: routerMock },
Location,
MsalCustomNavigationClient,
MsalService,
MsalGuard,
],
teardown: { destroyAfterEach: false },
});
authService = TestBed.inject(MsalService);
navigationClient = TestBed.inject(MsalCustomNavigationClient);
});
describe("NavigateInternal Unit tests", () => {
it("is created", () => {
expect(navigationClient).toBeTruthy();
});
it("NavigateInternal (noHistory false)", (done) => {
const url = "http://localhost:4200/profile";
const normalizedAbsoluteUrl = "/profile";
const options = {
noHistory: false,
} as NavigationOptions;
const navigateByUrlOptions = {
replaceUrl: false,
};
navigationClient.navigateInternal(url, options).then(() => {
expect(routerMock.navigateByUrl).toHaveBeenCalledWith(
normalizedAbsoluteUrl,
navigateByUrlOptions
);
done();
});
});
it("NavigateInternal (noHistory true)", (done) => {
const url = "http://localhost:4200/profile";
const options = {
noHistory: true,
} as NavigationOptions;
const windowLocationReplaceSpy = spyOn(
NavigationClient.prototype,
"navigateInternal"
);
navigationClient.navigateInternal(url, options).then(() => {
expect(windowLocationReplaceSpy).toHaveBeenCalledWith(url, options);
done();
});
});
});
});