mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge branch 'feature-context-help-7.2' into feature-context-help-7.4
This commit is contained in:
@@ -10,7 +10,7 @@ describe('ContextHelpToggleComponent', () => {
|
||||
let component: ContextHelpToggleComponent;
|
||||
let fixture: ComponentFixture<ContextHelpToggleComponent>;
|
||||
let contextHelpService;
|
||||
let contextHelpEmpty$ = new BehaviorSubject(true);
|
||||
const contextHelpEmpty$ = new BehaviorSubject(true);
|
||||
|
||||
beforeEach(async () => {
|
||||
contextHelpService = jasmine.createSpyObj('contextHelpService',
|
||||
|
@@ -53,9 +53,9 @@ describe('ContextHelpWrapperComponent', () => {
|
||||
let shouldShowIcons$: BehaviorSubject<boolean>;
|
||||
|
||||
function makeWrappedElement(): HTMLElement {
|
||||
let el: HTMLElement = document.createElement('div')
|
||||
el.innerHTML = 'example element';
|
||||
return el;
|
||||
const wrapped: HTMLElement = document.createElement('div');
|
||||
wrapped.innerHTML = 'example element';
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
beforeEach(waitForAsync( () => {
|
||||
@@ -96,8 +96,8 @@ describe('ContextHelpWrapperComponent', () => {
|
||||
fixture = TestBed.createComponent(TemplateComponent);
|
||||
el = fixture.debugElement;
|
||||
templateComponent = fixture.componentInstance;
|
||||
templateComponent.content = 'lorem'
|
||||
templateComponent.id = 'test-tooltip'
|
||||
templateComponent.content = 'lorem';
|
||||
templateComponent.id = 'test-tooltip';
|
||||
templateComponent.tooltipPlacement = ['bottom'];
|
||||
templateComponent.iconPlacement = 'left';
|
||||
wrapperComponent = el.query(By.css('ds-context-help-wrapper')).componentInstance;
|
||||
@@ -111,7 +111,7 @@ describe('ContextHelpWrapperComponent', () => {
|
||||
|
||||
it('should not show the context help icon while icon visibility is not turned on', (done) => {
|
||||
fixture.whenStable().then(() => {
|
||||
let wrapper = el.query(By.css('ds-context-help-wrapper')).nativeElement;
|
||||
const wrapper = el.query(By.css('ds-context-help-wrapper')).nativeElement;
|
||||
expect(wrapper.children.length).toBe(0);
|
||||
done();
|
||||
});
|
||||
@@ -127,9 +127,9 @@ describe('ContextHelpWrapperComponent', () => {
|
||||
|
||||
it('should show the context help button', (done) => {
|
||||
fixture.whenStable().then(() => {
|
||||
let wrapper = el.query(By.css('ds-context-help-wrapper')).nativeElement;
|
||||
const wrapper = el.query(By.css('ds-context-help-wrapper')).nativeElement;
|
||||
expect(wrapper.children.length).toBe(1);
|
||||
let [i] = wrapper.children;
|
||||
const [i] = wrapper.children;
|
||||
expect(i.tagName).toBe('I');
|
||||
done();
|
||||
});
|
||||
@@ -160,7 +160,7 @@ describe('ContextHelpWrapperComponent', () => {
|
||||
const nodeList: NodeList = fixture.debugElement.query(By.css('.ds-context-help-content'))
|
||||
.nativeElement
|
||||
.childNodes;
|
||||
const relevantNodes = Array.from(nodeList).filter(node => node.nodeType != Node.COMMENT_NODE);
|
||||
const relevantNodes = Array.from(nodeList).filter(node => node.nodeType !== Node.COMMENT_NODE);
|
||||
expect(relevantNodes.length).toBe(4);
|
||||
|
||||
const [text1, link1, text2, link2] = relevantNodes;
|
||||
@@ -190,7 +190,7 @@ describe('ContextHelpWrapperComponent', () => {
|
||||
const nodeList: NodeList = fixture.debugElement.query(By.css('.ds-context-help-content'))
|
||||
.nativeElement
|
||||
.childNodes;
|
||||
const relevantNodes = Array.from(nodeList).filter(node => node.nodeType != Node.COMMENT_NODE);
|
||||
const relevantNodes = Array.from(nodeList).filter(node => node.nodeType !== Node.COMMENT_NODE);
|
||||
expect(relevantNodes.length).toBe(1);
|
||||
|
||||
const [text] = relevantNodes;
|
||||
|
@@ -55,8 +55,8 @@ export class ContextHelpWrapperComponent implements OnInit, OnDestroy {
|
||||
|
||||
tooltip: NgbTooltip;
|
||||
|
||||
@Input() set content(content : string) {
|
||||
this.content$.next(content);
|
||||
@Input() set content(translateKey: string) {
|
||||
this.content$.next(translateKey);
|
||||
}
|
||||
private content$: BehaviorSubject<string | undefined> = new BehaviorSubject(undefined);
|
||||
|
||||
@@ -72,11 +72,11 @@ export class ContextHelpWrapperComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit() {
|
||||
this.parsedContent$ = combineLatest([
|
||||
this.content$.pipe(distinctUntilChanged(), mergeMap(content => this.translateService.get(content))),
|
||||
this.content$.pipe(distinctUntilChanged(), mergeMap(translateKey => this.translateService.get(translateKey))),
|
||||
this.dontParseLinks$.pipe(distinctUntilChanged())
|
||||
]).pipe(
|
||||
map(([content, dontParseLinks]) =>
|
||||
dontParseLinks ? [content] : this.parseLinks(content))
|
||||
map(([text, dontParseLinks]) =>
|
||||
dontParseLinks ? [text] : this.parseLinks(text))
|
||||
);
|
||||
this.shouldShowIcon$ = this.contextHelpService.shouldShowIcons$();
|
||||
this.subs.always = [this.parsedContent$.subscribe(), this.shouldShowIcon$.subscribe()];
|
||||
@@ -136,7 +136,7 @@ export class ContextHelpWrapperComponent implements OnInit, OnDestroy {
|
||||
* {href: "https://youtube.com", text: "so is this"}
|
||||
* ]
|
||||
*/
|
||||
private parseLinks(content: string): ParsedContent {
|
||||
private parseLinks(text: string): ParsedContent {
|
||||
// Implementation note: due to `matchAll` method on strings not being available for all versions,
|
||||
// separate "split" and "parse" steps are needed.
|
||||
|
||||
@@ -152,7 +152,7 @@ export class ContextHelpWrapperComponent implements OnInit, OnDestroy {
|
||||
// {href: string, text: string} objects.
|
||||
const parseRegexp = /^\[([^\]]*)\]\(([^\)]*)\)$/;
|
||||
|
||||
return content.match(splitRegexp).map((substring: string) => {
|
||||
return text.match(splitRegexp).map((substring: string) => {
|
||||
const match = substring.match(parseRegexp);
|
||||
return match === null
|
||||
? substring
|
||||
|
@@ -11,6 +11,8 @@ export const ContextHelpActionTypes = {
|
||||
'CONTEXT_HELP_HIDE_TOOLTIP' : type('dspace/context-help/CONTEXT_HELP_HIDE_TOOLTIP'),
|
||||
};
|
||||
|
||||
/* tslint:disable:max-classes-per-file */
|
||||
|
||||
/**
|
||||
* Toggles the visibility of all context help icons.
|
||||
*/
|
||||
|
@@ -62,7 +62,7 @@ describe('ContextHelpDirective', () => {
|
||||
{ provide: ContextHelpService, useValue: contextHelpService }
|
||||
],
|
||||
declarations: [TestComponent, ContextHelpWrapperComponent, ContextHelpDirective]
|
||||
}).compileComponents()
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -85,10 +85,10 @@ describe('ContextHelpDirective', () => {
|
||||
it('should generate the context help wrapper component', (done) => {
|
||||
fixture.whenStable().then(() => {
|
||||
expect(fixture.nativeElement.children.length).toBe(1);
|
||||
let [wrapper] = fixture.nativeElement.children;
|
||||
const [wrapper] = fixture.nativeElement.children;
|
||||
expect(component).toBeDefined();
|
||||
expect(wrapper.tagName).toBe('DS-CONTEXT-HELP-WRAPPER');
|
||||
expect(contextHelpService.add).toHaveBeenCalledWith(exampleContextHelp)
|
||||
expect(contextHelpService.add).toHaveBeenCalledWith(exampleContextHelp);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@@ -1,4 +1,4 @@
|
||||
export class ContextHelp {
|
||||
id: string;
|
||||
isTooltipVisible?: boolean = false;
|
||||
isTooltipVisible = false;
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { ContextHelp } from './context-help.model';
|
||||
import { ContextHelpAction, ContextHelpActionTypes } from './context-help.actions';
|
||||
|
||||
export type ContextHelpModels = {
|
||||
export interface ContextHelpModels {
|
||||
[id: string]: ContextHelp;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ContextHelpState {
|
||||
allIconsVisible: boolean;
|
||||
|
@@ -8,10 +8,9 @@ import { TestScheduler } from 'rxjs/testing';
|
||||
describe('ContextHelpService', () => {
|
||||
let service: ContextHelpService;
|
||||
let store;
|
||||
let initialState;
|
||||
let testScheduler;
|
||||
const booleans = { f: false, t: true };
|
||||
const mkContextHelp = (id: string) => ({ 0: {id, isTooltipVisible: false}, 1: {id, isTooltipVisible: true} })
|
||||
const mkContextHelp = (id: string) => ({ 0: {id, isTooltipVisible: false}, 1: {id, isTooltipVisible: true} });
|
||||
|
||||
beforeEach(async () => {
|
||||
TestBed.configureTestingModule({
|
||||
@@ -42,11 +41,13 @@ describe('ContextHelpService', () => {
|
||||
it('add and remove calls should be observable in getContextHelp$', () => {
|
||||
testScheduler.run(({cold, expectObservable}) => {
|
||||
const modifications = cold('-abAcCB', {
|
||||
a: () => service.add({id: 'a'}), b: () => service.add({id: 'b'}), c: () => service.add({id: 'c'}),
|
||||
a: () => service.add({id: 'a', isTooltipVisible: false}),
|
||||
b: () => service.add({id: 'b', isTooltipVisible: false}),
|
||||
c: () => service.add({id: 'c', isTooltipVisible: false}),
|
||||
A: () => service.remove('a'), B: () => service.remove('b'), C: () => service.remove('c'),
|
||||
})
|
||||
});
|
||||
modifications.subscribe(mod => mod());
|
||||
const match = (id) => ({ 0: undefined, 1: {id} });
|
||||
const match = (id) => ({ 0: undefined, 1: {id, isTooltipVisible: false} });
|
||||
expectObservable(service.getContextHelp$('a')).toBe('01-0---', match('a'));
|
||||
expectObservable(service.getContextHelp$('b')).toBe('0-1---0', match('b'));
|
||||
expectObservable(service.getContextHelp$('c')).toBe('0---10-', match('c'));
|
||||
|
Reference in New Issue
Block a user