From 0687e192758a51044284624605590584b3bc967c Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Tue, 19 Sep 2017 09:54:10 -0700 Subject: [PATCH] feat(uiSrefStatus): Emit all enclosed uiSref targetStates in the status object Closes https://github.com/ui-router/angular/pull/142 --- src/directives/uiSrefStatus.ts | 12 ++++++------ test/uiSrefStatus/uiSrefStatus.spec.ts | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/directives/uiSrefStatus.ts b/src/directives/uiSrefStatus.ts index 1d4142bb0..8c6a41bb5 100644 --- a/src/directives/uiSrefStatus.ts +++ b/src/directives/uiSrefStatus.ts @@ -32,8 +32,8 @@ export interface SrefStatus { entering: boolean; /** A transition is exiting the sref's target state */ exiting: boolean; - /** The sref's target state identifier */ - identifier: StateOrName; + /** The enclosed sref(s) target state(s) */ + targetStates: TargetState[]; } /** @internalapi */ @@ -42,7 +42,7 @@ const inactiveStatus: SrefStatus = { exact: false, entering: false, exiting: false, - identifier: null, + targetStates: [], }; /** @@ -120,18 +120,18 @@ function getSrefStatus(event: TransEvt, srefTarget: TargetState): SrefStatus { exact: isExact(), entering: isStartEvent ? isEntering() : false, exiting: isStartEvent ? isExiting() : false, - identifier: srefTarget.identifier(), + targetStates: [srefTarget], } as SrefStatus; } /** @internalapi */ -function mergeSrefStatus(left: SrefStatus, right: SrefStatus) { +function mergeSrefStatus(left: SrefStatus, right: SrefStatus): SrefStatus { return { active: left.active || right.active, exact: left.exact || right.exact, entering: left.entering || right.entering, exiting: left.exiting || right.exiting, - identifier: left.identifier || right.identifier, + targetStates: left.targetStates.concat(right.targetStates), }; } diff --git a/test/uiSrefStatus/uiSrefStatus.spec.ts b/test/uiSrefStatus/uiSrefStatus.spec.ts index 2069cec26..94364ed6c 100644 --- a/test/uiSrefStatus/uiSrefStatus.spec.ts +++ b/test/uiSrefStatus/uiSrefStatus.spec.ts @@ -42,10 +42,11 @@ describe('uiSrefStatus', () => { de.triggerEventHandler('click', {}); })); - it('should emit a event with identifier equals to `foo`', () => { - expect(component.updated).toHaveBeenCalledWith(jasmine.objectContaining({ - identifier: 'foo', - })); + it('should emit a event with a TargetState pointing to `foo`', () => { + expect(component.updated).toHaveBeenCalled(); + const arg: SrefStatus = (component.updated as jasmine.Spy).calls.mostRecent().args[0]; + expect(arg.targetStates.length).toEqual(1); + expect(arg.targetStates[0].state()).toEqual(jasmine.objectContaining({ name: 'foo' })); }); }); });