Skip to content

Commit 2962361

Browse files
authored
Merge pull request #2658 from intersective/2.4.y.z/CORE-8194/hide-expert-ph-forwardurl-trunk
[CORE-8194] 2.4.y.z/hide-expert-ph-forwardurl-trunk
2 parents c97d526 + 43fdbea commit 2962361

4 files changed

Lines changed: 84 additions & 84 deletions

File tree

projects/v3/src/app/components/assessment/assessment.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ export class AssessmentComponent implements OnInit, OnChanges, OnDestroy {
154154
private sharedService: SharedService,
155155
private assessmentService: AssessmentService,
156156
private activityService: ActivityService,
157-
private cdr: ChangeDetectorRef,
158157
private modalController: ModalController,
158+
private cdr: ChangeDetectorRef,
159159
) {
160160
this.resubscribe$.pipe(
161161
takeUntil(this.unsubscribe$),

projects/v3/src/app/pages/home/home.page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<div class="exp-header">
4545
<h2 class="headline-2"
4646
[innerHTML]="experience.name"></h2>
47-
<div class="button-group-no-gap" *ngIf="projectBrief || showProjectHub">
47+
<div class="button-group-no-gap" *ngIf="!isExpert && (projectBrief || showProjectHub)">
4848
<ion-button fill="clear"
4949
size="small"
5050
class="project-brief-btn"

projects/v3/src/app/pages/home/home.page.spec.ts

Lines changed: 67 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ import { ActivatedRoute, Router } from '@angular/router';
33
import { ActivityService } from '@v3/services/activity.service';
44
import { AssessmentService } from '@v3/services/assessment.service';
55
import { UtilsService } from '@v3/services/utils.service';
6-
import { AlertController, IonicModule, ModalController } from '@ionic/angular';
6+
import { IonicModule } from '@ionic/angular';
77
import { AchievementService } from '@v3/app/services/achievement.service';
88
import { HomeService } from '@v3/app/services/home.service';
99
import { NotificationsService } from '@v3/app/services/notifications.service';
1010
import { SharedService } from '@v3/app/services/shared.service';
1111
import { BrowserStorageService } from '@v3/app/services/storage.service';
1212
import { FastFeedbackService } from '@v3/app/services/fast-feedback.service';
1313
import { UnlockIndicatorService } from '@v3/app/services/unlock-indicator.service';
14-
import { PulsecheckService } from '@v3/app/services/pulsecheck.service';
15-
import { HttpClientTestingModule } from '@angular/common/http/testing';
16-
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
1714

1815
import { HomePage } from './home.page';
1916
import { of } from 'rxjs';
@@ -32,19 +29,19 @@ describe('HomePage', () => {
3229
let utilsService: jasmine.SpyObj<UtilsService>;
3330

3431
beforeEach(waitForAsync(() => {
35-
const homeServiceSpy = jasmine.createSpyObj('HomeService', {
36-
'getExperience': undefined,
37-
'getMilestones': undefined,
38-
'getProjectProgress': undefined,
39-
'getPulseCheckStatuses': of({ data: { pulseCheckStatus: {} } }),
40-
'getPulseCheckSkills': of({ data: { pulseCheckSkills: [] } }),
41-
}, {
42-
'experience$': of({ id: 1, name: 'Test Experience', cardUrl: 'test-card-url' }),
43-
'experienceProgress$': of(0),
44-
'activityCount$': of(0),
45-
'milestonesWithProgress$': of([]),
46-
'milestones$': of([]),
47-
'projectProgress$': of(0),
32+
const homeServiceSpy = jasmine.createSpyObj('HomeService', [
33+
'getExperience',
34+
'getMilestones',
35+
'getProjectProgress',
36+
'getPulseCheckStatuses',
37+
'getPulseCheckSkills',
38+
], {
39+
'experience$': of(),
40+
'experienceProgress$': of(),
41+
'activityCount$': of(),
42+
'milestonesWithProgress$': of(),
43+
'milestones$': of(),
44+
'projectProgress$': of(),
4845
});
4946

5047
const achievementServiceSpy = jasmine.createSpyObj('AchievementService', [
@@ -55,38 +52,19 @@ describe('HomePage', () => {
5552
'achievements$': of(),
5653
});
5754

58-
const sharedServiceSpy = jasmine.createSpyObj('SharedService', ['refreshJWT'], {
59-
'team$': of(null),
60-
});
55+
const sharedServiceSpy = jasmine.createSpyObj('SharedService', ['refreshJWT']);
6156
const storageServiceSpy = jasmine.createSpyObj('BrowserStorageService', [
6257
'get',
6358
'lastVisited',
6459
'getUser',
6560
'getFeature',
6661
]);
67-
// set up default return values for storage service
68-
storageServiceSpy.getUser.and.returnValue({
69-
role: 'participant',
70-
apikey: 'test-key',
71-
projectId: 1,
72-
teamId: 1,
73-
});
74-
storageServiceSpy.get.and.callFake((key: string) => {
75-
if (key === 'experience') {
76-
return { id: 1, name: 'Test Experience', cardUrl: 'test-card-url' };
77-
}
78-
return null;
79-
});
80-
storageServiceSpy.getFeature.and.returnValue(false);
81-
const fastFeedbackServiceSpy = jasmine.createSpyObj('FastFeedbackService', {
82-
'pullFastFeedback': of(null),
83-
});
62+
const fastFeedbackServiceSpy = jasmine.createSpyObj('FastFeedbackService', ['pullFastFeedback']);
8463
const utilsServiceSpy = jasmine.createSpyObj('UtilsService', ['setPageTitle', 'isMobile']);
8564

8665
TestBed.configureTestingModule({
8766
declarations: [ HomePage ],
88-
imports: [IonicModule.forRoot(), HttpClientTestingModule],
89-
schemas: [CUSTOM_ELEMENTS_SCHEMA],
67+
imports: [IonicModule.forRoot()],
9068
providers: [
9169
{
9270
provide: ActivatedRoute,
@@ -134,27 +112,7 @@ describe('HomePage', () => {
134112
'unlockedTasks$': of([])
135113
})
136114
},
137-
{
138-
provide: AlertController,
139-
useValue: jasmine.createSpyObj('AlertController', ['create'])
140-
},
141-
{
142-
provide: PulsecheckService,
143-
useValue: jasmine.createSpyObj('PulsecheckService', ['getPulsecheckStatuses'])
144-
},
145-
{
146-
provide: NotificationsService,
147-
useValue: jasmine.createSpyObj('NotificationsService', [
148-
'alert',
149-
'popUp',
150-
'getTodoItems',
151-
])
152-
},
153-
{
154-
provide: ModalController,
155-
useValue: jasmine.createSpyObj('ModalController', ['create', 'dismiss'])
156-
},
157-
],
115+
]
158116
}).compileComponents();
159117

160118
fixture = TestBed.createComponent(HomePage);
@@ -205,12 +163,7 @@ describe('HomePage', () => {
205163
it('should get experience from storage', async () => {
206164
await component.updateDashboard();
207165
expect(storageService.get).toHaveBeenCalledWith('experience');
208-
expect(component.experience).toEqual({ name: 'Test Experience', cardUrl: 'test-url' } as any);
209-
});
210-
211-
it('should set project hub visibility from feature toggle', async () => {
212-
await component.updateDashboard();
213-
expect(storageService.getFeature).toHaveBeenCalledWith('pulseCheckIndicator');
166+
expect(component.experience).toEqual({ name: 'Test Experience', cardUrl: 'test-url' });
214167
});
215168

216169
it('should set project hub visibility from feature toggle', async () => {
@@ -225,6 +178,20 @@ describe('HomePage', () => {
225178
expect(component.showProjectHub).toBe(false);
226179
});
227180

181+
it('should treat mentor users as expert users', async () => {
182+
storageService.getUser.and.returnValue({
183+
role: 'mentor',
184+
apikey: 'test-key',
185+
projectId: 1,
186+
teamId: 1,
187+
});
188+
189+
await component.updateDashboard();
190+
191+
expect(component.isExpert).toBe(true);
192+
expect(component.isParticipant).toBe(false);
193+
});
194+
228195
it('should call service methods to fetch data', async () => {
229196
await component.updateDashboard();
230197
expect(homeService.getMilestones).toHaveBeenCalled();
@@ -244,7 +211,7 @@ describe('HomePage', () => {
244211
component.pulseCheckIndicatorEnabled = true;
245212
await component.updateDashboard();
246213
expect(homeService.getPulseCheckStatuses).toHaveBeenCalled();
247-
expect(component.pulseCheckStatus).toEqual({ red: 1, orange: 2, green: 3 } as any);
214+
expect(component.pulseCheckStatus).toEqual({ red: 1, orange: 2, green: 3 });
248215
});
249216

250217
it('should not get pulse check statuses when pulse check indicator is disabled', async () => {
@@ -316,9 +283,7 @@ describe('HomePage', () => {
316283
data: { pulseCheckSkills: null }
317284
}));
318285
await component.updateDashboard();
319-
// component defaults to [] when pulseCheckSkills is null or empty (see line 243: || [])
320-
// and only updates when newSkills.length > 0, so it stays as initial []
321-
expect(component.pulseCheckSkills).toEqual([]);
286+
expect(component.pulseCheckSkills).toBeNull();
322287
});
323288

324289
it('should handle empty pulse check skills response', async () => {
@@ -333,6 +298,38 @@ describe('HomePage', () => {
333298
});
334299
});
335300

301+
describe('project brief actions', () => {
302+
beforeEach(() => {
303+
component.experience = {
304+
id: 1,
305+
name: 'Test Experience',
306+
leadImage: 'test-image',
307+
cardUrl: 'test-card-url'
308+
} as any;
309+
component.projectBrief = {
310+
id: 1,
311+
title: 'Project Brief'
312+
} as any;
313+
component.showProjectHub = true;
314+
});
315+
316+
it('should hide project brief actions for expert users', () => {
317+
component.isExpert = true;
318+
319+
fixture.detectChanges();
320+
321+
expect(fixture.nativeElement.querySelector('.button-group-no-gap')).toBeNull();
322+
});
323+
324+
it('should show project brief actions for non-expert users', () => {
325+
component.isExpert = false;
326+
327+
fixture.detectChanges();
328+
329+
expect(fixture.nativeElement.querySelector('.button-group-no-gap')).not.toBeNull();
330+
});
331+
});
332+
336333
describe('filterActivities', () => {
337334
const mockMilestones = [
338335
{

projects/v3/src/app/pages/home/home.page.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
3939

4040
isMobile: boolean;
4141
isParticipant: boolean;
42+
isExpert: boolean;
4243
isExpertWithoutTeam: boolean;
4344
pulseCheckIndicatorEnabled: boolean;
4445
activityProgresses = {};
@@ -103,10 +104,7 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
103104
}
104105

105106
ngOnInit() {
106-
const role = this.storageService.getUser().role;
107-
const teamId = this.storageService.getUser().teamId;
108-
this.isParticipant = role === 'participant';
109-
this.isExpertWithoutTeam = role === 'mentor' && !teamId;
107+
this.updateUserRoleState();
110108
this.pulseCheckIndicatorEnabled = this.storageService.getFeature('pulseCheckIndicator');
111109
this.isMobile = this.utils.isMobile();
112110

@@ -117,10 +115,8 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
117115
takeUntil(this.unsubscribe$)
118116
)
119117
.subscribe(() => {
120-
// re-evaluate expert without team status when team changes
121-
const currentRole = this.storageService.getUser().role;
122-
const currentTeamId = this.storageService.getUser().teamId;
123-
this.isExpertWithoutTeam = currentRole === 'mentor' && !currentTeamId;
118+
// re-evaluate role state when team changes
119+
this.updateUserRoleState();
124120
});
125121

126122
this.homeService.milestones$
@@ -227,10 +223,7 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
227223
await this.sharedService.refreshJWT(); // refresh JWT token [CORE-6083]
228224

229225
// re-evaluate user role and team status after JWT refresh updates teamId
230-
const role = this.storageService.getUser().role;
231-
const teamId = this.storageService.getUser().teamId;
232-
this.isParticipant = role === 'participant';
233-
this.isExpertWithoutTeam = role === 'mentor' && !teamId;
226+
this.updateUserRoleState();
234227

235228
this.experience = this.storageService.get("experience");
236229
this.showProjectHub = this.storageService.getFeature('showProjectHub');
@@ -291,6 +284,16 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
291284
this.router.navigate(["experiences"]);
292285
}
293286

287+
private updateUserRoleState(): void {
288+
const user = this.storageService.getUser() || {};
289+
const role = user.role;
290+
const teamId = user.teamId;
291+
292+
this.isParticipant = role === 'participant';
293+
this.isExpert = role === 'mentor';
294+
this.isExpertWithoutTeam = this.isExpert && !teamId;
295+
}
296+
294297
switchContent(event) {
295298
// update points upon switching to badges tab
296299
if (event.detail.value === "badges") {

0 commit comments

Comments
 (0)