[CST-9636] finalize implementation

This commit is contained in:
Giuseppe Digilio
2023-05-11 11:10:00 +02:00
parent 64c0fff370
commit f3aa2d47a6
3 changed files with 109 additions and 58 deletions

View File

@@ -10,6 +10,9 @@ import { SelectableListService } from '../../shared/object-list/selectable-list/
import { SelectableListState } from '../../shared/object-list/selectable-list/selectable-list.reducer';
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
import { Process } from '../../process-page/processes/process.model';
import { RouterTestingModule } from '@angular/router/testing';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
fdescribe('BulkAccessComponent', () => {
let component: BulkAccessComponent;
@@ -47,6 +50,13 @@ fdescribe('BulkAccessComponent', () => {
}
};
const mockFile = {
"uuids": [
'1234', '5678'
],
"file": { }
}
const mockSettings: any = jasmine.createSpyObj('AccessControlFormContainerComponent', {
getValue: jasmine.createSpy('getValue'),
reset: jasmine.createSpy('reset')
@@ -55,12 +65,18 @@ fdescribe('BulkAccessComponent', () => {
const selectableListState: SelectableListState = { id: 'test', selection };
const expectedIdList = ['1234', '5678'];
const selectableListStateEmpty: SelectableListState = { id: 'test', selection: [] };
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ TranslateModule.forRoot() ],
imports: [
RouterTestingModule,
TranslateModule.forRoot()
],
declarations: [ BulkAccessComponent ],
providers: [
{ provide: BulkAccessControlService, useValue: bulkAccessControlServiceMock },
{ provide: NotificationsService, useValue: NotificationsServiceStub },
{ provide: SelectableListService, useValue: selectableListServiceMock }
],
schemas: [NO_ERRORS_SCHEMA]
@@ -73,43 +89,70 @@ fdescribe('BulkAccessComponent', () => {
component = fixture.componentInstance;
bulkAccessControlService = TestBed.inject(BulkAccessControlService);
selectableListService = TestBed.inject(SelectableListService);
(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListState));
fixture.detectChanges();
component.settings = mockSettings;
});
afterEach(() => {
fixture.destroy();
});
it('should create', () => {
expect(component).toBeTruthy();
describe('when there are no elements selected', () => {
beforeEach(() => {
(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListStateEmpty));
fixture.detectChanges();
component.settings = mockSettings;
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should generate the id list by selected elements', () => {
expect(component.objectsSelected$.value).toEqual([]);
});
it('should disable the execute button when there are no objects selected', () => {
expect(component.canExport()).toBe(false);
});
});
it('should generate the id list by selected elements', () => {
expect(component.objectsSelected$.value).toEqual(expectedIdList);
});
describe('when there are elements selected', () => {
it('should disable the execute button when there are no objects selected', () => {
expect(component.canExport()).toBe(false);
});
beforeEach(() => {
it('should enable the execute button when there are objects selected', () => {
component.objectsSelected$.next(['1234']);
expect(component.canExport()).toBe(true);
});
(component as any).selectableListService.getSelectableList.and.returnValue(of(selectableListState));
fixture.detectChanges();
component.settings = mockSettings;
});
it('should call the settings reset method when reset is called', () => {
spyOn(component.settings, 'reset');
component.reset();
expect(component.settings.reset).toHaveBeenCalled();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call the bulkAccessControlService executeScript method when submit is called', () => {
(component.settings as any).getValue.and.returnValue(mockFormState)
bulkAccessControlService.executeScript.and.returnValue(createSuccessfulRemoteDataObject$(new Process()));
component.objectsSelected$.next(['1234']);
component.submit();
expect(bulkAccessControlService.executeScript).toHaveBeenCalled();
it('should generate the id list by selected elements', () => {
expect(component.objectsSelected$.value).toEqual(expectedIdList);
});
it('should enable the execute button when there are objects selected', () => {
component.objectsSelected$.next(['1234']);
expect(component.canExport()).toBe(true);
});
it('should call the settings reset method when reset is called', () => {
component.reset();
expect(component.settings.reset).toHaveBeenCalled();
});
it('should call the bulkAccessControlService executeScript method when submit is called', () => {
(component.settings as any).getValue.and.returnValue(mockFormState);
bulkAccessControlService.createPayloadFile.and.returnValue(mockFile);
bulkAccessControlService.executeScript.and.returnValue(createSuccessfulRemoteDataObject$(new Process()));
component.objectsSelected$.next(['1234']);
component.submit();
expect(bulkAccessControlService.executeScript).toHaveBeenCalled();
});
});
});