1
1
// make sure you import mocha-config before @angular/core
2
2
import { Component , ElementRef , NgModule , NO_ERRORS_SCHEMA } from '@angular/core' ;
3
3
import { TestBed } from '@angular/core/testing' ;
4
- import { AndroidFilterComponent , DEVICE , IOSFilterComponent , NativeScriptModule } from '@nativescript/angular' ;
4
+ import { AndroidFilterComponent , DEVICE , IOSFilterComponent , AppleFilterComponent , NativeScriptModule } from '@nativescript/angular' ;
5
5
import { platformNames } from '@nativescript/core/platform' ;
6
6
import { createDevice , dumpView } from './test-utils.spec' ;
7
7
@Component ( {
@@ -15,6 +15,17 @@ export class IosSpecificComponent {
15
15
constructor ( public elementRef : ElementRef ) { }
16
16
}
17
17
18
+ @Component ( {
19
+ template : ` <StackLayout>
20
+ <apple><Label text="Apple"></Label></apple>
21
+ </StackLayout>` ,
22
+ imports : [ AppleFilterComponent ] ,
23
+ schemas : [ NO_ERRORS_SCHEMA ] ,
24
+ } )
25
+ export class AppleSpecificComponent {
26
+ constructor ( public elementRef : ElementRef ) { }
27
+ }
28
+
18
29
@Component ( {
19
30
template : ` <StackLayout>
20
31
<android><Label text="ANDROID"></Label></android>
@@ -71,6 +82,31 @@ describe('Platform filter directives', () => {
71
82
} ) ;
72
83
} ) ;
73
84
85
+ describe ( 'on Apple device' , ( ) => {
86
+ beforeEach ( ( ) => {
87
+ return TestBed . configureTestingModule ( {
88
+ imports : DECLARATIONS ,
89
+ providers : [ { provide : DEVICE , useValue : createDevice ( platformNames . ios ) } ] ,
90
+ schemas : [ NO_ERRORS_SCHEMA ] ,
91
+ } ) . compileComponents ( ) ;
92
+ } ) ;
93
+ it ( 'does render apple specific content' , ( ) => {
94
+ const fixture = TestBed . createComponent ( AppleSpecificComponent ) ;
95
+ fixture . detectChanges ( ) ;
96
+ const componentRef = fixture . componentRef ;
97
+ const componentRoot = componentRef . instance . elementRef . nativeElement ;
98
+ expect ( dumpView ( componentRoot , true ) . indexOf ( '(label[text=Apple])' ) >= 0 ) . toBe ( true ) ;
99
+ } ) ;
100
+ it ( 'does not render android specific content' , ( ) => {
101
+ const fixture = TestBed . createComponent ( AndroidSpecificComponent ) ;
102
+ fixture . detectChanges ( ) ;
103
+ const componentRef = fixture . componentRef ;
104
+ const componentRoot = componentRef . instance . elementRef . nativeElement ;
105
+ console . log ( dumpView ( componentRoot , true ) ) ;
106
+ expect ( dumpView ( componentRoot , true ) . indexOf ( 'label' ) < 0 ) . toBe ( true ) ;
107
+ } ) ;
108
+ } ) ;
109
+
74
110
describe ( 'on Android device' , ( ) => {
75
111
beforeEach ( ( ) => {
76
112
return TestBed . configureTestingModule ( {
0 commit comments