Skip to content

Commit 5e5c2ab

Browse files
authored
Merge pull request #4168 from atmire/fix-export-button_contribute-main
Fix export button enabled in bulk access management without selecting step 2
2 parents 46831cb + 4b3b660 commit 5e5c2ab

File tree

5 files changed

+50
-11
lines changed

5 files changed

+50
-11
lines changed

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

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { NO_ERRORS_SCHEMA } from '@angular/core';
1+
import {
2+
Component,
3+
NO_ERRORS_SCHEMA,
4+
} from '@angular/core';
25
import {
36
ComponentFixture,
47
TestBed,
@@ -62,10 +65,17 @@ describe('BulkAccessComponent', () => {
6265
'file': { },
6366
};
6467

65-
const mockSettings: any = jasmine.createSpyObj('AccessControlFormContainerComponent', {
66-
getValue: jasmine.createSpy('getValue'),
67-
reset: jasmine.createSpy('reset'),
68-
});
68+
@Component({
69+
selector: 'ds-bulk-access-settings',
70+
template: '',
71+
exportAs: 'dsBulkSettings',
72+
standalone: true,
73+
})
74+
class MockBulkAccessSettingsComponent {
75+
isFormValid = jasmine.createSpy('isFormValid').and.returnValue(false);
76+
getValue = jasmine.createSpy('getValue');
77+
reset = jasmine.createSpy('reset');
78+
}
6979
const selection: any[] = [{ indexableObject: { uuid: '1234' } }, { indexableObject: { uuid: '5678' } }];
7080
const selectableListState: SelectableListState = { id: 'test', selection };
7181
const expectedIdList = ['1234', '5678'];
@@ -93,6 +103,9 @@ describe('BulkAccessComponent', () => {
93103
BulkAccessSettingsComponent,
94104
],
95105
},
106+
add: {
107+
imports: [MockBulkAccessSettingsComponent],
108+
},
96109
})
97110
.compileComponents();
98111
});
@@ -109,13 +122,12 @@ describe('BulkAccessComponent', () => {
109122
fixture.destroy();
110123
});
111124

112-
describe('when there are no elements selected', () => {
125+
describe('when there are no elements selected and step two form is invalid', () => {
113126

114127
beforeEach(() => {
115128

116129
(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListStateEmpty));
117130
fixture.detectChanges();
118-
component.settings = mockSettings;
119131
});
120132

121133
it('should create', () => {
@@ -138,7 +150,6 @@ describe('BulkAccessComponent', () => {
138150

139151
(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListState));
140152
fixture.detectChanges();
141-
component.settings = mockSettings;
142153
});
143154

144155
it('should create', () => {
@@ -149,15 +160,29 @@ describe('BulkAccessComponent', () => {
149160
expect(component.objectsSelected$.value).toEqual(expectedIdList);
150161
});
151162

152-
it('should enable the execute button when there are objects selected', () => {
163+
it('should not enable the execute button when there are objects selected and step two form is invalid', () => {
153164
component.objectsSelected$.next(['1234']);
154-
expect(component.canExport()).toBe(true);
165+
expect(component.canExport()).toBe(false);
155166
});
156167

157168
it('should call the settings reset method when reset is called', () => {
158169
component.reset();
159170
expect(component.settings.reset).toHaveBeenCalled();
160171
});
172+
});
173+
describe('when there are elements selected and the step two form is valid', () => {
174+
175+
beforeEach(() => {
176+
177+
(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListState));
178+
fixture.detectChanges();
179+
(component as any).settings.isFormValid.and.returnValue(true);
180+
});
181+
182+
it('should enable the execute button when there are objects selected and step two form is valid', () => {
183+
component.objectsSelected$.next(['1234']);
184+
expect(component.canExport()).toBe(true);
185+
});
161186

162187
it('should call the bulkAccessControlService executeScript method when submit is called', () => {
163188
(component.settings as any).getValue.and.returnValue(mockFormState);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
ChangeDetectionStrategy,
23
Component,
34
OnInit,
45
ViewChild,
@@ -31,6 +32,7 @@ import { BulkAccessSettingsComponent } from './settings/bulk-access-settings.com
3132
BtnDisabledDirective,
3233
],
3334
standalone: true,
35+
changeDetection: ChangeDetectionStrategy.OnPush,
3436
})
3537
export class BulkAccessComponent implements OnInit {
3638

@@ -70,7 +72,7 @@ export class BulkAccessComponent implements OnInit {
7072
}
7173

7274
canExport(): boolean {
73-
return this.objectsSelected$.value?.length > 0;
75+
return this.objectsSelected$.value?.length > 0 && this.settings?.isFormValid();
7476
}
7577

7678
/**

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
@@ -42,4 +42,8 @@ export class BulkAccessSettingsComponent {
4242
this.controlForm.reset();
4343
}
4444

45+
isFormValid() {
46+
return this.controlForm.isValid();
47+
}
48+
4549
}

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
@@ -135,6 +135,10 @@ export class AccessControlArrayFormComponent implements OnInit {
135135
return item.id;
136136
}
137137

138+
isValid() {
139+
return this.ngForm.valid;
140+
}
141+
138142
}
139143

140144

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
@@ -176,5 +176,9 @@ export class AccessControlFormContainerComponent<T extends DSpaceObject> impleme
176176
this.selectableListService.deselectAll(ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID);
177177
}
178178

179+
isValid() {
180+
return this.bitstreamAccessCmp.isValid() || this.itemAccessCmp.isValid();
181+
}
182+
179183
}
180184

0 commit comments

Comments
 (0)