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>
<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>
<ion-button onclick="toggleFullscreen()">Toggle content.fullscreen</ion-button>
<p>

View File

@ -310,8 +310,8 @@ export class Nav implements NavOutlet {
const router = this.win.document.querySelector('ion-router');
if (router) {
const direction = (result.direction === 'back')
? RouterIntent.Back
: RouterIntent.Forward;
? -1
: 1;
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';
describe('parseURL', () => {
@ -179,62 +179,62 @@ describe('readPath', () => {
describe('writePath', () => {
it('should write root path (no hash)', () => {
const history = mockHistory();
writePath(history, '', false, [''], RouterDirection.Forward, 123);
writePath(history, '', false, [''], RouterIntent.Forward, 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');
writePath(history, '/', false, [''], RouterDirection.Forward, 123);
writePath(history, '/', false, [''], RouterIntent.Forward, 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');
});
it('should write non root path (no hash)', () => {
const history = mockHistory();
writePath(history, '/path', false, [''], RouterDirection.Forward, 2);
writePath(history, '/path', false, [''], RouterIntent.Forward, 2);
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');
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');
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');
});
it('should write root path (no hash)', () => {
const history = mockHistory();
writePath(history, '', true, [''], RouterDirection.Forward, 123);
writePath(history, '', true, [''], RouterIntent.Forward, 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');
writePath(history, '/', true, [''], RouterDirection.Forward, 123);
writePath(history, '/', true, [''], RouterIntent.Forward, 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');
});
it('should write non root path (no hash)', () => {
const history = mockHistory();
writePath(history, '/path', true, [''], RouterDirection.Forward, 123);
writePath(history, '/path', true, [''], RouterIntent.Forward, 123);
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');
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');
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');
});
});

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> {
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 {
const path = segments

View File

@ -1,5 +1,5 @@
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';
@ -262,7 +262,7 @@ export class Tabs implements NavOutlet {
if (this.useRouter) {
const router = this.doc.querySelector('ion-router');
if (router) {
return router.navChanged(RouterIntent.Forward);
return router.navChanged(1);
}
}
return Promise.resolve(false);