Skip to content

Commit c1edcba

Browse files
committed
test: fix tests
1 parent c49fb86 commit c1edcba

File tree

8 files changed

+90
-80
lines changed

8 files changed

+90
-80
lines changed

apps/nativescript-demo-ng/.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "../../.eslintrc.json",
3-
"ignorePatterns": ["!**/*", "node_modules/**/*"],
3+
"ignorePatterns": ["!**/*", "node_modules/**/*", "platforms/**/*"],
44
"overrides": [
55
{
66
"files": ["*.ts"],

apps/nativescript-demo-ng/src/app/app.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Component, ViewContainerRef } from '@angular/core';
1+
import { Component, ViewContainerRef, OnInit, OnDestroy } from '@angular/core';
22

33
// registerElement('ns-app', () => GridLayout);
44
@Component({
55
selector: 'ns-app',
66
moduleId: module.id,
77
templateUrl: './app.component.html',
88
})
9-
export class AppComponent {
9+
export class AppComponent implements OnInit, OnDestroy {
1010
constructor(private vcRef: ViewContainerRef) {}
1111
ngOnInit() {
1212
console.log('ngOnInit');

apps/nativescript-demo-ng/src/app/home/home.component.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, NgZone } from '@angular/core';
1+
import { Component, NgZone, OnInit } from '@angular/core';
22
import { ActivatedRoute, Router } from '@angular/router';
33
import { RouterExtensions } from '@nativescript/angular';
44
import { Page, TabView } from '@nativescript/core';
@@ -8,7 +8,7 @@ import { Page, TabView } from '@nativescript/core';
88
selector: 'demo-home',
99
templateUrl: './home.component.html',
1010
})
11-
export class HomeComponent {
11+
export class HomeComponent implements OnInit {
1212
tabItems: { [key: string]: { index: number; title?: string; iconSource?: string; textTransform?: string } } = {};
1313
private _tabs = ['start'];
1414
private _hasInitTab: { start?: boolean } = {};
@@ -20,7 +20,7 @@ export class HomeComponent {
2020
private _activeRoute: ActivatedRoute,
2121
private _page: Page,
2222
private _ngRouter: Router,
23-
private _router: RouterExtensions
23+
private _router: RouterExtensions,
2424
) {
2525
this._initMenu();
2626
}

apps/nativescript-demo-ng/src/app/item/items.component.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { HttpClient } from '@angular/common/http';
33

44
import { Item } from './item';
@@ -11,11 +11,16 @@ import { ModalDialogService, NativeDialogService } from '@nativescript/angular';
1111
moduleId: module.id,
1212
templateUrl: './items.component.html',
1313
})
14-
export class ItemsComponent implements OnInit {
14+
export class ItemsComponent implements OnInit, OnDestroy {
1515
message = 'Hello Angular 18!';
1616
items: Array<Item>;
1717

18-
constructor(private itemService: ItemService, private nativeDialog: NativeDialogService, private modalDialog: ModalDialogService, private http: HttpClient) {}
18+
constructor(
19+
private itemService: ItemService,
20+
private nativeDialog: NativeDialogService,
21+
private modalDialog: ModalDialogService,
22+
private http: HttpClient,
23+
) {}
1924

2025
ngOnInit(): void {
2126
console.log('ItemsComponent ngOnInit');

apps/nativescript-demo-ng/src/app/item2/item-detail2.component.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { ActivatedRoute } from '@angular/router';
33
import { RouterExtensions } from '@nativescript/angular';
44

@@ -10,10 +10,14 @@ import { ItemService } from '../item/item.service';
1010
moduleId: module.id,
1111
templateUrl: './item-detail2.component.html',
1212
})
13-
export class ItemDetailComponent implements OnInit {
13+
export class ItemDetailComponent implements OnInit, OnDestroy {
1414
item: Item;
1515

16-
constructor(private itemService: ItemService, private route: ActivatedRoute, private router: RouterExtensions) {
16+
constructor(
17+
private itemService: ItemService,
18+
private route: ActivatedRoute,
19+
private router: RouterExtensions,
20+
) {
1721
console.log('ItemDetail2Component construct');
1822
}
1923

apps/nativescript-demo-ng/src/app/item3/items.component.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { HttpClient } from '@angular/common/http';
33

44
import { Item } from '../item/item';
@@ -11,13 +11,18 @@ import { ModalDialogService, NativeDialogService } from '@nativescript/angular';
1111
moduleId: module.id,
1212
templateUrl: './items.component.html',
1313
})
14-
export class ItemsComponent implements OnInit {
14+
export class ItemsComponent implements OnInit, OnDestroy {
1515
message = 'Hello Angular 18';
1616
items: Array<Item>;
1717
borderRadius: number;
1818
fontSize: number;
1919

20-
constructor(private itemService: ItemService, private nativeDialog: NativeDialogService, private modalDialog: ModalDialogService, private http: HttpClient) {
20+
constructor(
21+
private itemService: ItemService,
22+
private nativeDialog: NativeDialogService,
23+
private modalDialog: ModalDialogService,
24+
private http: HttpClient,
25+
) {
2126
if (global.isAndroid) {
2227
this.borderRadius = 25;
2328
this.fontSize = 15;
@@ -40,8 +45,8 @@ export class ItemsComponent implements OnInit {
4045
openModal() {
4146
const ref = this.nativeDialog.open(ModalComponent, {
4247
nativeOptions: {
43-
fullscreen: !!global.isAndroid
44-
}
48+
fullscreen: !!global.isAndroid,
49+
},
4550
});
4651
ref.afterOpened().subscribe(() => console.log('after openend'));
4752
ref.beforeClosed().subscribe((result) => console.log('beforeClosed', result));

apps/nativescript-demo-ng/src/main.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import './polyfills';
2-
import 'zone.js/dist/zone-testing.js';
2+
import 'zone.js/testing';
33
import { TestBed } from '@angular/core/testing';
44
import { platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
55
import { NativeScriptTestingModule } from '@nativescript/angular/testing';

apps/nativescript-demo-ng/src/tests/modal-dialog.spec.ts

+58-62
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NgModule, Component, ViewContainerRef, NO_ERRORS_SCHEMA } from '@angula
33
import { Page, Frame, isIOS } from '@nativescript/core';
44
import { ModalDialogParams, ModalDialogService } from '@nativescript/angular';
55

6-
import { ComponentFixture, TestBed, async, waitForAsync } from '@angular/core/testing';
6+
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
77
import { nsTestBedRender, nsTestBedAfterEach, nsTestBedBeforeEach, NATIVESCRIPT_TESTING_PROVIDERS, NativeScriptTestingModule } from '@nativescript/angular/testing';
88
import { NSLocationStrategy, Outlet } from '@nativescript/angular';
99
import { FrameService } from '@nativescript/angular';
@@ -45,7 +45,12 @@ export class FailComponent {
4545
</GridLayout>`,
4646
})
4747
export class SuccessComponent {
48-
constructor(public service: ModalDialogService, public vcRef: ViewContainerRef, public locationStrategy: NSLocationStrategy, public fakeFrameService: FrameService) {}
48+
constructor(
49+
public service: ModalDialogService,
50+
public vcRef: ViewContainerRef,
51+
public locationStrategy: NSLocationStrategy,
52+
public fakeFrameService: FrameService,
53+
) {}
4954
}
5055

5156
@NgModule({
@@ -89,64 +94,55 @@ describe('modal-dialog', () => {
8994
}
9095
});
9196

92-
it(
93-
'showModal does not throws when there is no viewContainer provided',
94-
waitForAsync(async () => {
95-
const fixture = TestBed.createComponent(FailComponent);
96-
const service = <ModalDialogService>fixture.componentRef.instance.service;
97-
await fixture.whenRenderingDone();
98-
// expect(() => service.showModal(ModalComponent, {})).toThrow("No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions.");
99-
expect(() => service.showModal(ModalComponent, {})).not.toThrow();
100-
})
101-
);
102-
103-
it(
104-
'showModal succeeds when there is viewContainer provided',
105-
waitForAsync(async () => {
106-
const fixture = TestBed.createComponent(SuccessComponent);
107-
const service = fixture.componentRef.instance.service;
108-
const locStrategy = fixture.componentRef.instance.locationStrategy;
109-
await fixture.whenRenderingDone();
110-
const outlet = new Outlet('primary', null, 'primary', 0);
111-
let parentView = fixture.componentRef.instance.vcRef.element.nativeElement;
112-
parentView = parentView.page && parentView.page.frame;
113-
outlet.frames.push(parentView);
114-
locStrategy._getOutlets().push(outlet);
115-
116-
locStrategy.pushState(null, 'test', '/test', null);
117-
118-
const comp = fixture.componentRef.instance;
119-
service.showModal(ModalComponent, { viewContainerRef: comp.vcRef }).catch((e) => fail(e));
120-
})
121-
);
122-
123-
it(
124-
'showModal passes modal params and gets result when resolved',
125-
waitForAsync(async () => {
126-
const context = { property: 'my context' };
127-
const fixture = TestBed.createComponent(SuccessComponent);
128-
129-
const service = <ModalDialogService>fixture.componentRef.instance.service;
130-
const locStrategy = <NSLocationStrategy>fixture.componentRef.instance.locationStrategy;
131-
const outlet = new Outlet('primary', null, 'primary', 0);
132-
133-
let parentView = fixture.componentRef.instance.vcRef.element.nativeElement;
134-
parentView = parentView.page && parentView.page.frame;
135-
outlet.frames.push(parentView);
136-
locStrategy._getOutlets().push(outlet);
137-
138-
locStrategy.pushState(null, 'test', '/test', null);
139-
140-
const comp = <SuccessComponent>fixture.componentRef.instance;
141-
service
142-
.showModal(ModalComponent, {
143-
viewContainerRef: comp.vcRef,
144-
context: context,
145-
})
146-
.then((res) => {
147-
expect(res).toEqual(context);
148-
})
149-
.catch((e) => fail(e));
150-
})
151-
);
97+
it('showModal does not throws when there is no viewContainer provided', waitForAsync(async () => {
98+
const fixture = TestBed.createComponent(FailComponent);
99+
const service = <ModalDialogService>fixture.componentRef.instance.service;
100+
await fixture.whenRenderingDone();
101+
// expect(() => service.showModal(ModalComponent, {})).toThrow("No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions.");
102+
expect(() => service.showModal(ModalComponent, {})).not.toThrow();
103+
}));
104+
105+
it('showModal succeeds when there is viewContainer provided', waitForAsync(async () => {
106+
const fixture = TestBed.createComponent(SuccessComponent);
107+
const service = fixture.componentRef.instance.service;
108+
const locStrategy = fixture.componentRef.instance.locationStrategy;
109+
await fixture.whenRenderingDone();
110+
const outlet = new Outlet('primary', null, 'primary', 0);
111+
let parentView = fixture.componentRef.instance.vcRef.element.nativeElement;
112+
parentView = parentView.page && parentView.page.frame;
113+
outlet.frames.push(parentView);
114+
locStrategy._getOutlets().push(outlet);
115+
116+
locStrategy.pushState(null, 'test', '/test', null);
117+
118+
const comp = fixture.componentRef.instance;
119+
service.showModal(ModalComponent, { viewContainerRef: comp.vcRef }).catch((e) => fail(e));
120+
}));
121+
122+
it('showModal passes modal params and gets result when resolved', waitForAsync(async () => {
123+
const context = { property: 'my context' };
124+
const fixture = TestBed.createComponent(SuccessComponent);
125+
126+
const service = <ModalDialogService>fixture.componentRef.instance.service;
127+
const locStrategy = <NSLocationStrategy>fixture.componentRef.instance.locationStrategy;
128+
const outlet = new Outlet('primary', null, 'primary', 0);
129+
130+
let parentView = fixture.componentRef.instance.vcRef.element.nativeElement;
131+
parentView = parentView.page && parentView.page.frame;
132+
outlet.frames.push(parentView);
133+
locStrategy._getOutlets().push(outlet);
134+
135+
locStrategy.pushState(null, 'test', '/test', null);
136+
137+
const comp = <SuccessComponent>fixture.componentRef.instance;
138+
service
139+
.showModal(ModalComponent, {
140+
viewContainerRef: comp.vcRef,
141+
context: context,
142+
})
143+
.then((res) => {
144+
expect(res).toEqual(context);
145+
})
146+
.catch((e) => fail(e));
147+
}));
152148
});

0 commit comments

Comments
 (0)