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
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<div class="resource">
<p-accordion (onOpen)="handleOpen()">
<p-accordion-panel value="0">
<p-accordion-header class="flex flex-row align-items-start gap-3 p-3">
<p-accordion-header
class="flex flex-row align-items-start gap-3 p-3"
[pt]="{
root: { role: 'presentation', tabindex: -1, 'aria-expanded': null },
}"
>
<div osfStopPropagation class="flex align-items-baseline gap-2 font-normal">
<osf-icon [class]="reviewStatusIcon[status()].value" [iconClass]="reviewStatusIcon[status()].icon"></osf-icon>

Expand All @@ -10,7 +15,7 @@
class="link-btn-no-padding"
styleClass="text-left"
link
[label]="submission().title | fixSpecialChar"
[label]="submission().title"
(onClick)="selected.emit()"
/>
@for (action of showAll ? visibleActions() : visibleActions().slice(0, limitValue); track $index) {
Expand All @@ -36,9 +41,25 @@
}
</div>
</div>

<ng-template #toggleicon let-active="active">
<button
type="button"
class="submission-accordion-toggle"
[attr.aria-expanded]="active"
[attr.aria-label]="'common.labels.contributors' | translate"
>
<i
class="p-icon pi"
[class.pi-chevron-up]="active"
[class.pi-chevron-down]="!active"
aria-hidden="true"
></i>
</button>
</ng-template>
</p-accordion-header>

