Skip to content

fix(router): fix return value for getTransition of NSRouterLink #1787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions nativescript-angular/router/ns-router-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class NSRouterLink { // tslint:disable-line:directive-class-suffix
}

private getTransition(): { animated: boolean, transition?: NavigationTransition } {
let transition: NavigationTransition = {};
let transition: NavigationTransition;
let animated: boolean;

if (typeof this.pageTransition === "boolean") {
Expand All @@ -125,7 +125,9 @@ export class NSRouterLink { // tslint:disable-line:directive-class-suffix
animated = false;
} else {
animated = true;
transition.name = <string>this.pageTransition;
transition = {
name: <string>this.pageTransition
};
}
} else {
animated = true;
Expand All @@ -134,6 +136,7 @@ export class NSRouterLink { // tslint:disable-line:directive-class-suffix

let duration = +this.pageTransitionDuration;
if (!isNaN(duration)) {
transition = transition || {};
transition.duration = duration;
}

Expand Down
43 changes: 43 additions & 0 deletions tests/app/tests/ns-router-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {NSRouterLink} from "nativescript-angular/router/ns-router-link";
import {ActivatedRoute, Router} from "@angular/router";
import {RouterExtensions} from "nativescript-angular/router";
import {assert, fake, spy, stub} from "./test-config";
import {SinonStub} from "sinon";

describe("NSRouterLink", () => {

const mockRouter = {} as Router;
let mockRouterExtensions = {
navigateByUrl: fake()
};
const mockActivatedRoute = {} as ActivatedRoute;
let nsRouterLink: NSRouterLink;
let urlTreeStub: SinonStub;

beforeEach(() => {
nsRouterLink = new NSRouterLink(mockRouter, mockRouterExtensions as unknown as RouterExtensions, mockActivatedRoute);
urlTreeStub = stub(nsRouterLink, 'urlTree').get(() => null);
});

afterEach(() => {
urlTreeStub.restore();
});

it('#tap should call navigateByUrl with undefined transition in extras when boolean is given for pageTransition input', () => {
nsRouterLink.pageTransition = false;
nsRouterLink.onTap();
assert.isUndefined(mockRouterExtensions.navigateByUrl.lastCall.args[1].transition);
});

it('#tap should call navigateByUrl with correct transition in extras when NavigationTransition object is given for pageTransition input', () => {
const pageTransition = {
name: 'slide',
duration: 500
};
nsRouterLink.pageTransition = pageTransition;
stub(nsRouterLink, 'urlTree').get(() => null);
nsRouterLink.onTap();
assert.equal(pageTransition, mockRouterExtensions.navigateByUrl.lastCall.args[1].transition);
});

});
4 changes: 4 additions & 0 deletions tests/app/tests/test-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
});

import * as chai from "chai";
import * as sinon from "sinon";
export let assert: typeof chai.assert = (<any>global).chai.assert;
export let fake: typeof sinon.fake = (<any>global).sinon.fake;
export let spy: typeof sinon.spy = (<any>global).sinon.spy;
export let stub: typeof sinon.stub = (<any>global).sinon.stub;
2 changes: 1 addition & 1 deletion tests/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function(config) {

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai'],
frameworks: ['mocha', 'chai', 'sinon'],


// list of files / patterns to load in the browser
Expand Down
11 changes: 7 additions & 4 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,21 @@
"devDependencies": {
"@types/chai": "^4.1.4",
"@types/mocha": "^5.2.4",
"@types/sinon": "^7.0.11",
"babel-traverse": "6.8.0",
"babel-types": "6.8.1",
"babylon": "6.8.0",
"chai": "4.1.2",
"karma": "2.0.4",
"karma-chai": "0.1.0",
"karma-mocha": "1.3.0",
"karma-mocha-reporter": "2.2.5",
"karma-nativescript-launcher": "0.4.0",
"karma-sinon": "^1.0.5",
"lazy": "1.0.11",
"mocha": "5.2.0",
"nativescript-dev-typescript": "next",
"babel-traverse": "6.8.0",
"babel-types": "6.8.1",
"babylon": "6.8.0",
"lazy": "1.0.11",
"sinon": "^7.3.2",
"tslint": "^4.5.1",
"typescript": "~3.1.1"
},
Expand Down