1
1
import { Component } from '@angular/core' ;
2
2
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
3
- import { Subject } from 'rxjs' ;
3
+ import { RxStrategyProvider } from '@rx-angular/cdk/render-strategies' ;
4
+ import { delay , Subject } from 'rxjs' ;
4
5
import { ChunkModule } from '../chunk.module' ;
5
6
6
7
@Component ( {
@@ -30,6 +31,7 @@ describe('ChunkDirective', () => {
30
31
let fixture : ComponentFixture < ChunkTestComponent > ;
31
32
let componentInstance : ChunkTestComponent ;
32
33
let nativeElement : HTMLElement ;
34
+ let strategyProvider : RxStrategyProvider ;
33
35
34
36
beforeEach ( ( ) => {
35
37
TestBed . configureTestingModule ( {
@@ -39,20 +41,27 @@ describe('ChunkDirective', () => {
39
41
fixture = TestBed . createComponent ( ChunkTestComponent ) ;
40
42
componentInstance = fixture . componentInstance ;
41
43
nativeElement = fixture . nativeElement ;
44
+ strategyProvider = TestBed . inject ( RxStrategyProvider ) ;
42
45
} ) ;
43
46
44
47
describe . each ( [
45
- [ undefined ] /* <- Invalid strategy should fallback. */ ,
46
- [ '' ] /* <- Same here. */ ,
47
- [ 'invalid' ] /* <- Same here. */ ,
48
- [ 'immediate' ] ,
49
- [ 'userBlocking' ] ,
50
- [ 'normal' ] ,
51
- [ 'low' ] ,
52
- [ 'idle' ] ,
53
- ] ) ( 'Stratgy: %s' , ( strategy : string ) => {
48
+ [ undefined , true ] /* <- Invalid strategy should fallback. */ ,
49
+ [ '' , true ] /* <- Same here. */ ,
50
+ [ 'invalid' , true ] /* <- Same here. */ ,
51
+ [ 'immediate' , true ] ,
52
+ [ 'userBlocking' , true ] ,
53
+ [ 'normal' , true ] ,
54
+ [ 'low' , true ] ,
55
+ [ 'idle' , true ] ,
56
+ [ 'local' , true ] ,
57
+ [ 'global' , false ] ,
58
+ [ 'native' , false ] ,
59
+ ] ) ( 'Strategy: %s' , ( strategy : string , scheduled : boolean ) => {
54
60
it ( 'should render with given strategy' , ( done ) => {
55
61
componentInstance . strategy = strategy ;
62
+ const expectedInitialTemplate = scheduled
63
+ ? 'not-chunked'
64
+ : 'chunked not-chunked' ;
56
65
componentInstance . renderCallback . subscribe ( ( ) => {
57
66
try {
58
67
expect ( nativeElement . textContent . trim ( ) ) . toBe ( 'chunked not-chunked' ) ;
@@ -62,11 +71,14 @@ describe('ChunkDirective', () => {
62
71
}
63
72
} ) ;
64
73
fixture . detectChanges ( ) ;
65
- expect ( nativeElement . textContent ) . toBe ( 'not-chunked' ) ;
74
+ expect ( nativeElement . textContent . trim ( ) ) . toBe ( expectedInitialTemplate ) ;
66
75
} ) ;
67
76
it ( 'should render the suspense template sync' , ( done ) => {
68
77
componentInstance . strategy = strategy ;
69
78
componentInstance . withSuspense = true ;
79
+ const expectedInitialTemplate = scheduled
80
+ ? 'suspendednot-chunked'
81
+ : 'chunked not-chunked' ;
70
82
componentInstance . renderCallback . subscribe ( ( ) => {
71
83
try {
72
84
expect ( nativeElement . textContent . trim ( ) ) . toBe ( 'chunked not-chunked' ) ;
@@ -76,7 +88,24 @@ describe('ChunkDirective', () => {
76
88
}
77
89
} ) ;
78
90
fixture . detectChanges ( ) ;
79
- expect ( nativeElement . textContent ) . toBe ( 'suspendednot-chunked' ) ;
91
+ expect ( nativeElement . textContent . trim ( ) ) . toBe ( expectedInitialTemplate ) ;
80
92
} ) ;
81
93
} ) ;
94
+
95
+ it ( 'should not render with noop strategy' , ( done ) => {
96
+ componentInstance . strategy = 'noop' ;
97
+ fixture . detectChanges ( ) ;
98
+ expect ( nativeElement . textContent ) . toBe ( 'not-chunked' ) ;
99
+ strategyProvider
100
+ . schedule ( ( ) => { } )
101
+ . pipe ( delay ( 10 ) ) // let's just wait a tiny bit to be sure nothing happens :)
102
+ . subscribe ( ( ) => {
103
+ try {
104
+ expect ( nativeElement . textContent . trim ( ) ) . toBe ( 'not-chunked' ) ;
105
+ done ( ) ;
106
+ } catch ( e ) {
107
+ done ( e . message ) ;
108
+ }
109
+ } ) ;
110
+ } ) ;
82
111
} ) ;
0 commit comments