<p-accordion-content>
<p-accordion-content [pt]="{ root: { role: null, 'aria-labelledby': null } }">
<div class="flex align-content-start gap-1 p-3 pt-0 ml-3">
<p>{{ 'common.labels.contributors' | translate }}:</p>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.submission-link {
color: var(--dark-blue-1);
.submission-accordion-toggle {
display: inline-flex;
align-items: center;
justify-content: center;
margin: 0;
padding: 0;
border: none;
background: transparent;
cursor: pointer;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { MockComponents, MockPipe } from 'ng-mocks';

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

import { ContributorsListComponent } from '@osf/shared/components/contributors-list/contributors-list.component';
import { IconComponent } from '@osf/shared/components/icon/icon.component';
import { TruncatedTextComponent } from '@osf/shared/components/truncated-text/truncated-text.component';
import { ReviewActionTrigger } from '@osf/shared/enums/trigger-action.enum';
import { DateAgoPipe } from '@osf/shared/pipes/date-ago.pipe';

import { MOCK_PREPRINT_SUBMISSION } from '@testing/mocks/submission.mock';
Expand All @@ -24,7 +27,7 @@ describe('PreprintSubmissionItemComponent', () => {
TestBed.configureTestingModule({
imports: [
PreprintSubmissionItemComponent,
...MockComponents(IconComponent, ContributorsListComponent),
...MockComponents(IconComponent, ContributorsListComponent, TruncatedTextComponent),
MockPipe(DateAgoPipe),
],
providers: [provideOSFCore()],
Expand All @@ -37,26 +40,6 @@ describe('PreprintSubmissionItemComponent', () => {
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should have input values', () => {
expect(component.status()).toBe(SubmissionReviewStatus.Pending);
expect(component.submission()).toEqual(mockSubmission);
});

it('should have constants defined', () => {
expect(component.reviewStatusIcon).toBeDefined();
expect(component.actionLabel).toBeDefined();
expect(component.actionState).toBeDefined();
});

it('should have default values', () => {
expect(component.limitValue).toBe(1);
expect(component.showAll).toBe(false);
});

it('should toggle history', () => {
expect(component.showAll).toBe(false);

Expand All @@ -67,38 +50,68 @@ describe('PreprintSubmissionItemComponent', () => {
expect(component.showAll).toBe(false);
});

it('should emit selected event', () => {
vi.spyOn(component.selected, 'emit');
component.selected.emit();
expect(component.selected.emit).toHaveBeenCalled();
it('should emit selected when title button is clicked', () => {
const selectedSpy = vi.fn();
component.selected.subscribe(selectedSpy);

fixture.debugElement.query(By.css('p-button')).triggerEventHandler('onClick', null);

expect(selectedSpy).toHaveBeenCalled();
});

it('should emit loadContributors when accordion opens', () => {
const loadContributorsSpy = vi.fn();
component.loadContributors.subscribe(loadContributorsSpy);

fixture.debugElement.query(By.css('p-accordion')).triggerEventHandler('onOpen', null);

expect(loadContributorsSpy).toHaveBeenCalled();
});

it('should emit loadMoreContributors from contributors list', () => {
const loadMoreSpy = vi.fn();
component.loadMoreContributors.subscribe(loadMoreSpy);

fixture.debugElement
.query(By.directive(ContributorsListComponent))
.triggerEventHandler('loadMoreContributors', null);

expect(loadMoreSpy).toHaveBeenCalled();
});

it('should accept custom input values', () => {
const customStatus = SubmissionReviewStatus.Accepted;
const customSubmission = {
it('should exclude report spam actions from visibleActions', () => {
fixture.componentRef.setInput('submission', {
...mockSubmission,
title: 'Custom Preprint',
actions: [
...mockSubmission.actions,
{
id: '2',
trigger: 'manual',
trigger: ReviewActionTrigger.ReportSpam,
fromState: 'pending',
toState: 'accepted',
toState: 'pending',
dateModified: '2023-01-02',
creator: {
id: 'user-2',
name: 'Jane Doe',
},
comment: 'Approved',
creator: { id: 'user-2', name: 'Jane Doe' },
comment: '',
},
],
};
});
fixture.detectChanges();

fixture.componentRef.setInput('status', customStatus);
fixture.componentRef.setInput('submission', customSubmission);
expect(component.visibleActions()).toHaveLength(1);
expect(component.visibleActions()[0].id).toBe('1');
});

it('should report hasMoreContributors when total exceeds loaded', () => {
fixture.componentRef.setInput('submission', {
...mockSubmission,
totalContributors: 5,
});
fixture.detectChanges();

expect(component.hasMoreContributors()).toBe(true);
});

expect(component.status()).toBe(customStatus);
expect(component.submission()).toEqual(customSubmission);
it('should not report hasMoreContributors when all contributors are loaded', () => {
expect(component.hasMoreContributors()).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import { TruncatedTextComponent } from '@osf/shared/components/truncated-text/tr
import { StopPropagationDirective } from '@osf/shared/directives/stop-propagation.directive';
import { ReviewActionTrigger } from '@osf/shared/enums/trigger-action.enum';
import { DateAgoPipe } from '@osf/shared/pipes/date-ago.pipe';
import { FixSpecialCharPipe } from '@osf/shared/pipes/fix-special-char.pipe';

import { PREPRINT_ACTION_LABEL, ReviewStatusIcon } from '../../constants';
import { ActionStatus, SubmissionReviewStatus } from '../../enums';
import { SubmissionReviewStatus } from '../../enums';
import { PreprintSubmissionModel, PreprintWithdrawalSubmission } from '../../models';

@Component({
Expand All @@ -31,31 +30,29 @@ import { PreprintSubmissionModel, PreprintWithdrawalSubmission } from '../../mod
AccordionContent,
ContributorsListComponent,
StopPropagationDirective,
FixSpecialCharPipe,
],
templateUrl: './preprint-submission-item.component.html',
styleUrl: './preprint-submission-item.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PreprintSubmissionItemComponent {
status = input.required<SubmissionReviewStatus>();
submission = input.required<PreprintSubmissionModel | PreprintWithdrawalSubmission>();
selected = output<void>();
loadContributors = output<void>();
loadMoreContributors = output<void>();
readonly status = input.required<SubmissionReviewStatus>();
readonly submission = input.required<PreprintSubmissionModel | PreprintWithdrawalSubmission>();
readonly selected = output<void>();
readonly loadContributors = output<void>();
readonly loadMoreContributors = output<void>();

readonly reviewStatusIcon = ReviewStatusIcon;
readonly actionLabel = PREPRINT_ACTION_LABEL;
readonly actionState = ActionStatus;

readonly limitValue = 1;
showAll = false;

readonly visibleActions = computed(() =>
this.submission().actions.filter((action) => action.trigger !== ReviewActionTrigger.ReportSpam)
);

limitValue = 1;
showAll = false;

hasMoreContributors = computed(() => {
readonly hasMoreContributors = computed(() => {
const submission = this.submission();
return submission.contributors.length < submission.totalContributors;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
<div class="w-full md:w-4">
<osf-select
[options]="sortOptions"
[placeholder]="'files.sort.placeholder' | translate"
[placeholder]="'files.sort.placeholder'"
[fullWidth]="true"
[(selectedValue)]="selectedSortOption"
(changeValue)="changeSort($event)"
[disabled]="isLoading()"
[selectedValue]="selectedSortOption()"
(changeValue)="changeSort($event)"
></osf-select>
</div>
</div>
Expand All @@ -34,7 +34,7 @@
} @else {
@if (submissions().length) {
<div class="submission-container mt-5">
@for (item of submissions(); track $index) {
@for (item of submissions(); track item.id) {
<div class="submission-item">
<osf-preprint-submission-item
[submission]="item"
Expand Down
Loading
Loading