mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-12109] rewrite unit test case
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
import { ComponentFixture, TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { ItemAlertsComponent } from './item-alerts.component';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { Item } from '../../core/shared/item.model';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||
import { of } from 'rxjs';
|
||||
import { DsoWithdrawnReinstateModalService } from '../../shared/dso-page/dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service';
|
||||
import { DsoWithdrawnReinstateModalService, REQUEST_REINSTATE } from '../../shared/dso-page/dso-withdrawn-reinstate-service/dso-withdrawn-reinstate-modal.service';
|
||||
import { CorrectionTypeDataService } from '../../core/submission/correctiontype-data.service';
|
||||
import { TestScheduler } from 'rxjs/testing';
|
||||
import { CorrectionType } from '../../core/submission/models/correctiontype.model';
|
||||
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||
import { createPaginatedList } from '../../shared/testing/utils.test';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
describe('ItemAlertsComponent', () => {
|
||||
let component: ItemAlertsComponent;
|
||||
@@ -16,6 +20,7 @@ describe('ItemAlertsComponent', () => {
|
||||
let authorizationService;
|
||||
let dsoWithdrawnReinstateModalService;
|
||||
let correctionTypeDataService;
|
||||
let testScheduler: TestScheduler;
|
||||
|
||||
const itemMock = Object.assign(new Item(), {
|
||||
uuid: 'item-uuid',
|
||||
@@ -25,9 +30,7 @@ describe('ItemAlertsComponent', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
authorizationService = jasmine.createSpyObj('authorizationService', ['isAuthorized']);
|
||||
dsoWithdrawnReinstateModalService = jasmine.createSpyObj('dsoWithdrawnReinstateModalService', ['openCreateWithdrawnReinstateModal']);
|
||||
correctionTypeDataService = jasmine.createSpyObj('correctionTypeDataService', {
|
||||
findByItem: of({})
|
||||
});
|
||||
correctionTypeDataService = jasmine.createSpyObj('correctionTypeDataService', ['findByItem']);
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ItemAlertsComponent],
|
||||
imports: [TranslateModule.forRoot()],
|
||||
@@ -85,6 +88,7 @@ describe('ItemAlertsComponent', () => {
|
||||
isWithdrawn: true
|
||||
});
|
||||
component.item = item;
|
||||
(correctionTypeDataService.findByItem).and.returnValue(createSuccessfulRemoteDataObject$([]));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
@@ -100,6 +104,7 @@ describe('ItemAlertsComponent', () => {
|
||||
isWithdrawn: false
|
||||
});
|
||||
component.item = item;
|
||||
(correctionTypeDataService.findByItem).and.returnValue(createSuccessfulRemoteDataObject$([]));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
@@ -109,17 +114,42 @@ describe('ItemAlertsComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true when user is not an admin and there is at least one correction with topic REQUEST_REINSTATE', fakeAsync((done) => {
|
||||
const isAdmin = false;
|
||||
const correction = [{ topic: 'REQUEST_REINSTATE' }];
|
||||
authorizationService.isAuthorized.and.returnValue(of(isAdmin));
|
||||
correctionTypeDataService.findByItem.and.returnValue(of(correction));
|
||||
|
||||
const result$ = component.showReinstateButton$();
|
||||
tick();
|
||||
result$.subscribe((result) => {
|
||||
expect(result).toBeTrue();
|
||||
done();
|
||||
describe('when the item is reinstated', () => {
|
||||
const correctionType = Object.assign(new CorrectionType(), {
|
||||
topic: REQUEST_REINSTATE
|
||||
});
|
||||
}));
|
||||
const correctionRD = createSuccessfulRemoteDataObject(createPaginatedList([correctionType]));
|
||||
|
||||
beforeEach(() => {
|
||||
item = itemMock;
|
||||
component.item = item;
|
||||
(correctionTypeDataService.findByItem).and.returnValue(of(correctionRD));
|
||||
|
||||
testScheduler = new TestScheduler((actual, expected) => {
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should return true when user is not an admin and there is at least one correction with topic REQUEST_REINSTATE', () => {
|
||||
testScheduler.run(({ cold, expectObservable }) => {
|
||||
const isAdminMarble = 'a';
|
||||
const correctionMarble = 'b';
|
||||
const expectedMarble = 'c';
|
||||
|
||||
const isAdminValues = { a: false };
|
||||
const correctionValues = { b: correctionRD };
|
||||
const expectedValues = { c: true };
|
||||
|
||||
const isAdmin$ = cold(isAdminMarble, isAdminValues);
|
||||
const correction$ = cold(correctionMarble, correctionValues);
|
||||
|
||||
(authorizationService.isAuthorized).and.returnValue(isAdmin$);
|
||||
(correctionTypeDataService.findByItem).and.returnValue(correction$);
|
||||
|
||||
expectObservable(component.showReinstateButton$()).toBe(expectedMarble, expectedValues);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user