From b9d47d5bce5f54f98683e5460bdf02d318d204ef Mon Sep 17 00:00:00 2001 From: Oscar Busk Date: Fri, 20 Aug 2021 17:19:55 +0200 Subject: [PATCH 1/2] Update uiSref input type to match functionality. Was updating our code to try to use strict templates and was noting failures on templates that has been working for years. Noticed that the inputtype to `uiSref` is "string" when it works just fine with a declaration or object too, since the internal uses all support StateOrName. --- src/directives/uiSref.ts | 4 ++-- test/uiSref/uiSref.spec.ts | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/directives/uiSref.ts b/src/directives/uiSref.ts index c332f41a5..54e343c24 100644 --- a/src/directives/uiSref.ts +++ b/src/directives/uiSref.ts @@ -1,4 +1,4 @@ -import { UIRouter, extend, Obj, TransitionOptions, TargetState, isNumber, isNullOrUndefined } from '@uirouter/core'; +import { UIRouter, extend, Obj, StateOrName, TransitionOptions, TargetState, isNumber, isNullOrUndefined } from '@uirouter/core'; import { Directive, Inject, @@ -87,7 +87,7 @@ export class UISref implements OnChanges { * Home * ``` */ - @Input('uiSref') state: string; + @Input('uiSref') state: StateOrName; /** * `@Input('uiParams')` The parameter values to use (as key/values) diff --git a/test/uiSref/uiSref.spec.ts b/test/uiSref/uiSref.spec.ts index 132f9a870..76e383656 100644 --- a/test/uiSref/uiSref.spec.ts +++ b/test/uiSref/uiSref.spec.ts @@ -5,7 +5,7 @@ import { By } from '@angular/platform-browser'; import { UIRouterModule } from '../../src/uiRouterNgModule'; import { UISref } from '../../src/directives/uiSref'; -import { UIRouter, TargetState, TransitionOptions } from '@uirouter/core'; +import { UIRouter, StateDeclaration, TargetState, TransitionOptions } from '@uirouter/core'; import { Subscription } from 'rxjs'; import { clickOnElement } from '../testUtils'; @@ -14,6 +14,7 @@ describe('uiSref', () => { template: ` + `, }) class TestComponent { @@ -22,6 +23,7 @@ describe('uiSref', () => { linkAOptions: TransitionOptions; targetA: string; linkB: string; + linkC: StateDeclaration; @ViewChildren(UISref) srefs: QueryList; @@ -39,6 +41,7 @@ describe('uiSref', () => { this.linkAOptions = null; this.targetA = ''; this.linkB = ''; + this.linkC = {}; } } @@ -112,6 +115,16 @@ describe('uiSref', () => { expect(gospy.mock.calls[0][0]).toBe('stateref'); }); + it('should handle when param is stateDeclaration', () => { + const { fixture, srefElements, router } = setup(); + const gospy = jest.spyOn(router.stateService, 'go'); + fixture.componentInstance.linkC = { name: 'stateref' }; + fixture.detectChanges(); + clickOnElement(srefElements[2]); + expect(gospy).toHaveBeenCalledTimes(1); + expect(gospy.mock.calls[0][0]).toEqual({ name: 'stateref' }); + }); + it('should ignore the click event when target is _blank', () => { const { fixture, srefElements, router } = setup(); const gospy = jest.spyOn(router.stateService, 'go'); From b6c259636541221af3327d6518cdcccd795abd65 Mon Sep 17 00:00:00 2001 From: Oscar Busk Date: Thu, 2 Dec 2021 13:56:46 +0100 Subject: [PATCH 2/2] Change type of uiSref setter --- src/directives/uiSref.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/directives/uiSref.ts b/src/directives/uiSref.ts index 54e343c24..3b9055f90 100644 --- a/src/directives/uiSref.ts +++ b/src/directives/uiSref.ts @@ -132,7 +132,7 @@ export class UISref implements OnChanges { } /** @internal */ - set uiSref(val: string) { + set uiSref(val: StateOrName) { this.state = val; this.update(); }