Skip to content

Commit 28eb709

Browse files
authored
Merge pull request #4169 from atmire/w29-129641_fix-export-button_contribute-7_x
[Port dspace-7_x] Fix export button enabled in bulk access management without selecting step 2
2 parents f5df726 + fa6b8cc commit 28eb709

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

src/app/access-control/bulk-access/bulk-access.component.spec.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
import { NO_ERRORS_SCHEMA } from '@angular/core';
2+
import { NO_ERRORS_SCHEMA, Component } from '@angular/core';
33

44
import { TranslateModule } from '@ngx-translate/core';
55
import { of } from 'rxjs';
@@ -57,10 +57,15 @@ describe('BulkAccessComponent', () => {
5757
'file': { }
5858
};
5959

60-
const mockSettings: any = jasmine.createSpyObj('AccessControlFormContainerComponent', {
61-
getValue: jasmine.createSpy('getValue'),
62-
reset: jasmine.createSpy('reset')
63-
});
60+
@Component({
61+
selector: 'ds-bulk-access-settings',
62+
template: ''
63+
})
64+
class MockBulkAccessSettingsComponent {
65+
isFormValid = jasmine.createSpy('isFormValid').and.returnValue(false);
66+
getValue = jasmine.createSpy('getValue');
67+
reset = jasmine.createSpy('reset');
68+
}
6469
const selection: any[] = [{ indexableObject: { uuid: '1234' } }, { indexableObject: { uuid: '5678' } }];
6570
const selectableListState: SelectableListState = { id: 'test', selection };
6671
const expectedIdList = ['1234', '5678'];
@@ -73,7 +78,10 @@ describe('BulkAccessComponent', () => {
7378
RouterTestingModule,
7479
TranslateModule.forRoot()
7580
],
76-
declarations: [ BulkAccessComponent ],
81+
declarations: [
82+
BulkAccessComponent,
83+
MockBulkAccessSettingsComponent,
84+
],
7785
providers: [
7886
{ provide: BulkAccessControlService, useValue: bulkAccessControlServiceMock },
7987
{ provide: NotificationsService, useValue: NotificationsServiceStub },
@@ -102,7 +110,6 @@ describe('BulkAccessComponent', () => {
102110

103111
(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListStateEmpty));
104112
fixture.detectChanges();
105-
component.settings = mockSettings;
106113
});
107114

108115
it('should create', () => {
@@ -119,13 +126,12 @@ describe('BulkAccessComponent', () => {
119126

120127
});
121128

122-
describe('when there are elements selected', () => {
129+
describe('when there are elements selected and step two form is invalid', () => {
123130

124131
beforeEach(() => {
125132

126133
(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListState));
127134
fixture.detectChanges();
128-
component.settings = mockSettings;
129135
});
130136

131137
it('should create', () => {
@@ -136,16 +142,33 @@ describe('BulkAccessComponent', () => {
136142
expect(component.objectsSelected$.value).toEqual(expectedIdList);
137143
});
138144

139-
it('should enable the execute button when there are objects selected', () => {
145+
it('should not enable the execute button when there are objects selected and step two form is invalid', () => {
140146
component.objectsSelected$.next(['1234']);
141-
expect(component.canExport()).toBe(true);
147+
expect(component.canExport()).toBe(false);
142148
});
143149

144150
it('should call the settings reset method when reset is called', () => {
145151
component.reset();
146152
expect(component.settings.reset).toHaveBeenCalled();
147153
});
148154

155+
156+
});
157+
158+
describe('when there are elements selectedted and the step two form is valid', () => {
159+
160+
beforeEach(() => {
161+
162+
(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListState));
163+
fixture.detectChanges();
164+
(component as any).settings.isFormValid.and.returnValue(true);
165+
});
166+
167+
it('should enable the execute button when there are objects selected and step two form is valid', () => {
168+
component.objectsSelected$.next(['1234']);
169+
expect(component.canExport()).toBe(true);
170+
});
171+
149172
it('should call the bulkAccessControlService executeScript method when submit is called', () => {
150173
(component.settings as any).getValue.and.returnValue(mockFormState);
151174
bulkAccessControlService.createPayloadFile.and.returnValue(mockFile);

src/app/access-control/bulk-access/bulk-access.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class BulkAccessComponent implements OnInit {
3737

3838
constructor(
3939
private bulkAccessControlService: BulkAccessControlService,
40-
private selectableListService: SelectableListService
40+
private selectableListService: SelectableListService,
4141
) {
4242
}
4343

@@ -51,7 +51,7 @@ export class BulkAccessComponent implements OnInit {
5151
}
5252

5353
canExport(): boolean {
54-
return this.objectsSelected$.value?.length > 0;
54+
return this.objectsSelected$.value?.length > 0 && this.settings?.isFormValid();
5555
}
5656

5757
/**

src/app/access-control/bulk-access/settings/bulk-access-settings.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ export class BulkAccessSettingsComponent {
3131
this.controlForm.reset();
3232
}
3333

34+
isFormValid() {
35+
return this.controlForm.isValid();
36+
}
37+
3438
}

src/app/shared/access-control-form-container/access-control-array-form/access-control-array-form.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ export class AccessControlArrayFormComponent implements OnInit {
119119
return item.id;
120120
}
121121

122+
isValid() {
123+
return this.ngForm.valid;
124+
}
125+
122126
}
123127

124128

src/app/shared/access-control-form-container/access-control-form-container.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,9 @@ export class AccessControlFormContainerComponent<T extends DSpaceObject> impleme
156156
this.selectableListService.deselectAll(ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID);
157157
}
158158

159+
isValid() {
160+
return this.bitstreamAccessCmp.isValid() || this.itemAccessCmp.isValid();
161+
}
162+
159163
}
160164

0 commit comments

Comments
 (0)