Skip to content
Merged
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
22 changes: 8 additions & 14 deletions src/app/features/preprints/mappers/preprints.mapper.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/features/preprints/models/preprint.models.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -57,7 +57,7 @@ export interface PreprintShortInfo {
id: string;
title: string;
dateModified: string;
contributors: IdNameModel[];
contributors: ContributorModel[];
providerId: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<tr class="cursor-pointer" (click)="navigateToPreprintDetails(item)">
<td>{{ item.title | fixSpecialChar }}</td>
<td>
<osf-list-info-shortener [data]="item.contributors" />
<osf-contributors-list-shortener [data]="item.contributors" />
</td>
<td>{{ item.dateModified | date: 'MMM d, y, h:mm a' }}</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('MyPreprintsComponent', () => {
imports: [
MyPreprintsComponent,
OSFTestingModule,
...MockComponents(SubHeaderComponent, SearchInputComponent, ListInfoShortenerComponent),
...MockComponents(SubHeaderComponent, SearchInputComponent, ContributorsListShortenerComponent),
MockPipe(TitleCasePipe),
],
providers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -46,7 +46,7 @@ import { FetchMyPreprints, MyPreprintsSelectors } from '../../store/my-preprints
TableModule,
Skeleton,
DatePipe,
ListInfoShortenerComponent,
ContributorsListShortenerComponent,
TitleCasePipe,
FixSpecialCharPipe,
],
Expand Down
27 changes: 15 additions & 12 deletions src/app/features/search/search.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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<SearchComponent>;
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();
Expand All @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
@if (dataValue && dataValue.length > 0) {
<div class="flex flex-row gap-1">
@for (item of dataValue.slice(0, limitValue); track item.id) {
{{ item.name }}{{ $last ? '' : ', ' }}
{{ item.fullName }}{{ $last ? '' : ', ' }}
}

@if (dataValue.length > limitValue) {
<p [pTooltip]="tooltipData" tooltipPosition="bottom" autoHide="false">
{{ 'common.labels.and' | translate }} {{ dataValue.length - limitValue }} {{ 'common.labels.more' | translate }}
</p>

<ng-template #tooltipData>
@for (item of dataValue.slice(limitValue); track item.id) {
<div>
{{ item.name }}
{{ item.fullName }}
</div>
}
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ListInfoShortenerComponent>;
let componentRef: ComponentRef<ListInfoShortenerComponent>;
describe('ContributorsListShortenerComponent', () => {
let component: ContributorsListShortenerComponent;
let fixture: ComponentFixture<ContributorsListShortenerComponent>;
let componentRef: ComponentRef<ContributorsListShortenerComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ListInfoShortenerComponent],
imports: [ContributorsListShortenerComponent],
}).compileComponents();

fixture = TestBed.createComponent(ListInfoShortenerComponent);
fixture = TestBed.createComponent(ContributorsListShortenerComponent);
component = fixture.componentInstance;
componentRef = fixture.componentRef;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ContributorModel[]>([]);
limit = input<number>(2);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@
<td>
<p class="flex align-items-center gap-2">
<osf-icon [iconClass]="item.isPublic ? 'fas fa-lock-open' : 'fas fa-lock'"></osf-icon>
<span class="overflow-ellipsis">{{ item.title | fixSpecialChar }}</span>
<span class="overflow-ellipsis">{{ item.title }}</span>
</p>
</td>
<td>
@for (contributor of item.contributors; track contributor) {
{{ contributor.fullName }}{{ $last ? '' : ', ' }}
}
<osf-contributors-list-shortener [data]="item.contributors" />
</td>
<td>{{ item.dateModified | date: 'MMM d, y, h:mm a' }}</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { MockComponent } from 'ng-mocks';
import { MockComponents } from 'ng-mocks';

import { ComponentFixture, TestBed } from '@angular/core/testing';

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';
Expand Down Expand Up @@ -42,7 +43,7 @@ describe('MyProjectsTableComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MyProjectsTableComponent, MockComponent(IconComponent)],
imports: [MyProjectsTableComponent, ...MockComponents(IconComponent, ContributorsListShortenerComponent)],
providers: [TranslateServiceMock],
}).compileComponents();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<div [innerHTML]="activityLog.formattedActivity" data-test="recent-activity-item-content"></div>
<div
class="word-break-word"
[innerHTML]="activityLog.formattedActivity"
data-test="recent-activity-item-content"
></div>

<p class="activity-date hidden text-right sm:block" data-test="recent-activity-item-date">
{{ activityLog.date | date: 'MMM d, y hh:mm a' }}
Expand Down
42 changes: 6 additions & 36 deletions src/testing/mocks/preprint-short-info.mock.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
import { PreprintShortInfo } from '@osf/features/preprints/models';

import { MOCK_CONTRIBUTOR, MOCK_CONTRIBUTOR_WITHOUT_HISTORY } from './contributors.mock';

export const PREPRINT_SHORT_INFO_ARRAY_MOCK: PreprintShortInfo[] = [
{
id: 'preprint-1',
title: 'Test Preprint 1',
dateModified: '2024-01-01T00:00:00Z',
contributors: [
{
id: 'user-1',
name: 'John Doe',
},
],
contributors: [MOCK_CONTRIBUTOR, MOCK_CONTRIBUTOR_WITHOUT_HISTORY],
providerId: 'provider-1',
},
{
id: 'preprint-2',
title: 'Test Preprint 2',
dateModified: '2024-01-02T00:00:00Z',
contributors: [
{
id: 'user-2',
name: 'Jane Smith',
},
{
id: 'user-3',
name: 'Bob Wilson',
},
],
contributors: [MOCK_CONTRIBUTOR, MOCK_CONTRIBUTOR_WITHOUT_HISTORY],
providerId: 'provider-2',
},
{
Expand All @@ -40,32 +28,14 @@ export const PREPRINT_SHORT_INFO_ARRAY_MOCK: PreprintShortInfo[] = [
id: 'preprint-4',
title: 'Test Preprint 4',
dateModified: '2024-01-04T00:00:00Z',
contributors: [
{
id: 'user-4',
name: 'Alice Johnson',
},
],
contributors: [MOCK_CONTRIBUTOR],
providerId: 'provider-3',
},
{
id: 'preprint-5',
title: 'Test Preprint 5',
dateModified: '2024-01-05T00:00:00Z',
contributors: [
{
id: 'user-5',
name: 'Charlie Brown',
},
{
id: 'user-6',
name: 'Diana Prince',
},
{
id: 'user-7',
name: 'Eve Adams',
},
],
contributors: [MOCK_CONTRIBUTOR],
providerId: 'provider-2',
},
];