-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathnavbar.component.spec.ts
More file actions
171 lines (155 loc) · 6.59 KB
/
navbar.component.spec.ts
File metadata and controls
171 lines (155 loc) · 6.59 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import { ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing'
import { NavbarComponent } from './navbar.component'
import { ReactiveFormsModule } from '@angular/forms'
import { RouterTestingModule } from '@angular/router/testing'
import { of, throwError } from 'rxjs'
import { MemberService } from 'src/app/member/service/member.service'
import { AccountService, LoginService } from 'src/app/account'
import { By } from '@angular/platform-browser'
import { HasAnyAuthorityDirective } from 'src/app/shared/directive/has-any-authority.directive'
import { HttpResponse } from '@angular/common/http'
import { Member } from 'src/app/member/model/member.model'
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
describe('NavbarComponent', () => {
let component: NavbarComponent
let fixture: ComponentFixture<NavbarComponent>
let loginService: jasmine.SpyObj<LoginService>
let accountService: jasmine.SpyObj<AccountService>
let memberService: jasmine.SpyObj<MemberService>
beforeEach(() => {
const loginServiceSpy = jasmine.createSpyObj('LoginService', ['login', 'logout'])
const memberServiceSpy = jasmine.createSpyObj('MemberService', ['find', 'setManagedMember'])
const accountServiceSpy = jasmine.createSpyObj('AccountService', [
'getAccountData',
'isAuthenticated',
'hasAnyAuthority',
'isLoggedAs',
'isOrganizationOwner',
'getImageUrl',
'getSalesforceId',
])
TestBed.configureTestingModule({
declarations: [NavbarComponent, HasAnyAuthorityDirective],
imports: [ReactiveFormsModule, RouterTestingModule],
providers: [
{ provide: LoginService, useValue: loginServiceSpy },
{ provide: MemberService, useValue: memberServiceSpy },
{ provide: AccountService, useValue: accountServiceSpy },
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
}).compileComponents()
fixture = TestBed.createComponent(NavbarComponent)
component = fixture.componentInstance
loginService = TestBed.inject(LoginService) as jasmine.SpyObj<LoginService>
memberService = TestBed.inject(MemberService) as jasmine.SpyObj<MemberService>
accountService = TestBed.inject(AccountService) as jasmine.SpyObj<AccountService>
})
it('should create', () => {
expect(component).toBeTruthy()
})
it('should display reports menu', fakeAsync(() => {
accountService.isAuthenticated.and.returnValue(true)
accountService.hasAnyAuthority.and.returnValue(false)
accountService.hasAnyAuthority.withArgs(['ROLE_USER']).and.returnValue(true)
accountService.isOrganizationOwner.and.returnValue(false)
accountService.getImageUrl.and.returnValue(null)
accountService.getSalesforceId.and.returnValue('sfid')
accountService.getAccountData.and.returnValue(
of({
id: 'id',
activated: true,
authorities: ['ROLE_USER'],
email: 'email@email.com',
firstName: 'name',
langKey: 'en',
lastName: 'surname',
imageUrl: 'url',
salesforceId: 'sfid',
loggedAs: false,
loginAs: 'sfid',
mainContact: false,
mfaEnabled: false,
})
)
memberService.find.and.returnValue(of({ id: 'id', client_id: 'a', isConsortiumLead: false }))
fixture.detectChanges()
tick()
const debugElement = fixture.debugElement.query(By.css('#tools-menu'))
expect(debugElement).toBeTruthy()
const consortiaReportLink = fixture.debugElement.query(By.css('#consortiaReportLink'))
expect(consortiaReportLink).toBeFalsy()
const consortiumMemberAffiliationsReportLink = fixture.debugElement.query(
By.css('#consortiumMemberAffiliationsReportLink')
)
expect(consortiumMemberAffiliationsReportLink).toBeFalsy()
const affiliationManagerLink = fixture.debugElement.query(By.css('#affiliationManagerLink'))
expect(affiliationManagerLink).toBeFalsy()
}))
it('should display consortia report link', fakeAsync(() => {
accountService.isAuthenticated.and.returnValue(true)
accountService.hasAnyAuthority.and.returnValue(false)
accountService.hasAnyAuthority.withArgs(['ROLE_CONSORTIUM_LEAD']).and.returnValue(true)
accountService.hasAnyAuthority.withArgs(['ROLE_USER']).and.returnValue(true)
accountService.isOrganizationOwner.and.returnValue(false)
accountService.getImageUrl.and.returnValue(null)
accountService.getSalesforceId.and.returnValue('sfid')
accountService.getAccountData.and.returnValue(
of({
id: 'id',
activated: true,
authorities: ['ROLE_USER', 'ROLE_CONSORTIUM_LEAD'],
email: 'email@email.com',
firstName: 'name',
langKey: 'en',
lastName: 'surname',
imageUrl: 'url',
salesforceId: 'sfid',
loggedAs: false,
loginAs: 'sfid',
mainContact: false,
mfaEnabled: false,
})
)
memberService.find.and.returnValue(of({ id: 'id', client_id: 'a', isConsortiumLead: true }))
fixture.detectChanges()
tick()
const consortiaReportLink = fixture.debugElement.query(By.css('#consortiaReportLink'))
expect(consortiaReportLink).toBeTruthy()
const consortiumMemberAffiliationsReportLink = fixture.debugElement.query(
By.css('#consortiumMemberAffiliationsReportLink')
)
expect(consortiumMemberAffiliationsReportLink).toBeTruthy()
}))
it('should display the affiliation manager link', fakeAsync(() => {
accountService.isAuthenticated.and.returnValue(true)
accountService.hasAnyAuthority.and.returnValue(false)
accountService.hasAnyAuthority.withArgs(['ASSERTION_SERVICE_ENABLED']).and.returnValue(true)
accountService.hasAnyAuthority.withArgs(['ROLE_USER']).and.returnValue(true)
accountService.isOrganizationOwner.and.returnValue(false)
accountService.getImageUrl.and.returnValue(null)
accountService.getSalesforceId.and.returnValue('sfid')
accountService.getAccountData.and.returnValue(
of({
id: 'id',
activated: true,
authorities: ['ROLE_USER', 'ASSERTION_SERVICE_ENABLED'],
email: 'email@email.com',
firstName: 'name',
langKey: 'en',
lastName: 'surname',
imageUrl: 'url',
salesforceId: 'sfid',
loggedAs: false,
loginAs: 'sfid',
mainContact: false,
mfaEnabled: false,
})
)
memberService.find.and.returnValue(of({ id: 'id', client_id: 'a', isConsortiumLead: true }))
fixture.detectChanges()
tick()
const affiliationManagerLink = fixture.debugElement.query(By.css('#affiliationManagerLink'))
expect(affiliationManagerLink).toBeTruthy()
}))
})