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
Expand Up @@ -226,13 +226,15 @@ <h2>{{ 'preprints.preprintStepper.authorAssertions.publicPreregistration.title'
severity="info"
(onClick)="backButtonClicked()"
/>
<p-button
class="w-6 md:w-6rem"
styleClass="w-full"
[label]="'common.buttons.delete' | translate"
severity="danger"
(onClick)="deletePreprint()"
/>
@if (showDeleteButton()) {
<p-button
class="w-6 md:w-6rem"
styleClass="w-full"
[label]="'common.buttons.delete' | translate"
severity="danger"
(onClick)="deletePreprint()"
/>
}
<p-button
class="w-6 md:w-9rem"
styleClass="w-full"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ describe('AuthorAssertionsStepComponent', () => {
expect(controls.preregLinkInfo.value).toBe(PreregLinkInfo.Both);
});

it('should default showDeleteButton to false', () => {
setup();

expect(component.showDeleteButton()).toBe(false);
});

it('should update showDeleteButton when input changes', () => {
setup();

fixture.componentRef.setInput('showDeleteButton', true);
fixture.detectChanges();

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

it('should enable coiStatement control when hasCoi becomes true', () => {
setup({ detectChanges: true });
component.authorAssertionsForm.controls.hasCoi.setValue(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Textarea } from 'primeng/textarea';
import { Tooltip } from 'primeng/tooltip';

import { NgClass } from '@angular/common';
import { ChangeDetectionStrategy, Component, effect, inject, output } from '@angular/core';
import { ChangeDetectionStrategy, Component, effect, inject, input, output } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import {
AbstractControl,
Expand Down Expand Up @@ -124,6 +124,7 @@ export class AuthorAssertionsStepComponent {
initialValue: this.createdPreprint()?.hasPreregLinks ?? ApplicabilityStatus.NotApplicable,
});

showDeleteButton = input(false);
nextClicked = output<void>();
backClicked = output<void>();
deleteClicked = output<void>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,15 @@ <h2>{{ 'preprints.preprintStepper.file.title' | translate }}</h2>
severity="info"
(onClick)="backButtonClicked()"
/>
<p-button
class="w-6 md:w-6rem"
styleClass="w-full"
[label]="'common.buttons.delete' | translate"
severity="danger"
(onClick)="deletePreprint()"
/>
@if (showDeleteButton()) {
<p-button
class="w-6 md:w-6rem"
styleClass="w-full"
[label]="'common.buttons.delete' | translate"
severity="danger"
(onClick)="deletePreprint()"
/>
}
<p-button
class="w-6 md:w-9rem"
styleClass="w-full"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { FilesTreeComponent } from '@osf/shared/components/files-tree/files-tree
import { IconComponent } from '@osf/shared/components/icon/icon.component';
import { FileModel } from '@osf/shared/models/files/file.model';
import { FileFolderModel } from '@osf/shared/models/files/file-folder.model';
import { CustomConfirmationService } from '@osf/shared/services/custom-confirmation.service';
import { ToastService } from '@osf/shared/services/toast.service';

import { FileStepComponent } from './file-step.component';
Expand All @@ -34,10 +33,6 @@ import { OSF_FILE_MOCK } from '@testing/mocks/osf-file.mock';
import { PREPRINT_MOCK } from '@testing/mocks/preprint.mock';
import { PREPRINT_PROVIDER_DETAILS_MOCK } from '@testing/mocks/preprint-provider-details';
import { provideOSFCore } from '@testing/osf.testing.provider';
import {
CustomConfirmationServiceMock,
CustomConfirmationServiceMockType,
} from '@testing/providers/custom-confirmation-provider.mock';
import { mergeSignalOverrides, provideMockStore, SignalOverride } from '@testing/providers/store-provider.mock';
import { ToastServiceMock, ToastServiceMockType } from '@testing/providers/toast-provider.mock';

Expand All @@ -46,7 +41,6 @@ describe('FileStepComponent', () => {
let fixture: ComponentFixture<FileStepComponent>;
let store: Store;
let toastServiceMock: ToastServiceMockType;
let confirmationServiceMock: CustomConfirmationServiceMockType;
const originalPointerEvent = (globalThis as unknown as { PointerEvent?: typeof Event }).PointerEvent;

const mockProvider: PreprintProviderDetails = PREPRINT_PROVIDER_DETAILS_MOCK;
Expand Down Expand Up @@ -81,16 +75,10 @@ describe('FileStepComponent', () => {
}) {
const signals = mergeSignalOverrides(defaultSignals, overrides?.selectorOverrides);
toastServiceMock = ToastServiceMock.simple();
confirmationServiceMock = CustomConfirmationServiceMock.simple();

TestBed.configureTestingModule({
imports: [FileStepComponent, ...MockComponents(IconComponent, FilesTreeComponent)],
providers: [
provideOSFCore(),
MockProvider(ToastService, toastServiceMock),
MockProvider(CustomConfirmationService, confirmationServiceMock),
provideMockStore({ signals }),
],
providers: [provideOSFCore(), MockProvider(ToastService, toastServiceMock), provideMockStore({ signals })],
});

store = TestBed.inject(Store);
Expand Down Expand Up @@ -348,4 +336,19 @@ describe('FileStepComponent', () => {

expect(store.dispatch).toHaveBeenCalledWith(new FetchProjectFilesByLink('/v2/nodes/node-456/files/', 3));
});

it('should default showDeleteButton to false', () => {
setup();

expect(component.showDeleteButton()).toBe(false);
});

it('should update showDeleteButton when input changes', () => {
setup();

fixture.componentRef.setInput('showDeleteButton', true);
fixture.detectChanges();

expect(component.showDeleteButton()).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import { ClearFileDirective } from '@osf/shared/directives/clear-file.directive'
import { StringOrNull } from '@osf/shared/helpers/types.helper';
import { FileModel } from '@osf/shared/models/files/file.model';
import { FileFolderModel } from '@osf/shared/models/files/file-folder.model';
import { CustomConfirmationService } from '@osf/shared/services/custom-confirmation.service';
import { ToastService } from '@osf/shared/services/toast.service';

@Component({
Expand All @@ -71,7 +70,6 @@ import { ToastService } from '@osf/shared/services/toast.service';
})
export class FileStepComponent implements OnInit {
private toastService = inject(ToastService);
private customConfirmationService = inject(CustomConfirmationService);
private destroyRef = inject(DestroyRef);

private actions = createDispatchMap({
Expand All @@ -90,6 +88,7 @@ export class FileStepComponent implements OnInit {
readonly PreprintFileSource = PreprintFileSource;

provider = input.required<PreprintProviderDetails>();
showDeleteButton = input(false);
preprint = select(PreprintStepperSelectors.getPreprint);
selectedFileSource = select(PreprintStepperSelectors.getSelectedFileSource);
fileUploadLink = select(PreprintStepperSelectors.getUploadLink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ <h2 class="mb-4">{{ 'preprints.preprintStepper.metadata.publicationCitationTitle
severity="info"
(onClick)="backButtonClicked()"
/>
<p-button
class="w-6 md:w-6rem"
styleClass="w-full"
[label]="'common.buttons.delete' | translate"
severity="danger"
(onClick)="deletePreprint()"
/>
@if (showDeleteButton()) {
<p-button
class="w-6 md:w-6rem"
styleClass="w-full"
[label]="'common.buttons.delete' | translate"
severity="danger"
(onClick)="deletePreprint()"
/>
}
<p-button
class="w-6 md:w-9rem"
styleClass="w-full"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ describe('PreprintsMetadataStepComponent', () => {
expect(nextClickedSpy).toHaveBeenCalled();
});

it('should default showDeleteButton to false', () => {
setup();

expect(component.showDeleteButton()).toBe(false);
});

it('should update showDeleteButton when input changes', () => {
setup();

fixture.componentRef.setInput('showDeleteButton', true);
fixture.detectChanges();

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

it('should dispatch save license from createLicense', () => {
setup({ detectChanges: false });
component.createLicense({ id: MOCK_LICENSE.id, licenseOptions: { year: '2024', copyrightHolders: 'A' } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class PreprintsMetadataStepComponent implements OnInit {
private toastService = inject(ToastService);

provider = input.required<PreprintProviderDetails>();
showDeleteButton = input(false);
nextClicked = output<void>();
backClicked = output<void>();
deleteClicked = output<void>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,16 @@ <h2>{{ 'preprints.preprintStepper.review.sections.supplements.title' | translate
[disabled]="isPreprintSubmitting()"
(onClick)="cancelSubmission()"
/>
<p-button
class="w-6 md:w-6rem"
styleClass="w-full"
[label]="'common.buttons.delete' | translate"
severity="danger"
[disabled]="isPreprintSubmitting()"
(onClick)="deletePreprint()"
/>
@if (showDeleteButton()) {
<p-button
class="w-6 md:w-6rem"
styleClass="w-full"
[label]="'common.buttons.delete' | translate"
severity="danger"
[disabled]="isPreprintSubmitting()"
(onClick)="deletePreprint()"
/>
}
<p-button
data-test-submit-button
class="w-6 md:w-9rem"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,19 @@ describe('ReviewStepComponent', () => {

expect(emitSpy).toHaveBeenCalled();
});

it('should default showDeleteButton to false', () => {
setup();

expect(component.showDeleteButton()).toBe(false);
});

it('should update showDeleteButton when input changes', () => {
setup();

fixture.componentRef.setInput('showDeleteButton', true);
fixture.detectChanges();

expect(component.showDeleteButton()).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class ReviewStepComponent implements OnInit {
private readonly toastService = inject(ToastService);

readonly provider = input.required<PreprintProviderDetails>();
readonly showDeleteButton = input(false);
readonly deleteClicked = output<void>();

private readonly actions = createDispatchMap({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ <h2>{{ 'preprints.preprintStepper.supplements.title' | translate }}</h2>
severity="info"
(onClick)="backButtonClicked()"
/>
<p-button
class="w-6 md:w-6rem"
styleClass="w-full"
[label]="'common.buttons.delete' | translate"
severity="danger"
[disabled]="isPreprintSubmitting()"
(onClick)="deletePreprint()"
/>
@if (showDeleteButton()) {
<p-button
class="w-6 md:w-6rem"
styleClass="w-full"
[label]="'common.buttons.delete' | translate"
severity="danger"
[disabled]="isPreprintSubmitting()"
(onClick)="deletePreprint()"
/>
}
<p-button
class="w-6 md:w-9rem"
styleClass="w-full"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ describe('SupplementsStepComponent', () => {
expect(store.dispatch).not.toHaveBeenCalledWith(expect.any(FetchPreprintProject));
});

it('should default showDeleteButton to false', () => {
setup();

expect(component.showDeleteButton()).toBe(false);
});

it('should update showDeleteButton when input changes', () => {
setup();

fixture.componentRef.setInput('showDeleteButton', true);
fixture.detectChanges();

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

it('should dispatch available projects from debounced project search', fakeAsync(() => {
setup();
(store.dispatch as jest.Mock).mockClear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
DestroyRef,
effect,
inject,
input,
OnInit,
output,
signal,
Expand Down Expand Up @@ -83,6 +84,7 @@ export class SupplementsStepComponent implements OnInit {
selectedSupplementOption = signal<SupplementOptions>(SupplementOptions.None);
selectedProjectId = signal<StringOrNull>(null);

showDeleteButton = input(false);
nextClicked = output<void>();
backClicked = output<void>();
deleteClicked = output<void>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ <h2>{{ 'preprints.preprintStepper.titleAndAbstract.title' | translate }}</h2>
severity="info"
[routerLink]="['/preprints', providerId(), 'discover']"
/>
@if (showDeleteButton()) {
<p-button
class="w-6 md:w-6rem"
styleClass="w-full"
[label]="'common.buttons.delete' | translate"
severity="danger"
(onClick)="deletePreprint()"
/>
}
<p-button
data-test-next-button
class="w-6 md:w-9rem"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ describe('TitleAndAbstractStepComponent', () => {
expect(component.titleAndAbstractForm.controls.description.value).toBe(mockPreprint.description);
});

it('should default showDeleteButton to false', () => {
setup();

expect(component.showDeleteButton()).toBe(false);
});

it('should update showDeleteButton when input changes', () => {
setup();

fixture.componentRef.setInput('showDeleteButton', true);
fixture.detectChanges();

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

it('should not dispatch or emit when form is invalid', () => {
setup();
const emitSpy = jest.spyOn(component.nextClicked, 'emit');
Expand Down Expand Up @@ -118,4 +133,13 @@ describe('TitleAndAbstractStepComponent', () => {

expect(emitSpy).toHaveBeenCalled();
});

it('should emit deleteClicked when deletePreprint is called', () => {
setup();
const emitSpy = jest.spyOn(component.deleteClicked, 'emit');

component.deletePreprint();

expect(emitSpy).toHaveBeenCalled();
});
});
Loading
Loading