mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
feat: fix DsoEditMenuSectionComponent test
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
import { MenuServiceStub } from '../../../testing/menu-service.stub';
|
import { MenuServiceStub } from '../../../testing/menu-service.stub';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
|
||||||
import { MenuService } from '../../../menu/menu.service';
|
import { MenuService } from '../../../menu/menu.service';
|
||||||
import { CSSVariableService } from '../../../sass-helper/css-variable.service';
|
import { CSSVariableService } from '../../../sass-helper/css-variable.service';
|
||||||
import { CSSVariableServiceStub } from '../../../testing/css-variable-service.stub';
|
import { CSSVariableServiceStub } from '../../../testing/css-variable-service.stub';
|
||||||
import { Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { RouterStub } from '../../../testing/router.stub';
|
import { RouterStub } from '../../../testing/router.stub';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
@@ -12,23 +11,31 @@ import { By } from '@angular/platform-browser';
|
|||||||
import { DsoEditMenuSectionComponent } from './dso-edit-menu-section.component';
|
import { DsoEditMenuSectionComponent } from './dso-edit-menu-section.component';
|
||||||
import { OnClickMenuItemModel } from '../../../menu/menu-item/models/onclick.model';
|
import { OnClickMenuItemModel } from '../../../menu/menu-item/models/onclick.model';
|
||||||
import { MenuItemType } from 'src/app/shared/menu/menu-item-type.model';
|
import { MenuItemType } from 'src/app/shared/menu/menu-item-type.model';
|
||||||
|
import { ActivatedRouteStub } from '../../../testing/active-router.stub';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
|
||||||
function initAsync(dummySectionText: { visible: boolean; icon: string; active: boolean; model: { disabled: boolean; text: string; type: MenuItemType }; id: string }, menuService: MenuServiceStub) {
|
function initAsync(dummySectionText: {
|
||||||
|
visible: boolean;
|
||||||
|
icon: string;
|
||||||
|
active: boolean;
|
||||||
|
model: { disabled: boolean; text: string; type: MenuItemType };
|
||||||
|
id: string
|
||||||
|
}, menuService: MenuServiceStub) {
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot(), DsoEditMenuSectionComponent, TestComponent],
|
imports: [
|
||||||
providers: [
|
TranslateModule.forRoot(),
|
||||||
{ provide: 'sectionDataProvider', useValue: dummySectionText },
|
DsoEditMenuSectionComponent,
|
||||||
{ provide: MenuService, useValue: menuService },
|
TestComponent
|
||||||
{ provide: CSSVariableService, useClass: CSSVariableServiceStub },
|
],
|
||||||
{ provide: Router, useValue: new RouterStub() },
|
providers: [
|
||||||
]
|
{provide: 'sectionDataProvider', useValue: dummySectionText},
|
||||||
}).overrideComponent(DsoEditMenuSectionComponent, {
|
{provide: MenuService, useValue: menuService},
|
||||||
set: {
|
{provide: CSSVariableService, useClass: CSSVariableServiceStub},
|
||||||
entryComponents: [TestComponent]
|
{provide: Router, useValue: new RouterStub()},
|
||||||
}
|
{provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
|
||||||
})
|
]
|
||||||
.compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +68,6 @@ describe('DsoEditMenuSectionComponent', () => {
|
|||||||
},
|
},
|
||||||
icon: iconString
|
icon: iconString
|
||||||
};
|
};
|
||||||
|
|
||||||
const dummySectionClick = {
|
const dummySectionClick = {
|
||||||
id: 'dummy',
|
id: 'dummy',
|
||||||
active: false,
|
active: false,
|
||||||
@@ -77,6 +83,7 @@ describe('DsoEditMenuSectionComponent', () => {
|
|||||||
|
|
||||||
describe('text model', () => {
|
describe('text model', () => {
|
||||||
initAsync(dummySectionText, menuService);
|
initAsync(dummySectionText, menuService);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(menuService, 'getSubSectionsByParentID').and.returnValue(observableOf([]));
|
spyOn(menuService, 'getSubSectionsByParentID').and.returnValue(observableOf([]));
|
||||||
fixture = TestBed.createComponent(DsoEditMenuSectionComponent);
|
fixture = TestBed.createComponent(DsoEditMenuSectionComponent);
|
||||||
@@ -93,6 +100,7 @@ describe('DsoEditMenuSectionComponent', () => {
|
|||||||
const button = fixture.debugElement.query(By.css('.btn-dark'));
|
const button = fixture.debugElement.query(By.css('.btn-dark'));
|
||||||
expect(button.nativeElement.innerHTML).toContain('fa-' + iconString);
|
expect(button.nativeElement.innerHTML).toContain('fa-' + iconString);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the section model in a disabled link or text', () => {
|
describe('when the section model in a disabled link or text', () => {
|
||||||
it('should show just the button', () => {
|
it('should show just the button', () => {
|
||||||
const textButton = fixture.debugElement.query(By.css('div div button'));
|
const textButton = fixture.debugElement.query(By.css('div div button'));
|
||||||
|
Reference in New Issue
Block a user