test(router): fix tests

This commit is contained in:
Manu Mtz.-Almeida
2018-05-11 19:45:44 +02:00
parent 3da0c989b2
commit d0bd3ba89e
7 changed files with 11048 additions and 25 deletions

11023
core/package-lock.json generated

File diff suppressed because one or more lines are too long

View File

@ -19,7 +19,7 @@
</ion-header> </ion-header>
<div style="display: flex; flex: 1"> <div style="display: flex; flex: 1">
<ion-content scroll-enabled="false" padding style="text-align: center; flex: 2" id="content"> <ion-content padding style="text-align: center; flex: 2" id="content">
<f></f> <f></f>
<ion-button onclick="toggleFullscreen()">Toggle content.fullscreen</ion-button> <ion-button onclick="toggleFullscreen()">Toggle content.fullscreen</ion-button>
<p> <p>

View File

@ -310,8 +310,8 @@ export class Nav implements NavOutlet {
const router = this.win.document.querySelector('ion-router'); const router = this.win.document.querySelector('ion-router');
if (router) { if (router) {
const direction = (result.direction === 'back') const direction = (result.direction === 'back')
? RouterIntent.Back ? -1
: RouterIntent.Forward; : 1;
router.navChanged(direction); router.navChanged(direction);
} }

View File

@ -1,4 +1,4 @@
import { RouteChain, RouterDirection } from '../utils/interface'; import { RouteChain, RouterIntent } from '../utils/interface';
import { chainToPath, generatePath, parsePath, readPath, writePath } from '../utils/path'; import { chainToPath, generatePath, parsePath, readPath, writePath } from '../utils/path';
describe('parseURL', () => { describe('parseURL', () => {
@ -179,62 +179,62 @@ describe('readPath', () => {
describe('writePath', () => { describe('writePath', () => {
it('should write root path (no hash)', () => { it('should write root path (no hash)', () => {
const history = mockHistory(); const history = mockHistory();
writePath(history, '', false, [''], RouterDirection.Forward, 123); writePath(history, '', false, [''], RouterIntent.Forward, 123);
expect(history.pushState).toHaveBeenCalledWith(123, '', '/'); expect(history.pushState).toHaveBeenCalledWith(123, '', '/');
writePath(history, '', false, ['schedule'], RouterDirection.Forward, 123); writePath(history, '', false, ['schedule'], RouterIntent.Forward, 123);
expect(history.pushState).toHaveBeenCalledWith(123, '', '/schedule'); expect(history.pushState).toHaveBeenCalledWith(123, '', '/schedule');
writePath(history, '/', false, [''], RouterDirection.Forward, 123); writePath(history, '/', false, [''], RouterIntent.Forward, 123);
expect(history.pushState).toHaveBeenCalledWith(123, '', '/'); expect(history.pushState).toHaveBeenCalledWith(123, '', '/');
writePath(history, '/', false, ['to', 'schedule'], RouterDirection.Forward, 123); writePath(history, '/', false, ['to', 'schedule'], RouterIntent.Forward, 123);
expect(history.pushState).toHaveBeenCalledWith(123, '', '/to/schedule'); expect(history.pushState).toHaveBeenCalledWith(123, '', '/to/schedule');
}); });
it('should write non root path (no hash)', () => { it('should write non root path (no hash)', () => {
const history = mockHistory(); const history = mockHistory();
writePath(history, '/path', false, [''], RouterDirection.Forward, 2); writePath(history, '/path', false, [''], RouterIntent.Forward, 2);
expect(history.pushState).toHaveBeenCalledWith(2, '', '/path'); expect(history.pushState).toHaveBeenCalledWith(2, '', '/path');
writePath(history, '/path', false, ['to', 'page'], RouterDirection.Forward, 2); writePath(history, '/path', false, ['to', 'page'], RouterIntent.Forward, 2);
expect(history.pushState).toHaveBeenCalledWith(2, '', '/path/to/page'); expect(history.pushState).toHaveBeenCalledWith(2, '', '/path/to/page');
writePath(history, 'path/to', false, ['second', 'page'], RouterDirection.Forward, 2); writePath(history, 'path/to', false, ['second', 'page'], RouterIntent.Forward, 2);
expect(history.pushState).toHaveBeenCalledWith(2, '', '/path/to/second/page'); expect(history.pushState).toHaveBeenCalledWith(2, '', '/path/to/second/page');
writePath(history, '/path/to/', false, ['second', 'page'], RouterDirection.Forward, 2); writePath(history, '/path/to/', false, ['second', 'page'], RouterIntent.Forward, 2);
expect(history.pushState).toHaveBeenCalledWith(2, '', '/path/to/second/page'); expect(history.pushState).toHaveBeenCalledWith(2, '', '/path/to/second/page');
}); });
it('should write root path (no hash)', () => { it('should write root path (no hash)', () => {
const history = mockHistory(); const history = mockHistory();
writePath(history, '', true, [''], RouterDirection.Forward, 123); writePath(history, '', true, [''], RouterIntent.Forward, 123);
expect(history.pushState).toHaveBeenCalledWith(123, '', '#/'); expect(history.pushState).toHaveBeenCalledWith(123, '', '#/');
writePath(history, '', true, ['schedule'], RouterDirection.Forward, 123); writePath(history, '', true, ['schedule'], RouterIntent.Forward, 123);
expect(history.pushState).toHaveBeenCalledWith(123, '', '#/schedule'); expect(history.pushState).toHaveBeenCalledWith(123, '', '#/schedule');
writePath(history, '/', true, [''], RouterDirection.Forward, 123); writePath(history, '/', true, [''], RouterIntent.Forward, 123);
expect(history.pushState).toHaveBeenCalledWith(123, '', '#/'); expect(history.pushState).toHaveBeenCalledWith(123, '', '#/');
writePath(history, '/', true, ['to', 'schedule'], RouterDirection.Forward, 123); writePath(history, '/', true, ['to', 'schedule'], RouterIntent.Forward, 123);
expect(history.pushState).toHaveBeenCalledWith(123, '', '#/to/schedule'); expect(history.pushState).toHaveBeenCalledWith(123, '', '#/to/schedule');
}); });
it('should write non root path (no hash)', () => { it('should write non root path (no hash)', () => {
const history = mockHistory(); const history = mockHistory();
writePath(history, '/path', true, [''], RouterDirection.Forward, 123); writePath(history, '/path', true, [''], RouterIntent.Forward, 123);
expect(history.pushState).toHaveBeenCalledWith(123, '', '#/path'); expect(history.pushState).toHaveBeenCalledWith(123, '', '#/path');
writePath(history, '/path', true, ['to', 'page'], RouterDirection.Forward, 123); writePath(history, '/path', true, ['to', 'page'], RouterIntent.Forward, 123);
expect(history.pushState).toHaveBeenCalledWith(123, '', '#/path/to/page'); expect(history.pushState).toHaveBeenCalledWith(123, '', '#/path/to/page');
writePath(history, 'path/to', true, ['second', 'page'], RouterDirection.Forward, 123); writePath(history, 'path/to', true, ['second', 'page'], RouterIntent.Forward, 123);
expect(history.pushState).toHaveBeenCalledWith(123, '', '#/path/to/second/page'); expect(history.pushState).toHaveBeenCalledWith(123, '', '#/path/to/second/page');
writePath(history, '/path/to/', true, ['second', 'page'], RouterDirection.Forward, 123); writePath(history, '/path/to/', true, ['second', 'page'], RouterIntent.Forward, 123);
expect(history.pushState).toHaveBeenCalledWith(123, '', '#/path/to/second/page'); expect(history.pushState).toHaveBeenCalledWith(123, '', '#/path/to/second/page');
}); });
}); });

View File

@ -1,4 +1,5 @@
import { NavOutletElement, RouteChain, RouteID, RouterIntent } from '../../../interface'; import { NavOutletElement, RouteChain, RouteID } from '../../../interface';
import { RouterIntent } from './interface';
export async function writeNavState(root: HTMLElement | undefined, chain: RouteChain, intent: RouterIntent, index: number, changed = false): Promise<boolean> { export async function writeNavState(root: HTMLElement | undefined, chain: RouteChain, intent: RouterIntent, index: number, changed = false): Promise<boolean> {
try { try {

View File

@ -1,4 +1,5 @@
import { RouteChain, RouterIntent } from '../../../interface'; import { RouteChain } from '../../../interface';
import { RouterIntent } from './interface';
export function generatePath(segments: string[]): string { export function generatePath(segments: string[]): string {
const path = segments const path = segments

View File

@ -1,5 +1,5 @@
import { Build, Component, Element, Event, EventEmitter, Listen, Method, Prop, State } from '@stencil/core'; import { Build, Component, Element, Event, EventEmitter, Listen, Method, Prop, State } from '@stencil/core';
import { Config, NavOutlet, RouteID, RouteWrite, RouterIntent } from '../../interface'; import { Config, NavOutlet, RouteID, RouteWrite } from '../../interface';
import { TabbarLayout, TabbarPlacement } from '../tabbar/tabbar'; import { TabbarLayout, TabbarPlacement } from '../tabbar/tabbar';
@ -262,7 +262,7 @@ export class Tabs implements NavOutlet {
if (this.useRouter) { if (this.useRouter) {
const router = this.doc.querySelector('ion-router'); const router = this.doc.querySelector('ion-router');
if (router) { if (router) {
return router.navChanged(RouterIntent.Forward); return router.navChanged(1);
} }
} }
return Promise.resolve(false); return Promise.resolve(false);