mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
[DURACOM-240] add and fix tests
This commit is contained in:

committed by
Giuseppe Digilio

parent
e1ba78c443
commit
3e30f64e9c
@@ -1,8 +0,0 @@
|
|||||||
// import { MathDirective } from './math.directive';
|
|
||||||
|
|
||||||
describe('MathDirective', () => {
|
|
||||||
it('should create an instance', () => {
|
|
||||||
// const directive = new MathDirective();
|
|
||||||
// expect(directive).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,16 +1,54 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
import {
|
||||||
|
Observable,
|
||||||
|
of,
|
||||||
|
} from 'rxjs';
|
||||||
|
|
||||||
import { MathService } from './math.service';
|
import {
|
||||||
|
MathJaxConfig,
|
||||||
|
MathService,
|
||||||
|
} from './math.service';
|
||||||
|
|
||||||
|
export class MockMathService extends MathService {
|
||||||
|
protected mathJaxOptions: any = {};
|
||||||
|
protected mathJax: MathJaxConfig = { source: '', id: '' };
|
||||||
|
protected mathJaxFallback: MathJaxConfig = { source: '', id: '' };
|
||||||
|
|
||||||
|
protected registerMathJaxAsync(config: MathJaxConfig): Promise<any> {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
ready(): Observable<boolean> {
|
||||||
|
return of(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
render(element: HTMLElement): void {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
describe('MathService', () => {
|
describe('MathService', () => {
|
||||||
let service: MathService;
|
let service: MockMathService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({});
|
TestBed.configureTestingModule({});
|
||||||
service = TestBed.inject(MathService);
|
service = new MockMathService();
|
||||||
|
spyOn(service, 'render');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be created', () => {
|
it('should be created', () => {
|
||||||
expect(service).toBeTruthy();
|
expect(service).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be ready', (done) => {
|
||||||
|
service.ready().subscribe(isReady => {
|
||||||
|
expect(isReady).toBe(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render', () => {
|
||||||
|
service.render(document.createElement('div'));
|
||||||
|
expect(service.render).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -18,6 +18,7 @@ import { APP_CONFIG } from '../../../../../config/app-config.interface';
|
|||||||
import { environment } from '../../../../../environments/environment';
|
import { environment } from '../../../../../environments/environment';
|
||||||
import { BrowseDefinitionDataService } from '../../../../core/browse/browse-definition-data.service';
|
import { BrowseDefinitionDataService } from '../../../../core/browse/browse-definition-data.service';
|
||||||
import { Item } from '../../../../core/shared/item.model';
|
import { Item } from '../../../../core/shared/item.model';
|
||||||
|
import { MathService } from '../../../../core/shared/math.service';
|
||||||
import {
|
import {
|
||||||
MetadataMap,
|
MetadataMap,
|
||||||
MetadataValue,
|
MetadataValue,
|
||||||
@@ -26,7 +27,7 @@ import { TranslateLoaderMock } from '../../../../shared/mocks/translate-loader.m
|
|||||||
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/remote-data.utils';
|
||||||
import { BrowseDefinitionDataServiceStub } from '../../../../shared/testing/browse-definition-data-service.stub';
|
import { BrowseDefinitionDataServiceStub } from '../../../../shared/testing/browse-definition-data-service.stub';
|
||||||
import { createPaginatedList } from '../../../../shared/testing/utils.test';
|
import { createPaginatedList } from '../../../../shared/testing/utils.test';
|
||||||
import { MarkdownPipe } from '../../../../shared/utils/markdown.pipe';
|
import { MarkdownDirective } from '../../../../shared/utils/markdown.directive';
|
||||||
import { MetadataValuesComponent } from '../../../field-components/metadata-values/metadata-values.component';
|
import { MetadataValuesComponent } from '../../../field-components/metadata-values/metadata-values.component';
|
||||||
import { ItemPageFieldComponent } from './item-page-field.component';
|
import { ItemPageFieldComponent } from './item-page-field.component';
|
||||||
|
|
||||||
@@ -65,12 +66,13 @@ describe('ItemPageFieldComponent', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
{ provide: APP_CONFIG, useValue: appConfig },
|
{ provide: APP_CONFIG, useValue: appConfig },
|
||||||
{ provide: BrowseDefinitionDataService, useValue: BrowseDefinitionDataServiceStub },
|
{ provide: BrowseDefinitionDataService, useValue: BrowseDefinitionDataServiceStub },
|
||||||
|
{ provide: MathService, useValue: {} },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA],
|
schemas: [NO_ERRORS_SCHEMA],
|
||||||
}).overrideComponent(ItemPageFieldComponent, {
|
}).overrideComponent(ItemPageFieldComponent, {
|
||||||
set: { changeDetection: ChangeDetectionStrategy.Default },
|
set: { changeDetection: ChangeDetectionStrategy.Default },
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
markdownSpy = spyOn(MarkdownPipe.prototype, 'transform');
|
markdownSpy = spyOn(MarkdownDirective.prototype, 'render');
|
||||||
fixture = TestBed.createComponent(ItemPageFieldComponent);
|
fixture = TestBed.createComponent(ItemPageFieldComponent);
|
||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
comp.item = mockItemWithMetadataFieldsAndValue(mockFields, mockValue);
|
comp.item = mockItemWithMetadataFieldsAndValue(mockFields, mockValue);
|
||||||
|
@@ -1,8 +1,42 @@
|
|||||||
|
import {
|
||||||
|
Component,
|
||||||
|
DebugElement,
|
||||||
|
} from '@angular/core';
|
||||||
|
import {
|
||||||
|
ComponentFixture,
|
||||||
|
TestBed,
|
||||||
|
} from '@angular/core/testing';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
|
import { MathService } from '../../core/shared/math.service';
|
||||||
|
import { MockMathService } from '../../core/shared/math.service.spec';
|
||||||
import { MarkdownDirective } from './markdown.directive';
|
import { MarkdownDirective } from './markdown.directive';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
template: `<div dsMarkdown="test"></div>`,
|
||||||
|
})
|
||||||
|
class TestComponent {}
|
||||||
|
|
||||||
describe('MarkdownDirective', () => {
|
describe('MarkdownDirective', () => {
|
||||||
it('should create an instance', () => {
|
let component: TestComponent;
|
||||||
const directive = new MarkdownDirective();
|
let fixture: ComponentFixture<TestComponent>;
|
||||||
expect(directive).toBeTruthy();
|
let divEl: DebugElement;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ TestComponent, MarkdownDirective ],
|
||||||
|
providers: [
|
||||||
|
{ provide: MathService, useClass: MockMathService },
|
||||||
|
],
|
||||||
|
}).compileComponents();
|
||||||
|
spyOn(MarkdownDirective.prototype, 'render');
|
||||||
|
fixture = TestBed.createComponent(TestComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
divEl = fixture.debugElement.query(By.css('div'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call render method', () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(MarkdownDirective.prototype.render).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user