mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
97399 WIP: Tests for ContextHelpDirective
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<div class="page-internal-server-error container">
|
||||
<h1>500</h1>
|
||||
<h2><small>{{"500.page-internal-server-error" | translate}}</small></h2>
|
||||
<h2><small *dsContextHelp="{content: 'context-help.multi-para.test'}">{{"500.page-internal-server-error" | translate}}</small></h2>
|
||||
<br/>
|
||||
<p>{{"500.help" | translate}}</p>
|
||||
<br/>
|
||||
|
@@ -53,7 +53,7 @@ export class ContextHelpWrapperComponent {
|
||||
* into link-free pieces of text and objects of the form
|
||||
* {href: string, text: string} (which represent links).
|
||||
* This function makes no effort to check whether the href is a
|
||||
* correct URL. Currently this function does not support escape
|
||||
* correct URL. Currently, this function does not support escape
|
||||
* characters: its behavior when given a string containing square
|
||||
* brackets that do not deliminate a link is undefined.
|
||||
* Regular parentheses outside of links do work, however.
|
||||
|
@@ -1,8 +1,65 @@
|
||||
import { ContextHelpDirective } from './context-help.directive';
|
||||
import { Component, DebugElement, Input } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { of as observableOf, Observable } from 'rxjs';
|
||||
import { ContextHelpDirective, ContextHelpDirectiveInput } from './context-help.directive';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { ContextHelpWrapperComponent } from './context-help-wrapper/context-help-wrapper.component';
|
||||
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
@Component({
|
||||
template: `<div *dsContextHelp="contextHelpParams()">some text</div>`
|
||||
})
|
||||
class TestComponent {
|
||||
@Input() content = '';
|
||||
contextHelpParams(): ContextHelpDirectiveInput {
|
||||
return {
|
||||
content: this.content
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:max-classes-per-file
|
||||
class MockTranslateService {
|
||||
messages: {[index: string]: string} = {
|
||||
lorem: 'lorem ipsum dolor sit amet',
|
||||
linkTest: 'This is text, [this](https://dspace.lyrasis.org) is a link, and [so is this](https://google.com)'
|
||||
};
|
||||
|
||||
get(key: string): Observable<string> {
|
||||
return observableOf(this.messages[key]);
|
||||
}
|
||||
}
|
||||
|
||||
describe('ContextHelpDirective', () => {
|
||||
it('should create an instance', () => {
|
||||
const directive = new ContextHelpDirective();
|
||||
expect(directive).toBeTruthy();
|
||||
let component: TestComponent;
|
||||
let fixture: ComponentFixture<TestComponent>;
|
||||
// let el: DebugElement;
|
||||
// let translateService: TranslateService;
|
||||
|
||||
beforeEach(() => {
|
||||
console.log('Anyone hear that?');
|
||||
fixture = TestBed.configureTestingModule({
|
||||
imports: [NgbTooltipModule],
|
||||
providers: [
|
||||
{ provide: TranslateService, useClass: MockTranslateService }
|
||||
],
|
||||
declarations: [TestComponent, ContextHelpWrapperComponent, ContextHelpDirective]
|
||||
}).createComponent(TestComponent);
|
||||
component = fixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should add the tooltip icon', () => {
|
||||
component.content = 'lorem';
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component).toBeDefined();
|
||||
const [wrapper] = fixture.nativeElement.children;
|
||||
const [i, div] = wrapper.children;
|
||||
expect(wrapper.tagName).toBe('DS-CONTEXT-HELP-WRAPPER');
|
||||
expect(i.tagName).toBe('I');
|
||||
expect(div.tagName).toBe('DIV');
|
||||
expect(div.innerHTML).toBe('some text');
|
||||
i.click(); // TODO: triggers a type error
|
||||
});
|
||||
});
|
||||
|
@@ -3,10 +3,10 @@ import { PlacementArray } from '@ng-bootstrap/ng-bootstrap/util/positioning';
|
||||
import { ContextHelpWrapperComponent } from './context-help-wrapper/context-help-wrapper.component';
|
||||
import { PlacementDir } from './context-help-wrapper/placement-dir.model';
|
||||
|
||||
export type ContextHelpDirectiveInput = {
|
||||
content: string,
|
||||
tooltipPlacement?: PlacementArray,
|
||||
iconPlacement?: PlacementDir
|
||||
export interface ContextHelpDirectiveInput {
|
||||
content: string;
|
||||
tooltipPlacement?: PlacementArray;
|
||||
iconPlacement?: PlacementDir;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user