From 7812eecb53668a202abfe115c93384279e346efc Mon Sep 17 00:00:00 2001 From: Koen Pauwels Date: Mon, 16 Jan 2023 11:07:47 +0100 Subject: [PATCH] 97732 Fix linter issues --- .../context-help-toggle.component.spec.ts | 2 +- .../context-help-wrapper.component.spec.ts | 20 +++++++++---------- .../context-help-wrapper.component.ts | 14 ++++++------- src/app/shared/context-help.actions.ts | 2 ++ src/app/shared/context-help.directive.spec.ts | 6 +++--- src/app/shared/context-help.directive.ts | 2 +- src/app/shared/context-help.model.ts | 2 +- src/app/shared/context-help.reducer.ts | 4 ++-- src/app/shared/context-help.service.spec.ts | 11 +++++----- 9 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/app/header/context-help-toggle/context-help-toggle.component.spec.ts b/src/app/header/context-help-toggle/context-help-toggle.component.spec.ts index 8f98aaaabc..1df646f8aa 100644 --- a/src/app/header/context-help-toggle/context-help-toggle.component.spec.ts +++ b/src/app/header/context-help-toggle/context-help-toggle.component.spec.ts @@ -10,7 +10,7 @@ describe('ContextHelpToggleComponent', () => { let component: ContextHelpToggleComponent; let fixture: ComponentFixture; let contextHelpService; - let contextHelpEmpty$ = new BehaviorSubject(true); + const contextHelpEmpty$ = new BehaviorSubject(true); beforeEach(async () => { contextHelpService = jasmine.createSpyObj('contextHelpService', diff --git a/src/app/shared/context-help-wrapper/context-help-wrapper.component.spec.ts b/src/app/shared/context-help-wrapper/context-help-wrapper.component.spec.ts index c0c7f9a821..e9ff9b0856 100644 --- a/src/app/shared/context-help-wrapper/context-help-wrapper.component.spec.ts +++ b/src/app/shared/context-help-wrapper/context-help-wrapper.component.spec.ts @@ -53,9 +53,9 @@ describe('ContextHelpWrapperComponent', () => { let shouldShowIcons$: BehaviorSubject; 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; diff --git a/src/app/shared/context-help-wrapper/context-help-wrapper.component.ts b/src/app/shared/context-help-wrapper/context-help-wrapper.component.ts index 1bf3dc1ce0..51bb9531cd 100644 --- a/src/app/shared/context-help-wrapper/context-help-wrapper.component.ts +++ b/src/app/shared/context-help-wrapper/context-help-wrapper.component.ts @@ -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 = 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 diff --git a/src/app/shared/context-help.actions.ts b/src/app/shared/context-help.actions.ts index 5f985c2f73..fa602b6bcf 100644 --- a/src/app/shared/context-help.actions.ts +++ b/src/app/shared/context-help.actions.ts @@ -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. */ diff --git a/src/app/shared/context-help.directive.spec.ts b/src/app/shared/context-help.directive.spec.ts index 70e27b658c..8fb03061fc 100644 --- a/src/app/shared/context-help.directive.spec.ts +++ b/src/app/shared/context-help.directive.spec.ts @@ -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(); }); }); diff --git a/src/app/shared/context-help.directive.ts b/src/app/shared/context-help.directive.ts index 83c3908dcf..22005cc066 100644 --- a/src/app/shared/context-help.directive.ts +++ b/src/app/shared/context-help.directive.ts @@ -47,7 +47,7 @@ export class ContextHelpDirective implements OnChanges, OnDestroy { private viewContainerRef: ViewContainerRef, private componentFactoryResolver: ComponentFactoryResolver, private contextHelpService: ContextHelpService - ){} + ) {} ngOnChanges() { this.clearMostRecentId(); diff --git a/src/app/shared/context-help.model.ts b/src/app/shared/context-help.model.ts index 9c024dbf1f..ea6fd036cf 100644 --- a/src/app/shared/context-help.model.ts +++ b/src/app/shared/context-help.model.ts @@ -1,4 +1,4 @@ export class ContextHelp { id: string; - isTooltipVisible?: boolean = false; + isTooltipVisible = false; } diff --git a/src/app/shared/context-help.reducer.ts b/src/app/shared/context-help.reducer.ts index 13e9488dfd..9ff8a06989 100644 --- a/src/app/shared/context-help.reducer.ts +++ b/src/app/shared/context-help.reducer.ts @@ -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; diff --git a/src/app/shared/context-help.service.spec.ts b/src/app/shared/context-help.service.spec.ts index 96b81ee8e1..f06e700210 100644 --- a/src/app/shared/context-help.service.spec.ts +++ b/src/app/shared/context-help.service.spec.ts @@ -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'));