From 7d8066381b9c439f3999a310a6e42922cb196c16 Mon Sep 17 00:00:00 2001 From: nsemets Date: Fri, 23 Jan 2026 15:26:41 +0200 Subject: [PATCH] fix(preprint-contributors): fixed issue with removed contributors --- .../preprints/mappers/preprints.mapper.ts | 22 ++++------ .../preprints/models/preprint.models.ts | 4 +- .../my-preprints/my-preprints.component.html | 2 +- .../my-preprints.component.spec.ts | 4 +- .../my-preprints/my-preprints.component.ts | 4 +- .../features/search/search.component.spec.ts | 27 ++++++------ ...ontributors-list-shortener.component.html} | 5 ++- ...ontributors-list-shortener.component.scss} | 0 ...ributors-list-shortener.component.spec.ts} | 14 +++---- .../contributors-list-shortener.component.ts | 19 +++++++++ .../list-info-shortener.component.ts | 19 --------- .../my-projects-table.component.html | 6 +-- .../my-projects-table.component.spec.ts | 5 ++- .../my-projects-table.component.ts | 4 +- .../recent-activity-list.component.html | 6 ++- src/testing/mocks/preprint-short-info.mock.ts | 42 +++---------------- 16 files changed, 77 insertions(+), 106 deletions(-) rename src/app/shared/components/{list-info-shortener/list-info-shortener.component.html => contributors-list-shortener/contributors-list-shortener.component.html} (88%) rename src/app/shared/components/{list-info-shortener/list-info-shortener.component.scss => contributors-list-shortener/contributors-list-shortener.component.scss} (100%) rename src/app/shared/components/{list-info-shortener/list-info-shortener.component.spec.ts => contributors-list-shortener/contributors-list-shortener.component.spec.ts} (64%) create mode 100644 src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.ts delete mode 100644 src/app/shared/components/list-info-shortener/list-info-shortener.component.ts diff --git a/src/app/features/preprints/mappers/preprints.mapper.ts b/src/app/features/preprints/mappers/preprints.mapper.ts index 51ead14da..61dd10329 100644 --- a/src/app/features/preprints/mappers/preprints.mapper.ts +++ b/src/app/features/preprints/mappers/preprints.mapper.ts @@ -1,4 +1,5 @@ import { StringOrNull } from '@osf/shared/helpers/types.helper'; +import { ContributorsMapper } from '@osf/shared/mappers/contributors'; import { IdentifiersMapper } from '@osf/shared/mappers/identifiers.mapper'; import { LicensesMapper } from '@osf/shared/mappers/licenses.mapper'; import { ApiData, JsonApiResponseWithMeta, ResponseJsonApi } from '@osf/shared/models/common/json-api.model'; @@ -170,20 +171,13 @@ export class PreprintsMapper { > ): PreprintShortInfoWithTotalCount { return { - data: response.data.map((preprintData) => { - return { - id: preprintData.id, - title: replaceBadEncodedChars(preprintData.attributes.title), - dateModified: preprintData.attributes.date_modified, - contributors: preprintData.embeds.bibliographic_contributors.data.map((contrData) => { - return { - id: contrData.id, - name: contrData.embeds.users.data.attributes.full_name, - }; - }), - providerId: preprintData.relationships.provider.data.id, - }; - }), + data: response.data.map((preprintData) => ({ + id: preprintData.id, + title: replaceBadEncodedChars(preprintData.attributes.title), + dateModified: preprintData.attributes.date_modified, + contributors: ContributorsMapper.getContributors(preprintData.embeds?.bibliographic_contributors?.data), + providerId: preprintData.relationships.provider.data.id, + })), totalCount: response.meta.total, }; } diff --git a/src/app/features/preprints/models/preprint.models.ts b/src/app/features/preprints/models/preprint.models.ts index f4ad604b4..527c1a76d 100644 --- a/src/app/features/preprints/models/preprint.models.ts +++ b/src/app/features/preprints/models/preprint.models.ts @@ -1,6 +1,6 @@ import { UserPermissions } from '@osf/shared/enums/user-permissions.enum'; import { BooleanOrNull, StringOrNull } from '@osf/shared/helpers/types.helper'; -import { IdNameModel } from '@shared/models/common/id-name.model'; +import { ContributorModel } from '@osf/shared/models/contributors/contributor.model'; import { IdentifierModel } from '@shared/models/identifiers/identifier.model'; import { LicenseModel, LicenseOptions } from '@shared/models/license/license.model'; @@ -57,7 +57,7 @@ export interface PreprintShortInfo { id: string; title: string; dateModified: string; - contributors: IdNameModel[]; + contributors: ContributorModel[]; providerId: string; } diff --git a/src/app/features/preprints/pages/my-preprints/my-preprints.component.html b/src/app/features/preprints/pages/my-preprints/my-preprints.component.html index a5f24cdcf..3bb682bad 100644 --- a/src/app/features/preprints/pages/my-preprints/my-preprints.component.html +++ b/src/app/features/preprints/pages/my-preprints/my-preprints.component.html @@ -54,7 +54,7 @@ {{ item.title | fixSpecialChar }} - + {{ item.dateModified | date: 'MMM d, y, h:mm a' }} diff --git a/src/app/features/preprints/pages/my-preprints/my-preprints.component.spec.ts b/src/app/features/preprints/pages/my-preprints/my-preprints.component.spec.ts index 9045aeb8a..b907ff6a1 100644 --- a/src/app/features/preprints/pages/my-preprints/my-preprints.component.spec.ts +++ b/src/app/features/preprints/pages/my-preprints/my-preprints.component.spec.ts @@ -6,7 +6,7 @@ import { TitleCasePipe } from '@angular/common'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ActivatedRoute, Router } from '@angular/router'; -import { ListInfoShortenerComponent } from '@osf/shared/components/list-info-shortener/list-info-shortener.component'; +import { ContributorsListShortenerComponent } from '@osf/shared/components/contributors-list-shortener/contributors-list-shortener.component'; import { SearchInputComponent } from '@osf/shared/components/search-input/search-input.component'; import { SubHeaderComponent } from '@osf/shared/components/sub-header/sub-header.component'; import { DEFAULT_TABLE_PARAMS } from '@osf/shared/constants/default-table-params.constants'; @@ -54,7 +54,7 @@ describe('MyPreprintsComponent', () => { imports: [ MyPreprintsComponent, OSFTestingModule, - ...MockComponents(SubHeaderComponent, SearchInputComponent, ListInfoShortenerComponent), + ...MockComponents(SubHeaderComponent, SearchInputComponent, ContributorsListShortenerComponent), MockPipe(TitleCasePipe), ], providers: [ diff --git a/src/app/features/preprints/pages/my-preprints/my-preprints.component.ts b/src/app/features/preprints/pages/my-preprints/my-preprints.component.ts index 6f6d346b4..f85efb139 100644 --- a/src/app/features/preprints/pages/my-preprints/my-preprints.component.ts +++ b/src/app/features/preprints/pages/my-preprints/my-preprints.component.ts @@ -23,7 +23,7 @@ import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop'; import { FormControl } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; -import { ListInfoShortenerComponent } from '@osf/shared/components/list-info-shortener/list-info-shortener.component'; +import { ContributorsListShortenerComponent } from '@osf/shared/components/contributors-list-shortener/contributors-list-shortener.component'; import { SearchInputComponent } from '@osf/shared/components/search-input/search-input.component'; import { SubHeaderComponent } from '@osf/shared/components/sub-header/sub-header.component'; import { DEFAULT_TABLE_PARAMS } from '@osf/shared/constants/default-table-params.constants'; @@ -46,7 +46,7 @@ import { FetchMyPreprints, MyPreprintsSelectors } from '../../store/my-preprints TableModule, Skeleton, DatePipe, - ListInfoShortenerComponent, + ContributorsListShortenerComponent, TitleCasePipe, FixSpecialCharPipe, ], diff --git a/src/app/features/search/search.component.spec.ts b/src/app/features/search/search.component.spec.ts index bbc554ebc..1c6eec014 100644 --- a/src/app/features/search/search.component.spec.ts +++ b/src/app/features/search/search.component.spec.ts @@ -1,31 +1,21 @@ -import { Store } from '@ngxs/store'; - import { MockComponent } from 'ng-mocks'; -import { of } from 'rxjs'; - -import { signal } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { GlobalSearchComponent } from '@osf/shared/components/global-search/global-search.component'; +import { SEARCH_TAB_OPTIONS } from '@osf/shared/constants/search-tab-options.const'; import { SearchComponent } from './search.component'; -describe.skip('SearchComponent', () => { +describe('SearchComponent', () => { let component: SearchComponent; let fixture: ComponentFixture; - let store: Store; beforeEach(async () => { await TestBed.configureTestingModule({ imports: [SearchComponent, MockComponent(GlobalSearchComponent)], - providers: [], }).compileComponents(); - store = TestBed.inject(Store); - jest.spyOn(store, 'selectSignal').mockReturnValue(signal('')); - jest.spyOn(store, 'dispatch').mockReturnValue(of(undefined)); - fixture = TestBed.createComponent(SearchComponent); component = fixture.componentInstance; fixture.detectChanges(); @@ -34,4 +24,17 @@ describe.skip('SearchComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should initialize searchTabOptions with SEARCH_TAB_OPTIONS', () => { + expect(component.searchTabOptions).toEqual(SEARCH_TAB_OPTIONS); + }); + + it('should render template with correct structure', () => { + const hostElement = fixture.debugElement.nativeElement; + const containerDiv = hostElement.querySelector('div.mt-6.pt-5'); + expect(containerDiv).toBeTruthy(); + + const globalSearch = containerDiv.querySelector('osf-global-search'); + expect(globalSearch).toBeTruthy(); + }); }); diff --git a/src/app/shared/components/list-info-shortener/list-info-shortener.component.html b/src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.html similarity index 88% rename from src/app/shared/components/list-info-shortener/list-info-shortener.component.html rename to src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.html index 98e915ea2..4f5e22852 100644 --- a/src/app/shared/components/list-info-shortener/list-info-shortener.component.html +++ b/src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.html @@ -4,17 +4,18 @@ @if (dataValue && dataValue.length > 0) {
@for (item of dataValue.slice(0, limitValue); track item.id) { - {{ item.name }}{{ $last ? '' : ', ' }} + {{ item.fullName }}{{ $last ? '' : ', ' }} } @if (dataValue.length > limitValue) {

{{ 'common.labels.and' | translate }} {{ dataValue.length - limitValue }} {{ 'common.labels.more' | translate }}

+ @for (item of dataValue.slice(limitValue); track item.id) {
- {{ item.name }} + {{ item.fullName }}
}
diff --git a/src/app/shared/components/list-info-shortener/list-info-shortener.component.scss b/src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.scss similarity index 100% rename from src/app/shared/components/list-info-shortener/list-info-shortener.component.scss rename to src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.scss diff --git a/src/app/shared/components/list-info-shortener/list-info-shortener.component.spec.ts b/src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.spec.ts similarity index 64% rename from src/app/shared/components/list-info-shortener/list-info-shortener.component.spec.ts rename to src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.spec.ts index 8e6e76746..28390cbf9 100644 --- a/src/app/shared/components/list-info-shortener/list-info-shortener.component.spec.ts +++ b/src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.spec.ts @@ -2,19 +2,19 @@ import { ComponentRef } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { ListInfoShortenerComponent } from './list-info-shortener.component'; +import { ContributorsListShortenerComponent } from './contributors-list-shortener.component'; -describe('ListInfoShortenerComponent', () => { - let component: ListInfoShortenerComponent; - let fixture: ComponentFixture; - let componentRef: ComponentRef; +describe('ContributorsListShortenerComponent', () => { + let component: ContributorsListShortenerComponent; + let fixture: ComponentFixture; + let componentRef: ComponentRef; beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [ListInfoShortenerComponent], + imports: [ContributorsListShortenerComponent], }).compileComponents(); - fixture = TestBed.createComponent(ListInfoShortenerComponent); + fixture = TestBed.createComponent(ContributorsListShortenerComponent); component = fixture.componentInstance; componentRef = fixture.componentRef; }); diff --git a/src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.ts b/src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.ts new file mode 100644 index 000000000..793ee2149 --- /dev/null +++ b/src/app/shared/components/contributors-list-shortener/contributors-list-shortener.component.ts @@ -0,0 +1,19 @@ +import { TranslatePipe } from '@ngx-translate/core'; + +import { Tooltip } from 'primeng/tooltip'; + +import { ChangeDetectionStrategy, Component, input } from '@angular/core'; + +import { ContributorModel } from '@osf/shared/models/contributors/contributor.model'; + +@Component({ + selector: 'osf-contributors-list-shortener', + imports: [Tooltip, TranslatePipe], + templateUrl: './contributors-list-shortener.component.html', + styleUrl: './contributors-list-shortener.component.scss', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class ContributorsListShortenerComponent { + data = input([]); + limit = input(2); +} diff --git a/src/app/shared/components/list-info-shortener/list-info-shortener.component.ts b/src/app/shared/components/list-info-shortener/list-info-shortener.component.ts deleted file mode 100644 index 6de6cd5e9..000000000 --- a/src/app/shared/components/list-info-shortener/list-info-shortener.component.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { TranslatePipe } from '@ngx-translate/core'; - -import { Tooltip } from 'primeng/tooltip'; - -import { ChangeDetectionStrategy, Component, input } from '@angular/core'; - -import { IdNameModel } from '@osf/shared/models/common/id-name.model'; - -@Component({ - selector: 'osf-list-info-shortener', - imports: [Tooltip, TranslatePipe], - templateUrl: './list-info-shortener.component.html', - styleUrl: './list-info-shortener.component.scss', - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class ListInfoShortenerComponent { - data = input([]); - limit = input(2); -} diff --git a/src/app/shared/components/my-projects-table/my-projects-table.component.html b/src/app/shared/components/my-projects-table/my-projects-table.component.html index f67b93b39..15d83dd59 100644 --- a/src/app/shared/components/my-projects-table/my-projects-table.component.html +++ b/src/app/shared/components/my-projects-table/my-projects-table.component.html @@ -39,13 +39,11 @@

- {{ item.title | fixSpecialChar }} + {{ item.title }}

- @for (contributor of item.contributors; track contributor) { - {{ contributor.fullName }}{{ $last ? '' : ', ' }} - } + {{ item.dateModified | date: 'MMM d, y, h:mm a' }} diff --git a/src/app/shared/components/my-projects-table/my-projects-table.component.spec.ts b/src/app/shared/components/my-projects-table/my-projects-table.component.spec.ts index b750bf06d..5aa148c0e 100644 --- a/src/app/shared/components/my-projects-table/my-projects-table.component.spec.ts +++ b/src/app/shared/components/my-projects-table/my-projects-table.component.spec.ts @@ -1,4 +1,4 @@ -import { MockComponent } from 'ng-mocks'; +import { MockComponents } from 'ng-mocks'; import { ComponentFixture, TestBed } from '@angular/core/testing'; @@ -6,6 +6,7 @@ import { SortOrder } from '@osf/shared/enums/sort-order.enum'; import { TableParameters } from '@osf/shared/models/table-parameters.model'; import { MyResourcesItem } from '@shared/models/my-resources/my-resources.models'; +import { ContributorsListShortenerComponent } from '../contributors-list-shortener/contributors-list-shortener.component'; import { IconComponent } from '../icon/icon.component'; import { MyProjectsTableComponent } from './my-projects-table.component'; @@ -42,7 +43,7 @@ describe('MyProjectsTableComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [MyProjectsTableComponent, MockComponent(IconComponent)], + imports: [MyProjectsTableComponent, ...MockComponents(IconComponent, ContributorsListShortenerComponent)], providers: [TranslateServiceMock], }).compileComponents(); diff --git a/src/app/shared/components/my-projects-table/my-projects-table.component.ts b/src/app/shared/components/my-projects-table/my-projects-table.component.ts index 8d868ea60..22472efb9 100644 --- a/src/app/shared/components/my-projects-table/my-projects-table.component.ts +++ b/src/app/shared/components/my-projects-table/my-projects-table.component.ts @@ -10,13 +10,13 @@ import { ChangeDetectionStrategy, Component, input, output } from '@angular/core import { SortOrder } from '@osf/shared/enums/sort-order.enum'; import { MyResourcesItem } from '@osf/shared/models/my-resources/my-resources.models'; import { TableParameters } from '@osf/shared/models/table-parameters.model'; -import { FixSpecialCharPipe } from '@osf/shared/pipes/fix-special-char.pipe'; +import { ContributorsListShortenerComponent } from '../contributors-list-shortener/contributors-list-shortener.component'; import { IconComponent } from '../icon/icon.component'; @Component({ selector: 'osf-my-projects-table', - imports: [CommonModule, TableModule, IconComponent, Skeleton, TranslatePipe, FixSpecialCharPipe], + imports: [CommonModule, TableModule, IconComponent, Skeleton, TranslatePipe, ContributorsListShortenerComponent], templateUrl: './my-projects-table.component.html', styleUrl: './my-projects-table.component.scss', changeDetection: ChangeDetectionStrategy.OnPush, diff --git a/src/app/shared/components/recent-activity/recent-activity-list.component.html b/src/app/shared/components/recent-activity/recent-activity-list.component.html index 409006aa3..8ec859417 100644 --- a/src/app/shared/components/recent-activity/recent-activity-list.component.html +++ b/src/app/shared/components/recent-activity/recent-activity-list.component.html @@ -5,7 +5,11 @@ class="activity-item flex justify-content-between align-items-center gap-2 pb-2 px-3" data-test="recent-activity-item" > -
+