mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 13:03:04 +00:00
[CST-4981] fixed and finished unit testing
This commit is contained in:
@@ -18,6 +18,8 @@ import { ActivatedRoute } from '@angular/router';
|
||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
||||
import createSpy = jasmine.createSpy;
|
||||
import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils';
|
||||
import { Item } from '../../core/shared/item.model';
|
||||
|
||||
describe('AdminSidebarComponent', () => {
|
||||
let comp: AdminSidebarComponent;
|
||||
@@ -26,6 +28,28 @@ describe('AdminSidebarComponent', () => {
|
||||
let authorizationService: AuthorizationDataService;
|
||||
let scriptService;
|
||||
|
||||
|
||||
const mockItem = Object.assign(new Item(), {
|
||||
id: 'fake-id',
|
||||
uuid: 'fake-id',
|
||||
handle: 'fake/handle',
|
||||
lastModified: '2018',
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://localhost:8000/items/fake-id'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const routeStub = {
|
||||
data: observableOf({
|
||||
dso: createSuccessfulRemoteDataObject(mockItem)
|
||||
}),
|
||||
children: []
|
||||
};
|
||||
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
authorizationService = jasmine.createSpyObj('authorizationService', {
|
||||
isAuthorized: observableOf(true)
|
||||
@@ -42,6 +66,7 @@ describe('AdminSidebarComponent', () => {
|
||||
{ provide: ActivatedRoute, useValue: {} },
|
||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||
{ provide: ScriptDataService, useValue: scriptService },
|
||||
{ provide: ActivatedRoute, useValue: routeStub },
|
||||
{
|
||||
provide: NgbModal, useValue: {
|
||||
open: () => {/*comment*/
|
||||
|
@@ -2,8 +2,8 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { first, map } from 'rxjs/operators';
|
||||
import { RemoteData } from 'src/app/core/data/remote-data';
|
||||
import { DSpaceObject } from 'src/app/core/shared/dspace-object.model';
|
||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-community-authorizations',
|
||||
|
@@ -13,10 +13,39 @@ import { MenuService } from '../shared/menu/menu.service';
|
||||
import { MenuServiceStub } from '../shared/testing/menu-service.stub';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { Item } from '../core/shared/item.model';
|
||||
import { createSuccessfulRemoteDataObject } from '../shared/remote-data.utils';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
|
||||
|
||||
let comp: NavbarComponent;
|
||||
let fixture: ComponentFixture<NavbarComponent>;
|
||||
|
||||
const authorizationService = jasmine.createSpyObj('authorizationService', {
|
||||
isAuthorized: observableOf(true)
|
||||
});
|
||||
|
||||
const mockItem = Object.assign(new Item(), {
|
||||
id: 'fake-id',
|
||||
uuid: 'fake-id',
|
||||
handle: 'fake/handle',
|
||||
lastModified: '2018',
|
||||
_links: {
|
||||
self: {
|
||||
href: 'https://localhost:8000/items/fake-id'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const routeStub = {
|
||||
data: observableOf({
|
||||
dso: createSuccessfulRemoteDataObject(mockItem)
|
||||
}),
|
||||
children: []
|
||||
};
|
||||
|
||||
|
||||
|
||||
describe('NavbarComponent', () => {
|
||||
const menuService = new MenuServiceStub();
|
||||
|
||||
@@ -33,7 +62,8 @@ describe('NavbarComponent', () => {
|
||||
Injector,
|
||||
{ provide: MenuService, useValue: menuService },
|
||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
|
||||
{ provide: ActivatedRoute, useValue: {} }
|
||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||
{ provide: ActivatedRoute, useValue: routeStub },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
})
|
||||
@@ -42,7 +72,6 @@ describe('NavbarComponent', () => {
|
||||
|
||||
// synchronous beforeEach
|
||||
beforeEach(() => {
|
||||
spyOn(menuService, 'getMenuTopSections').and.returnValue(observableOf([]));
|
||||
|
||||
fixture = TestBed.createComponent(NavbarComponent);
|
||||
|
||||
@@ -53,4 +82,6 @@ describe('NavbarComponent', () => {
|
||||
it('should create', () => {
|
||||
expect(comp).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
@@ -7,11 +7,8 @@ import { TextMenuItemModel } from '../shared/menu/menu-item/models/text.model';
|
||||
import { LinkMenuItemModel } from '../shared/menu/menu-item/models/link.model';
|
||||
import { HostWindowService } from '../shared/host-window.service';
|
||||
import { environment } from '../../environments/environment';
|
||||
import { AuthorizationDataService } from 'src/app/core/data/feature-authorization/authorization-data.service';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { map, take } from 'rxjs/operators';
|
||||
import { RemoteData } from '../core/data/remote-data';
|
||||
import { Collection } from 'src/app/core/shared/collection.model';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
|
||||
|
||||
/**
|
||||
* Component representing the public navbar
|
||||
|
@@ -10,9 +10,9 @@ import { MenuSection } from './menu.reducer';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { MenuID } from './initial-menus-state';
|
||||
import { AuthorizationDataService } from 'src/app/core/data/feature-authorization/authorization-data.service';
|
||||
import { createSuccessfulRemoteDataObject } from 'src/app/shared/remote-data.utils';
|
||||
import { Item } from '../../core/shared/item.model';
|
||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||
import { createSuccessfulRemoteDataObject } from '../remote-data.utils';
|
||||
|
||||
describe('MenuComponent', () => {
|
||||
let comp: MenuComponent;
|
||||
@@ -22,6 +22,8 @@ describe('MenuComponent', () => {
|
||||
|
||||
const mockMenuID = 'mock-menuID' as MenuID;
|
||||
|
||||
const mockStatisticSection = { 'id': 'statistics_site', 'active': true, 'visible': true, 'index': 2, 'type': 'statistics', 'model': { 'type': 1, 'text': 'menu.section.statistics', 'link': 'statistics' } };
|
||||
|
||||
const authorizationService = jasmine.createSpyObj('authorizationService', {
|
||||
isAuthorized: observableOf(true)
|
||||
});
|
||||
@@ -38,6 +40,7 @@ describe('MenuComponent', () => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const routeStub = {
|
||||
data: observableOf({
|
||||
dso: createSuccessfulRemoteDataObject(mockItem)
|
||||
@@ -125,36 +128,15 @@ describe('MenuComponent', () => {
|
||||
});
|
||||
|
||||
describe('when unauthorized statistics', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
comp.sections = observableOf([{ 'id': 'browse_global_communities_and_collections', 'active': false, 'visible': true, 'index': 0, 'model': { 'type': 1, 'text': 'menu.section.browse_global_communities_and_collections', 'link': '/community-list' }, 'shouldPersistOnRouteChange': true }, { 'id': 'browse_global', 'active': false, 'visible': true, 'index': 1, 'model': { 'type': 0, 'text': 'menu.section.browse_global' }, 'shouldPersistOnRouteChange': true }, { 'id': 'statistics_site', 'active': true, 'visible': true, 'index': 2, 'type': 'statistics', 'model': { 'type': 1, 'text': 'menu.section.statistics', 'link': 'statistics' } }]);
|
||||
authorizationService.isAuthorized().and.returnValue(observableOf(false));
|
||||
fixture.detectChanges();
|
||||
it('should get observable of empty object', () => {
|
||||
expect(comp.getAuthorizedStatistics(mockStatisticSection)).toBeObservable({});
|
||||
});
|
||||
|
||||
it('when authorized statistics', (done => {
|
||||
comp.sections.subscribe((sections) => {
|
||||
expect(sections.length).toEqual(2);
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('get authorized statistics', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
comp.sections = observableOf([{ 'id': 'browse_global_communities_and_collections', 'active': false, 'visible': true, 'index': 0, 'model': { 'type': 1, 'text': 'menu.section.browse_global_communities_and_collections', 'link': '/community-list' }, 'shouldPersistOnRouteChange': true }, { 'id': 'browse_global', 'active': false, 'visible': true, 'index': 1, 'model': { 'type': 0, 'text': 'menu.section.browse_global' }, 'shouldPersistOnRouteChange': true }, { 'id': 'statistics_site', 'active': true, 'visible': true, 'index': 2, 'type': 'statistics', 'model': { 'type': 1, 'text': 'menu.section.statistics', 'link': 'statistics' } }]);
|
||||
fixture.detectChanges();
|
||||
it('should get observable of empty object', () => {
|
||||
expect(comp.getAuthorizedStatistics(mockStatisticSection)).toBeObservable(mockStatisticSection);
|
||||
});
|
||||
});
|
||||
|
||||
it('get authorized statistics', (done => {
|
||||
comp.sections.subscribe((sections) => {
|
||||
expect(sections.length).toEqual(3);
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
@@ -9,9 +9,9 @@ import { hasValue, isNotEmpty, hasValueOperator, isNotEmptyOperator } from '../e
|
||||
import { MenuSectionComponent } from './menu-section/menu-section.component';
|
||||
import { getComponentForMenu } from './menu-section.decorator';
|
||||
import { compareArraysUsingIds } from '../../item-page/simple/item-types/shared/item-relationships-utils';
|
||||
import { AuthorizationDataService } from 'src/app/core/data/feature-authorization/authorization-data.service';
|
||||
import { FeatureID } from 'src/app/core/data/feature-authorization/feature-id';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
||||
|
||||
/**
|
||||
* A basic implementation of a MenuComponent
|
||||
@@ -87,7 +87,6 @@ export class MenuComponent implements OnInit, OnDestroy {
|
||||
|
||||
this.subs.push(
|
||||
this.sections.pipe(
|
||||
tap(t => console.log(t)),
|
||||
// if you return an array from a switchMap it will emit each element as a separate event.
|
||||
// So this switchMap is equivalent to a subscribe with a forEach inside
|
||||
switchMap((sections: MenuSection[]) => sections),
|
||||
|
@@ -32,13 +32,13 @@ import { RESOURCE_POLICY } from '../../../core/resource-policy/models/resource-p
|
||||
import { EPersonMock } from '../../testing/eperson.mock';
|
||||
import { isNotEmptyOperator } from '../../empty.util';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { RemoteData } from 'src/app/core/data/remote-data';
|
||||
import { RouterMock } from '../../mocks/router.mock';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { PaginationServiceStub } from '../../testing/pagination-service.stub';
|
||||
import { PaginationService } from 'src/app/core/pagination/pagination.service';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { StoreMock } from '../../testing/store.mock';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { PaginationService } from '../../../core/pagination/pagination.service';
|
||||
|
||||
export const mockResourcePolicyFormData = {
|
||||
name: [
|
||||
|
@@ -10,7 +10,7 @@ import { ThemedCommunityStatisticsPageComponent } from './community-statistics-p
|
||||
import { ThemedItemStatisticsPageComponent } from './item-statistics-page/themed-item-statistics-page.component';
|
||||
import { ThemedSiteStatisticsPageComponent } from './site-statistics-page/themed-site-statistics-page.component';
|
||||
import { ItemResolver } from '../item-page/item.resolver';
|
||||
import { StatisticsAdministratorGuard } from 'src/app/core/data/feature-authorization/feature-authorization-guard/statistics-administrator.guard';
|
||||
import { StatisticsAdministratorGuard } from '../core/data/feature-authorization/feature-authorization-guard/statistics-administrator.guard';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
|
@@ -15,6 +15,6 @@ getTestBed().initTestEnvironment(
|
||||
platformBrowserDynamicTesting()
|
||||
);
|
||||
// Then we find all the tests.
|
||||
const context = require.context('./app/shared/menu', true, /\.spec\.ts$/);
|
||||
const context = require.context('./', true, /\.spec\.ts$/);
|
||||
// And load the modules.
|
||||
context.keys().map(context);
|
||||
|
Reference in New Issue
Block a user