Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/app/features/profile/profile.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<osf-loading-spinner />
} @else {
@if (user()) {
@if (user()?.mergedBy) {
<p-message class="w-full mb-4" severity="info">
<ng-template #container>
<span>
{{ 'profile.mergedAccount.message' | translate }}
<a [href]="user()?.mergedBy">{{ user()?.mergedBy }}</a>
</span>
</ng-template>
</p-message>
}
<osf-profile-information [currentUser]="user()" [showEdit]="isMyProfile()" (editProfile)="toProfileSettings()" />

@if (defaultSearchFiltersInitialized()) {
Expand Down
67 changes: 67 additions & 0 deletions src/app/features/profile/profile.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MockComponents, MockProvider } from 'ng-mocks';

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ActivatedRoute, Router } from '@angular/router';

import { PrerenderReadyService } from '@core/services/prerender-ready.service';
Expand All @@ -13,6 +14,7 @@ import { ProfileInformationComponent } from './components';
import { ProfileComponent } from './profile.component';
import { ProfileSelectors } from './store';

import { MOCK_USER } from '@testing/mocks/data.mock';
import { OSFTestingModule } from '@testing/osf.testing.module';
import { ActivatedRouteMockBuilder } from '@testing/providers/route-provider.mock';
import { RouterMockBuilder } from '@testing/providers/router-provider.mock';
Expand Down Expand Up @@ -78,4 +80,69 @@ describe('ProfileComponent', () => {
expect(component.resourceTabOptions).toBeDefined();
expect(component.resourceTabOptions.every((option) => option.value !== ResourceType.Agent)).toBe(true);
});

describe('merged user message', () => {
it('should display merged message when user has mergedBy property', async () => {
const mergedUser = { ...MOCK_USER, mergedBy: 'https://osf.io/user123/' };

await TestBed.configureTestingModule({
imports: [
ProfileComponent,
OSFTestingModule,
...MockComponents(ProfileInformationComponent, GlobalSearchComponent, LoadingSpinnerComponent),
],
providers: [
MockProvider(Router, routerMock),
MockProvider(ActivatedRoute, activatedRouteMock),
MockProvider(PrerenderReadyService),
provideMockStore({
signals: [
{ selector: UserSelectors.getCurrentUser, value: mergedUser },
{ selector: ProfileSelectors.getUserProfile, value: null },
{ selector: ProfileSelectors.isUserProfileLoading, value: false },
],
}),
],
}).compileComponents();

fixture = TestBed.createComponent(ProfileComponent);
fixture.detectChanges();

const messageElement = fixture.debugElement.query(By.css('p-message'));
expect(messageElement).toBeTruthy();

const linkElement = fixture.debugElement.query(By.css('p-message a'));
expect(linkElement.nativeElement.href).toContain('https://osf.io/user123/');
});

it('should not display merged message when user does not have mergedBy property', async () => {
const normalUser = { ...MOCK_USER, mergedBy: undefined };

await TestBed.configureTestingModule({
imports: [
ProfileComponent,
OSFTestingModule,
...MockComponents(ProfileInformationComponent, GlobalSearchComponent, LoadingSpinnerComponent),
],
providers: [
MockProvider(Router, routerMock),
MockProvider(ActivatedRoute, activatedRouteMock),
MockProvider(PrerenderReadyService),
provideMockStore({
signals: [
{ selector: UserSelectors.getCurrentUser, value: normalUser },
{ selector: ProfileSelectors.getUserProfile, value: null },
{ selector: ProfileSelectors.isUserProfileLoading, value: false },
],
}),
],
}).compileComponents();

fixture = TestBed.createComponent(ProfileComponent);
fixture.detectChanges();

const messageElement = fixture.debugElement.query(By.css('p-message'));
expect(messageElement).toBeFalsy();
});
});
});
6 changes: 5 additions & 1 deletion src/app/features/profile/profile.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { createDispatchMap, select } from '@ngxs/store';

import { TranslatePipe } from '@ngx-translate/core';

import { Message } from 'primeng/message';

import {
ChangeDetectionStrategy,
Component,
Expand Down Expand Up @@ -30,7 +34,7 @@ import { FetchUserProfile, ProfileSelectors, SetUserProfile } from './store';
templateUrl: './profile.component.html',
styleUrl: './profile.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [ProfileInformationComponent, GlobalSearchComponent, LoadingSpinnerComponent],
imports: [ProfileInformationComponent, GlobalSearchComponent, LoadingSpinnerComponent, Message, TranslatePipe],
})
export class ProfileComponent implements OnInit, OnDestroy {
private router = inject(Router);
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/mappers/user/user.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class UserMapper {
canViewReviews: user.attributes.can_view_reviews === true, // [NS] Do not simplify it
timezone: user.attributes.timezone,
locale: user.attributes.locale,
mergedBy: user.links.merged_by,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/app/shared/models/user/user-json-api.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ interface UserLinksJsonApi {
iri: string;
profile_image: string;
self: string;
merged_by?: string;
}

interface UserRelationshipsJsonApi {
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/models/user/user.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ export interface UserModel {
defaultRegionId: string;
link?: string;
iri?: string;
mergedBy?: string;
}
5 changes: 5 additions & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@
"institutions": "Institutions",
"recentActivity": "Recent Activity"
},
"profile": {
"mergedAccount": {
"message": "This account has been merged with "
}
},
"toast": {
"tos-consent": {
"message": "Notice: We've updated our",
Expand Down
1 change: 1 addition & 0 deletions src/testing/mocks/data.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const MOCK_USER: UserModel = {
defaultRegionId: 'us',
allowIndexing: true,
canViewReviews: true,
mergedBy: undefined,
};

export const MOCK_USER_RELATED_COUNTS: UserRelatedCounts = {
Expand Down