Skip to content

Commit e38b3c8

Browse files
committed
Update tests project for RC6. Fix Karma tests.
1 parent 2887942 commit e38b3c8

26 files changed

+184
-152
lines changed

tests/app/app.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {MultiPageMain} from "./multi-page-main.component";
44

55
@Component({
66
selector: "my-app",
7-
directives: [SinglePageMain, MultiPageMain],
87
template: `
98
<multi-page-main></multi-page-main>
109
<!--

tests/app/base.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {ROUTER_DIRECTIVES, Router } from '@angular/router';
21
import {Component, OpaqueToken, OnInit, OnDestroy} from "@angular/core";
32
export const HOOKS_LOG = new OpaqueToken("Hooks log");
43
import {BehaviorSubject} from "rxjs";

tests/app/first.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {ROUTER_DIRECTIVES, Router, ActivatedRoute } from '@angular/router';
2-
import {Component, Inject} from "@angular/core";
3-
import {HOOKS_LOG, BaseComponent} from "./base.component";
4-
import {BehaviorSubject} from "rxjs";
1+
import { Router, ActivatedRoute } from '@angular/router';
2+
import { Component, Inject } from "@angular/core";
3+
import { HOOKS_LOG, BaseComponent } from "./base.component";
4+
import { BehaviorSubject } from "rxjs";
55

66
@Component({
77
selector: "first-comp",

tests/app/main.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ import {Page} from "ui/page";
1111
import {StackLayout} from "ui/layouts/stack-layout";
1212

1313
import * as application from "application";
14+
import "ui/styling/style";
15+
import "ui/frame";
1416
import {HOOKS_LOG} from "./base.component";
1517
import {MultiPageMain, routes as multiPageRoutes} from "./multi-page-main.component";
1618
import {SinglePageMain, routes as singlePageRoutes} from "./single-page-main.component";
17-
import {provide, OpaqueToken, NgModule} from "@angular/core";
19+
import {FirstComponent} from "./first.component";
20+
import {SecondComponent} from "./second.component";
21+
import { OpaqueToken, NgModule } from "@angular/core";
1822

1923
import {PageNavigationApp} from "./snippets/navigation/page-outlet";
2024
import {NavigationApp} from "./snippets/navigation/router-outlet";
@@ -33,18 +37,25 @@ trace.enable();
3337
// nativeScriptBootstrap(IconFontComponent);
3438
const platform = platformNativeScriptDynamic({bootInExistingPage: true});
3539
const root = new StackLayout();
36-
const rootViewProvider = provide(APP_ROOT_VIEW, { useValue: root });
40+
const rootViewProvider = {provide: APP_ROOT_VIEW, useValue: root};
3741
const singlePageHooksLog = new BehaviorSubject([]);
38-
const singlePageHooksLogProvider = provide(HOOKS_LOG, { useValue: singlePageHooksLog });
42+
const singlePageHooksLogProvider = {provide: HOOKS_LOG, useValue: singlePageHooksLog};
3943
const multiPageHooksLog = new BehaviorSubject([]);
40-
const multiPageHooksLogProvider = provide(HOOKS_LOG, { useValue: multiPageHooksLog });
44+
const multiPageHooksLogProvider = {provide: HOOKS_LOG, useValue: multiPageHooksLog};
4145

4246
@NgModule({
4347
bootstrap: [
4448
SinglePageMain
4549
],
4650
declarations: [
47-
SinglePageMain
51+
SinglePageMain,
52+
FirstComponent,
53+
SecondComponent,
54+
],
55+
entryComponents: [
56+
SinglePageMain,
57+
FirstComponent,
58+
SecondComponent,
4859
],
4960
imports: [
5061
NativeScriptModule,
@@ -69,7 +80,14 @@ class SinglePageModule {}
6980
MultiPageMain
7081
],
7182
declarations: [
72-
MultiPageMain
83+
MultiPageMain,
84+
FirstComponent,
85+
SecondComponent,
86+
],
87+
entryComponents: [
88+
MultiPageMain,
89+
FirstComponent,
90+
SecondComponent,
7391
],
7492
imports: [
7593
NativeScriptModule,

tests/app/multi-page-main.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import {ROUTER_DIRECTIVES, Router, RouterConfig } from '@angular/router';
2-
import {nsProvideRouter, NS_ROUTER_DIRECTIVES} from 'nativescript-angular/router';
1+
import {Router} from '@angular/router';
32
import {Component, ElementRef} from "@angular/core";
43
import {Location, LocationStrategy} from '@angular/common';
54
import {FirstComponent} from "./first.component";
65
import {SecondComponent} from "./second.component";
76

87
@Component({
98
selector: "multi-page-main",
10-
directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
119
template: `
1210
<Label text="Multi-page router"></Label>
1311
<page-router-outlet></page-router-outlet>
@@ -23,7 +21,7 @@ export class MultiPageMain {
2321
}
2422

2523
export const routes = [
26-
{ path: "", redirectTo: "first/multi-page", terminal: true },
24+
{ path: "", redirectTo: "first/multi-page", pathMatch: "full", terminal: true },
2725
{ path: "first/:id", component: FirstComponent },
2826
{ path: "second/:id", component: SecondComponent },
2927
];

tests/app/second.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ROUTER_DIRECTIVES, Router, ActivatedRoute } from '@angular/router';
1+
import {Router, ActivatedRoute } from '@angular/router';
22
import {Component, Inject} from "@angular/core";
33
import {Location} from "@angular/common";
44
import {HOOKS_LOG, BaseComponent} from "./base.component";

tests/app/single-page-main.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import {ROUTER_DIRECTIVES, Router, RouterConfig } from '@angular/router';
2-
import {nsProvideRouter} from 'nativescript-angular/router';
1+
import {Router} from '@angular/router';
32
import {Component, ElementRef} from "@angular/core";
43
import {Location, LocationStrategy} from '@angular/common';
54
import {FirstComponent} from "./first.component";
65
import {SecondComponent} from "./second.component";
76

87
@Component({
98
selector: "single-page-main",
10-
directives: [ROUTER_DIRECTIVES],
119
template: `
1210
<Label text="Single-page router"></Label>
1311
<router-outlet></router-outlet>
@@ -23,7 +21,7 @@ export class SinglePageMain {
2321
}
2422

2523
export const routes = [
26-
{ path: "", redirectTo: "first/single-page", terminal: true },
24+
{ path: "", redirectTo: "first/single-page", pathMatch: "full", terminal: true },
2725
{ path: "first/:id", component: FirstComponent },
2826
{ path: "second/:id", component: SecondComponent },
2927
];

tests/app/snippets/navigation/app.routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {FirstComponent, SecondComponent} from "./navigation-common";
22
// >> router-config-all
33
export const routes = [
4-
{ path: "", redirectTo: "/first", terminal: true },
4+
{ path: "", redirectTo: "/first", pathMatch: "full", terminal: true },
55
{ path: "first", component: FirstComponent },
66
{ path: "second", component: SecondComponent },
77
];
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// >> router-content-components
22
import {Component} from '@angular/core';
3-
import {NS_ROUTER_DIRECTIVES} from 'nativescript-angular/router';
43

54
@Component({
65
selector: "first",
7-
directives: [NS_ROUTER_DIRECTIVES],
86
template: `
97
<StackLayout>
108
<Label text="First component" class="title"></Label>
@@ -15,12 +13,11 @@ export class FirstComponent { }
1513

1614
@Component({
1715
selector: "second",
18-
directives: [NS_ROUTER_DIRECTIVES],
1916
template: `
2017
<StackLayout>
2118
<Label text="Second component" class="title"></Label>
2219
<Button text="GO TO FIRST" [nsRouterLink]="['/first']" class="link"></Button>
2320
</StackLayout>`
2421
})
2522
export class SecondComponent { }
26-
// << router-content-components
23+
// << router-content-components

tests/app/snippets/navigation/page-outlet.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ApplicationRef } from '@angular/core';
44
import { Component, NgModule } from '@angular/core';
55
import { platformNativeScriptDynamic } from "nativescript-angular/platform";
66
import { NativeScriptRouterModule } from "nativescript-angular/router";
7-
import { Router } from '@angular/router';
7+
import { Router, NavigationStart, NavigationEnd } from '@angular/router';
88
import { routes } from "./app.routes";
99

1010
@Component({
@@ -13,8 +13,26 @@ import { routes } from "./app.routes";
1313
})
1414
export class PageNavigationApp {
1515
// >> (hide)
16+
public startEvent: any;
17+
public endEvent: any;
18+
19+
public done: Promise<void>;
20+
1621
constructor(public router: Router, public appRef: ApplicationRef) {
1722
registerTestApp(PageNavigationApp, this, appRef);
23+
24+
this.done = new Promise<void>((resolve, reject) => {
25+
this.router.events.subscribe((e) => {
26+
console.log("------>>>>>> PageRouter event: " + e.toString());
27+
if (e instanceof NavigationStart) {
28+
this.startEvent = e;
29+
}
30+
if (e instanceof NavigationEnd) {
31+
this.endEvent = e
32+
resolve();
33+
}
34+
});
35+
});
1836
}
1937
// << (hide)
2038
}

tests/app/snippets/navigation/router-extensions.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import {Component} from "@angular/core";
2-
import {NS_ROUTER_DIRECTIVES } from 'nativescript-angular/router';
3-
import {nsProvideRouter} from 'nativescript-angular/router';
4-
import {RouterConfig} from '@angular/router';
5-
6-
1+
import { Component } from "@angular/core";
72
import { RouterExtensions } from 'nativescript-angular/router';
83

94
@Component({
105
// ...
116
// >> (hide)
127
selector: "router-extensions-import",
13-
directives: [NS_ROUTER_DIRECTIVES],
148
templateUrl: 'snippets/navigation/router-extensions.html'
159
// << (hide)
1610
})
@@ -70,9 +64,7 @@ export class MainComponent {
7064
})
7165
export class App { }
7266

73-
const routes: RouterConfig = [
67+
const routes = [
7468
{ path: "", component: MyComponent },
7569
{ path: "main", component: MainComponent },
7670
];
77-
78-
export const providers = nsProvideRouter(routes, {});

tests/app/snippets/navigation/router-outlet.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { ApplicationRef } from '@angular/core';
44
import { Component, NgModule } from '@angular/core';
55
import { platformNativeScriptDynamic } from "nativescript-angular/platform";
66
import { NativeScriptRouterModule } from "nativescript-angular/router";
7-
import { Router } from '@angular/router';
7+
import { Router, NavigationStart, NavigationEnd } from '@angular/router';
88
import { routes } from "./app.routes";
9+
import {FirstComponent, SecondComponent} from "./navigation-common";
910

1011
@Component({
1112
selector: 'navigation-test',
@@ -24,14 +25,32 @@ import { routes } from "./app.routes";
2425
})
2526
export class NavigationApp {
2627
// >> (hide)
28+
public startEvent: any;
29+
public endEvent: any;
30+
public done: Promise<void>;
31+
2732
constructor(public router: Router, public appRef: ApplicationRef) {
2833
registerTestApp(NavigationApp, this, appRef);
34+
35+
this.done = new Promise<void>((resolve, reject) => {
36+
this.router.events.subscribe((e) => {
37+
console.log("------>>>>>> Router event: " + e.toString());
38+
if (e instanceof NavigationStart) {
39+
this.startEvent = e;
40+
}
41+
if (e instanceof NavigationEnd) {
42+
this.endEvent = e
43+
resolve();
44+
}
45+
});
46+
});
2947
}
3048
// << (hide)
3149
}
3250

3351
@NgModule({
3452
bootstrap: [NavigationApp],
53+
entryComponents: [FirstComponent, SecondComponent],
3554
imports: [
3655
NativeScriptRouterModule,
3756
NativeScriptRouterModule.forRoot(routes)

tests/app/tests/detached-loader-tests.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ class TestComponent { }
1818
class LoaderComponentBase {
1919
@ViewChild(DetachedLoader) public loader: DetachedLoader;
2020

21-
public ready: Promise<LoaderComponent>;
21+
public ready: Promise<LoaderComponentBase>;
2222
private resolve;
2323
constructor() {
2424
this.ready = new Promise((reslove, reject) => {
2525
this.resolve = reslove;
2626
})
2727
}
2828
ngAfterViewInit() {
29+
console.log("!!! ngAfterViewInit -> loader: " + this.loader);
2930
this.resolve(this);
3031
}
3132
}
3233

3334
@Component({
3435
selector: 'loader-component-on-push',
35-
directives: [DetachedLoader],
3636
template: `
3737
<StackLayout>
3838
<DetachedContainer #loader></DetachedContainer>
@@ -43,7 +43,6 @@ export class LoaderComponent extends LoaderComponentBase { }
4343

4444
@Component({
4545
selector: 'loader-component-on-push',
46-
directives: [DetachedLoader],
4746
changeDetection: ChangeDetectionStrategy.OnPush,
4847
template: `
4948
<StackLayout>
@@ -57,7 +56,8 @@ describe('DetachedLoader', () => {
5756
let testApp: TestApp = null;
5857

5958
before(() => {
60-
return TestApp.create().then((app) => {
59+
return TestApp.create([], [LoaderComponent, LoaderComponentOnPush, TestComponent]).then((app) => {
60+
console.log("TEST APP: " + app);
6161
testApp = app;
6262
})
6363
});

tests/app/tests/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
inject,
66
} from '@angular/core/testing';
77
import {ReflectiveInjector} from '@angular/core';
8-
import {BaseRequestOptions, ConnectionBackend, Http, HTTP_PROVIDERS, Response, ResponseOptions} from '@angular/http';
8+
import {BaseRequestOptions, ConnectionBackend, Http, Response, ResponseOptions} from '@angular/http';
99
import 'rxjs/add/operator/map';
1010
import {MockBackend} from '@angular/http/testing';
1111
import {NSHttp} from "nativescript-angular/http/ns-http";

tests/app/tests/list-view-tests.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DataItem {
1616
template: `
1717
<StackLayout>
1818
<ListView height="200" [items]="myItems" (setupItemView)="onSetupItemView($event)">
19-
<template #item="item" #i="index" #odd="odd" #even="even">
19+
<template let-item="item" let-i="index" let-odd="odd" let-even="even">
2020
<StackLayout [class.odd]="odd" [class.even]="even">
2121
<Label [text]='"index: " + i'></Label>
2222
<Label [text]='"[" + item.id +"] " + item.name'></Label>
@@ -43,12 +43,11 @@ export class TestListViewComponent {
4343
}
4444
}
4545

46-
// TODO: Skip list-view test until karma test launcher double navigate bug is fixed
47-
describe.skip('ListView-tests', () => {
46+
describe('ListView-tests', () => {
4847
let testApp: TestApp = null;
4948

5049
before(() => {
51-
return TestApp.create().then((app) => {
50+
return TestApp.create([], [TestListViewComponent]).then((app) => {
5251
testApp = app;
5352
})
5453
});

0 commit comments

Comments
 (0)