Skip to content
Merged
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
45 changes: 34 additions & 11 deletions src/app/access-control/bulk-access/bulk-access.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { NO_ERRORS_SCHEMA, Component } from '@angular/core';

import { TranslateModule } from '@ngx-translate/core';
import { of } from 'rxjs';
Expand Down Expand Up @@ -57,10 +57,15 @@ describe('BulkAccessComponent', () => {
'file': { }
};

const mockSettings: any = jasmine.createSpyObj('AccessControlFormContainerComponent', {
getValue: jasmine.createSpy('getValue'),
reset: jasmine.createSpy('reset')
});
@Component({
selector: 'ds-bulk-access-settings',
template: ''
})
class MockBulkAccessSettingsComponent {
isFormValid = jasmine.createSpy('isFormValid').and.returnValue(false);
getValue = jasmine.createSpy('getValue');
reset = jasmine.createSpy('reset');
}
const selection: any[] = [{ indexableObject: { uuid: '1234' } }, { indexableObject: { uuid: '5678' } }];
const selectableListState: SelectableListState = { id: 'test', selection };
const expectedIdList = ['1234', '5678'];
Expand All @@ -73,7 +78,10 @@ describe('BulkAccessComponent', () => {
RouterTestingModule,
TranslateModule.forRoot()
],
declarations: [ BulkAccessComponent ],
declarations: [
BulkAccessComponent,
MockBulkAccessSettingsComponent,
],
providers: [
{ provide: BulkAccessControlService, useValue: bulkAccessControlServiceMock },
{ provide: NotificationsService, useValue: NotificationsServiceStub },
Expand Down Expand Up @@ -102,7 +110,6 @@ describe('BulkAccessComponent', () => {

(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListStateEmpty));
fixture.detectChanges();
component.settings = mockSettings;
});

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

});

describe('when there are elements selected', () => {
describe('when there are elements selected and step two form is invalid', () => {

beforeEach(() => {

(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListState));
fixture.detectChanges();
component.settings = mockSettings;
});

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

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

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


});

describe('when there are elements selectedted and the step two form is valid', () => {

beforeEach(() => {

(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListState));
fixture.detectChanges();
(component as any).settings.isFormValid.and.returnValue(true);
});

it('should enable the execute button when there are objects selected and step two form is valid', () => {
component.objectsSelected$.next(['1234']);
expect(component.canExport()).toBe(true);
});

it('should call the bulkAccessControlService executeScript method when submit is called', () => {
(component.settings as any).getValue.and.returnValue(mockFormState);
bulkAccessControlService.createPayloadFile.and.returnValue(mockFile);
Expand Down
4 changes: 2 additions & 2 deletions src/app/access-control/bulk-access/bulk-access.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class BulkAccessComponent implements OnInit {

constructor(
private bulkAccessControlService: BulkAccessControlService,
private selectableListService: SelectableListService
private selectableListService: SelectableListService,
) {
}

Expand All @@ -51,7 +51,7 @@ export class BulkAccessComponent implements OnInit {
}

canExport(): boolean {
return this.objectsSelected$.value?.length > 0;
return this.objectsSelected$.value?.length > 0 && this.settings?.isFormValid();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@
this.controlForm.reset();
}

isFormValid() {
return this.controlForm.isValid();

Check warning on line 35 in src/app/access-control/bulk-access/settings/bulk-access-settings.component.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L35 was not covered by tests
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
return item.id;
}

isValid() {
return this.ngForm.valid;

Check warning on line 123 in src/app/shared/access-control-form-container/access-control-array-form/access-control-array-form.component.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L123 was not covered by tests
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,9 @@ export class AccessControlFormContainerComponent<T extends DSpaceObject> impleme
this.selectableListService.deselectAll(ITEM_ACCESS_CONTROL_SELECT_BITSTREAMS_LIST_ID);
}

isValid() {
return this.bitstreamAccessCmp.isValid() || this.itemAccessCmp.isValid();
}

}

Loading