80195: Fix ItemMoveComponent unit tests

This commit is contained in:
Yura Bondarenko
2021-06-29 09:56:29 +02:00
parent 72a6754245
commit b0599fa27c

View File

@@ -49,7 +49,9 @@ describe('ItemMoveComponent', () => {
name: 'Test collection 2' name: 'Test collection 2'
}); });
const mockItemDataService = jasmine.createSpyObj({ let itemDataService;
const mockItemDataServiceSuccess = jasmine.createSpyObj({
moveToCollection: createSuccessfulRemoteDataObject$(collection1), moveToCollection: createSuccessfulRemoteDataObject$(collection1),
findById: createSuccessfulRemoteDataObject$(mockItem), findById: createSuccessfulRemoteDataObject$(mockItem),
}); });
@@ -86,25 +88,31 @@ describe('ItemMoveComponent', () => {
const notificationsServiceStub = new NotificationsServiceStub(); const notificationsServiceStub = new NotificationsServiceStub();
const init = (mockItemDataService) => {
itemDataService = mockItemDataService;
TestBed.configureTestingModule({
imports: [CommonModule, FormsModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
declarations: [ItemMoveComponent],
providers: [
{ provide: ActivatedRoute, useValue: routeStub },
{ provide: Router, useValue: routerStub },
{ provide: ItemDataService, useValue: mockItemDataService },
{ provide: NotificationsService, useValue: notificationsServiceStub },
{ provide: SearchService, useValue: mockSearchService },
{ provide: RequestService, useValue: getMockRequestService() },
], schemas: [
CUSTOM_ELEMENTS_SCHEMA
]
}).compileComponents();
fixture = TestBed.createComponent(ItemMoveComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
};
describe('ItemMoveComponent success', () => { describe('ItemMoveComponent success', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ init(mockItemDataServiceSuccess);
imports: [CommonModule, FormsModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
declarations: [ItemMoveComponent],
providers: [
{ provide: ActivatedRoute, useValue: routeStub },
{ provide: Router, useValue: routerStub },
{ provide: ItemDataService, useValue: mockItemDataService },
{ provide: NotificationsService, useValue: notificationsServiceStub },
{ provide: SearchService, useValue: mockSearchService },
{ provide: RequestService, useValue: getMockRequestService() },
], schemas: [
CUSTOM_ELEMENTS_SCHEMA
]
}).compileComponents();
fixture = TestBed.createComponent(ItemMoveComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
}); });
it('should get current url ', () => { it('should get current url ', () => {
@@ -128,7 +136,7 @@ describe('ItemMoveComponent', () => {
comp.selectedCollection = collection1; comp.selectedCollection = collection1;
comp.moveToCollection(); comp.moveToCollection();
expect(mockItemDataService.moveToCollection).toHaveBeenCalledWith('item-id', collection1); expect(itemDataService.moveToCollection).toHaveBeenCalledWith('item-id', collection1);
}); });
it('should call notificationsService success message on success', () => { it('should call notificationsService success message on success', () => {
comp.moveToCollection(); comp.moveToCollection();
@@ -140,22 +148,7 @@ describe('ItemMoveComponent', () => {
describe('ItemMoveComponent fail', () => { describe('ItemMoveComponent fail', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ init(mockItemDataServiceFail);
imports: [CommonModule, FormsModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
declarations: [ItemMoveComponent],
providers: [
{ provide: ActivatedRoute, useValue: routeStub },
{ provide: Router, useValue: routerStub },
{ provide: ItemDataService, useValue: mockItemDataServiceFail },
{ provide: NotificationsService, useValue: notificationsServiceStub },
{ provide: SearchService, useValue: mockSearchService },
], schemas: [
CUSTOM_ELEMENTS_SCHEMA
]
}).compileComponents();
fixture = TestBed.createComponent(ItemMoveComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
}); });
it('should call notificationsService error message on fail', () => { it('should call notificationsService error message on fail', () => {