[CST-9636] WIP Create unit tests

This commit is contained in:
Giuseppe Digilio
2023-05-10 20:18:20 +02:00
parent e31fc562c5
commit 64c0fff370
15 changed files with 382 additions and 53 deletions

View File

@@ -1,25 +1,80 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { NgbAccordionModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
import { BulkAccessSettingsComponent } from './bulk-access-settings.component';
import { NO_ERRORS_SCHEMA } from '@angular/core';
describe('BulkAccessSettingsComponent', () => {
let component: BulkAccessSettingsComponent;
let fixture: ComponentFixture<BulkAccessSettingsComponent>;
const mockFormState = {
"bitstream": [],
"item": [
{
"name": "embargo",
"startDate": {
"year": 2026,
"month": 5,
"day": 31
},
"endDate": null
}
],
"state": {
"item": {
"toggleStatus": true,
"accessMode": "replace"
},
"bitstream": {
"toggleStatus": false,
"accessMode": "",
"changesLimit": "",
"selectedBitstreams": []
}
}
};
const mockControl: any = jasmine.createSpyObj('AccessControlFormContainerComponent', {
getFormValue: jasmine.createSpy('getFormValue'),
reset: jasmine.createSpy('reset')
});
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ BulkAccessSettingsComponent ]
})
.compileComponents();
imports: [NgbAccordionModule, TranslateModule.forRoot()],
declarations: [BulkAccessSettingsComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(BulkAccessSettingsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
component.controlForm = mockControl;
});
it('should create', () => {
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should have a method to get the form value', () => {
expect(component.getValue).toBeDefined();
});
it('should have a method to reset the form', () => {
expect(component.reset).toBeDefined();
});
it('should return the correct form value', () => {
const expectedValue = mockFormState;
(component.controlForm as any).getFormValue.and.returnValue(mockFormState)
const actualValue = component.getValue();
expect(actualValue).toEqual(expectedValue);
});
it('should call reset on the control form', () => {
component.reset();
expect(component.controlForm.reset).toHaveBeenCalled();
});
});