Skip to content

Commit 163bdbf

Browse files
[DSC-1924] finalize implementation, add tests
1 parent 6e74702 commit 163bdbf

6 files changed

Lines changed: 435 additions & 60 deletions

File tree

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
<div class="w-100 d-flex mt-1 mb-3 align-items-start">
1+
<div
2+
*ngIf="!(processing$ | async); else loading"
3+
class="w-100 d-flex mt-1 mb-3 align-items-start"
4+
>
25
<button
36
type="button"
47
class="btn btn-info mr-2"
58
ngbTooltip="{{'submission.workflow.tasks.pool.claim_selected_help' | translate}}"
6-
[disabled]="(processing$ | async) || !(claimEnabled$ | async)"
9+
[disabled]="!(claimEnabled$ | async)"
710
(click)="claimAllSelectedTask()"
11+
[attr.data-test-disabled]="!(claimEnabled$ | async) ?? false"
812
>
913
<span>
1014
<i class="fas fa-hand-paper"></i>
@@ -16,18 +20,84 @@
1620
type="button"
1721
class="btn btn-success mr-2"
1822
ngbTooltip="{{'submission.workflow.tasks.claimed.approve_selected_help' | translate}}"
19-
[disabled]="(processing$ | async) || !(claimedTaskActionsEnabled$ | async)"
23+
[disabled]="!(claimedTaskActionsEnabled$ | async)"
2024
(click)="submitAllSelectedTask()"
25+
[attr.data-test-disabled]="!(claimedTaskActionsEnabled$ | async) ?? false"
2126
>
2227
<span>
2328
<i class="fa fa-thumbs-up"></i>
2429
{{'submission.workflow.tasks.claimed.approve.selected' | translate}}
2530
</span>
2631
</button>
2732

33+
<button
34+
class="btn btn-danger mr-2"
35+
[ngbTooltip]="rejectTipContent"
36+
[disabled]="!(claimedTaskActionsEnabled$ | async)"
37+
(click)="openRejectModal(rejectModal)"
38+
[attr.data-test-disabled]="!(claimedTaskActionsEnabled$ | async) ?? false"
39+
>
40+
<span>
41+
<i class="fa fa-trash"></i>
42+
{{'submission.workflow.tasks.claimed.reject.selected.submit' | translate}}
43+
</span>
44+
</button>
2845

29-
<span *ngIf="(processing$ | async)">
30-
<i class='fas fa-circle-notch fa-spin'></i>
31-
{{'submission.workflow.tasks.generic.processing' | translate}}
32-
</span>
46+
<button
47+
type="button"
48+
class="btn btn-secondary"
49+
ngbTooltip="{{'submission.workflow.tasks.claimed.return_help' | translate}}"
50+
[disabled]="!(claimedTaskActionsEnabled$ | async)"
51+
(click)="returnSelectedToPool()"
52+
[attr.data-test-disabled]="!(claimedTaskActionsEnabled$ | async) ?? false"
53+
>
54+
<span>
55+
<i class="fa fa-undo"></i>
56+
{{'submission.workflow.tasks.claimed.return.selected' | translate}}
57+
</span>
58+
</button>
3359
</div>
60+
61+
<ng-template #loading>
62+
<div class="w-100 d-flex mt-1 mb-3 justify-content-center align-items-center">
63+
<span>
64+
<i class='fas fa-circle-notch fa-spin'></i>
65+
{{'submission.workflow.tasks.generic.processing' | translate}}
66+
</span>
67+
</div>
68+
</ng-template>
69+
<ng-template #rejectTipContent><p [innerHTML]="'submission.workflow.tasks.claimed.reject_help' | translate"></p></ng-template>
70+
<ng-template #rejectModal let-c="close" let-d="dismiss">
71+
<div class="modal-header">
72+
<h4 class="modal-title">{{'submission.workflow.tasks.claimed.reject.reason.title' | translate}}</h4>
73+
<button
74+
type="button"
75+
class="close"
76+
aria-label="Close"
77+
(click)="d('Cross click')"
78+
>
79+
<span aria-hidden="true">&times;</span>
80+
</button>
81+
</div>
82+
<div class="modal-body">
83+
<div class="alert alert-info" role="alert">
84+
{{'submission.workflow.tasks.claimed.reject.reason.info' | translate}}
85+
</div>
86+
<form (ngSubmit)="rejectSelected();" [formGroup]="rejectForm">
87+
<textarea
88+
style="width: 100%"
89+
formControlName="reason"
90+
rows="4"
91+
placeholder="{{'submission.workflow.tasks.claimed.reject.reason.placeholder' | translate}}"
92+
></textarea>
93+
<button
94+
id="btn-chat"
95+
class="btn btn-danger btn-lg btn-block mt-3"
96+
[disabled]="!rejectForm.valid"
97+
type="submit"
98+
>
99+
<span>{{'submission.workflow.tasks.claimed.reject.reason.submit' | translate}}</span>
100+
</button>
101+
</form>
102+
</div>
103+
</ng-template>

src/app/my-dspace-page/my-dspace-new-submission/my-dspace-bulk-action/my-dspace-bulk-action.component.scss

Whitespace-only changes.
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import { NO_ERRORS_SCHEMA } from '@angular/core';
2+
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
3+
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
4+
import { RouterTestingModule } from '@angular/router/testing';
5+
6+
import { of } from 'rxjs';
7+
import { TranslateModule } from '@ngx-translate/core';
8+
import { MyDSpaceBulkActionComponent } from './my-dspace-bulk-action.component';
9+
import { SearchService } from '../../../core/shared/search/search.service';
10+
import { SelectableListService } from '../../../shared/object-list/selectable-list/selectable-list.service';
11+
import { PoolTaskDataService } from '../../../core/tasks/pool-task-data.service';
12+
import { ProcessTaskResponse } from '../../../core/tasks/models/process-task-response';
13+
import { ClaimedTaskDataService } from '../../../core/tasks/claimed-task-data.service';
14+
import { NotificationsService } from '../../../shared/notifications/notifications.service';
15+
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
16+
import { Router } from '@angular/router';
17+
import { RouterStub } from '../../../shared/testing/router.stub';
18+
import { SearchServiceStub } from '../../../shared/testing/search-service.stub';
19+
import { UntypedFormBuilder } from '@angular/forms';
20+
import { RequestService } from '../../../core/data/request.service';
21+
import { By } from '@angular/platform-browser';
22+
23+
describe('MyDSpaceBulkActionComponent test suite', () => {
24+
let comp: MyDSpaceBulkActionComponent;
25+
let fixture: ComponentFixture<MyDSpaceBulkActionComponent>;
26+
27+
const testAction = {
28+
_embedded: {
29+
indexableObject: {
30+
type: ''
31+
}
32+
}
33+
};
34+
35+
const selectableListService = jasmine.createSpyObj('selectableListService', {
36+
getSelectableList: of({selection: []}),
37+
deselectAll: jasmine.createSpy('deselectAll')
38+
});
39+
40+
const poolTaskService = new PoolTaskDataService(null, null, null, null);
41+
42+
const claimedTaskService = jasmine.createSpyObj('claimedTaskService', {
43+
submitTask: of(new ProcessTaskResponse(true))
44+
});
45+
46+
const requestService = jasmine.createSpyObj('requestService', {
47+
removeByHrefSubstring: {},
48+
});
49+
50+
beforeEach(waitForAsync(() => {
51+
TestBed.configureTestingModule({
52+
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
53+
declarations: [MyDSpaceBulkActionComponent],
54+
providers: [
55+
{ provide: SelectableListService, useValue: selectableListService },
56+
{ provide: RequestService, useValue: requestService },
57+
{ provide: PoolTaskDataService, useValue: poolTaskService },
58+
{ provide: ClaimedTaskDataService, useValue: claimedTaskService },
59+
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
60+
{ provide: Router, useValue: new RouterStub() },
61+
{ provide: SearchService, useValue: new SearchServiceStub('searchLink') },
62+
{
63+
provide: NgbModal, useValue: {
64+
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
65+
open: () => {}
66+
}
67+
},
68+
{ provide: UntypedFormBuilder, useValue: new UntypedFormBuilder() },
69+
],
70+
schemas: [NO_ERRORS_SCHEMA]
71+
}).compileComponents();
72+
}));
73+
74+
afterEach(() => {
75+
fixture.destroy();
76+
});
77+
78+
beforeEach(() => {
79+
fixture = TestBed.createComponent(MyDSpaceBulkActionComponent);
80+
comp = fixture.componentInstance;
81+
comp.processing$.next(false);
82+
selectableListService.getSelectableList.and.returnValue(of({ selection: []}));
83+
84+
fixture.detectChanges();
85+
});
86+
87+
it('should create', () => {
88+
expect(comp).toBeTruthy();
89+
});
90+
91+
it('all button should be disabled by default', () => {
92+
const disabledButtons = fixture.debugElement.queryAll(By.css('button[data-test-disabled="true"]'));
93+
expect(disabledButtons.length).toBe(4);
94+
});
95+
96+
it('claim button should be enabled', () => {
97+
const mockAction = testAction;
98+
mockAction._embedded.indexableObject.type = 'claimaction';
99+
selectableListService.getSelectableList.and.returnValue(of({ selection: [mockAction]}));
100+
comp.claimEnabled$ = of(true);
101+
fixture.detectChanges();
102+
103+
const disabledButtons = fixture.debugElement.queryAll(By.css('button[data-test-disabled="true"]'));
104+
const claimButton = fixture.debugElement.query(By.css('.btn.btn-info'));
105+
expect(disabledButtons.length).toBe(3);
106+
expect(claimButton.nativeElement.disabled).toBeFalsy();
107+
});
108+
109+
it('claimed task buttons should be enabled', () => {
110+
const mockAction = testAction;
111+
mockAction._embedded.indexableObject.type = 'claimedtask';
112+
selectableListService.getSelectableList.and.returnValue(of({ selection: [mockAction]}));
113+
comp.claimedTaskActionsEnabled$ = of(true);
114+
fixture.detectChanges();
115+
116+
const disabledButtons = fixture.debugElement.queryAll(By.css('button[data-test-disabled="true"]'));
117+
const approveButton = fixture.debugElement.query(By.css('.btn.btn-success'));
118+
const rejectButton = fixture.debugElement.query(By.css('.btn.btn-danger'));
119+
const returnToPoolButton = fixture.debugElement.query(By.css('.btn.btn-secondary'));
120+
expect(disabledButtons.length).toBe(1);
121+
expect(approveButton.nativeElement.disabled).toBeFalsy();
122+
expect(rejectButton.nativeElement.disabled).toBeFalsy();
123+
expect(returnToPoolButton.nativeElement.disabled).toBeFalsy();
124+
});
125+
126+
it('All buttons should be enabled', () => {
127+
const mockAction = testAction;
128+
const mockAction2 = testAction;
129+
mockAction._embedded.indexableObject.type = 'claimaction';
130+
mockAction2._embedded.indexableObject.type = 'claimedtask';
131+
selectableListService.getSelectableList.and.returnValue(of({ selection: [mockAction, mockAction2]}));
132+
comp.claimEnabled$ = of(true);
133+
comp.claimedTaskActionsEnabled$ = of(true);
134+
fixture.detectChanges();
135+
136+
const disabledButtons = fixture.debugElement.queryAll(By.css('button[data-test-disabled="true"]'));
137+
expect(disabledButtons.length).toBe(0);
138+
});
139+
140+
});

0 commit comments

Comments
 (0)