6
6
import { BidiModule , Dir , Direction } from '@angular/cdk/bidi' ;
7
7
import { Location } from '@angular/common' ;
8
8
import { Component , DebugElement , ViewChild } from '@angular/core' ;
9
- import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
9
+ import { ComponentFixture , fakeAsync , TestBed , tick , waitForAsync } from '@angular/core/testing' ;
10
10
import { By } from '@angular/platform-browser' ;
11
11
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
12
12
@@ -27,6 +27,7 @@ describe('NzPageHeaderComponent', () => {
27
27
providers : [ provideNzIconsTesting ( ) ]
28
28
} ) ;
29
29
location = TestBed . inject ( Location ) ;
30
+ spyOn ( location , 'getState' ) . and . returnValue ( { navigationId : 2 } ) ;
30
31
} ) ) ;
31
32
32
33
it ( 'should basic work' , ( ) => {
@@ -39,6 +40,14 @@ describe('NzPageHeaderComponent', () => {
39
40
expect ( pageHeader . nativeElement . querySelector ( '.ant-page-header-heading-sub-title' ) ) . toBeTruthy ( ) ;
40
41
} ) ;
41
42
43
+ it ( 'should displayed the back button if nzBack has observer' , ( ) => {
44
+ const fixture = TestBed . createComponent ( NzDemoPageHeaderBasicComponent ) ;
45
+ const pageHeader = fixture . debugElement . query ( By . directive ( NzPageHeaderComponent ) ) ;
46
+ fixture . detectChanges ( ) ;
47
+ const back = pageHeader . nativeElement . querySelector ( '.ant-page-header-back-button' ) ;
48
+ expect ( back ) . toBeTruthy ( ) ;
49
+ } ) ;
50
+
42
51
it ( 'should ghost work' , ( ) => {
43
52
const fixture = TestBed . createComponent ( NzDemoPageHeaderGhostComponent ) ;
44
53
const pageHeader = fixture . debugElement . query ( By . directive ( NzPageHeaderComponent ) ) ;
@@ -67,6 +76,29 @@ describe('NzPageHeaderComponent', () => {
67
76
expect ( location . back ) . toHaveBeenCalled ( ) ;
68
77
} ) ;
69
78
79
+ it ( 'should not show the back button if there is no history of navigation' , fakeAsync ( ( ) => {
80
+ const fixture = TestBed . createComponent ( NzDemoPageHeaderResponsiveComponent ) ;
81
+ const pageHeader = fixture . debugElement . query ( By . directive ( NzPageHeaderComponent ) ) ;
82
+ spyOn ( location , 'getState' ) . and . returnValue ( { navigationId : 1 } ) ;
83
+ fixture . detectChanges ( ) ;
84
+ pageHeader . componentInstance . ngAfterViewInit ( ) ;
85
+ tick ( ) ;
86
+ fixture . detectChanges ( ) ;
87
+ const back = pageHeader . nativeElement . querySelector ( '.ant-page-header-back-button' ) ;
88
+ expect ( back ) . toBeNull ( ) ;
89
+ } ) ) ;
90
+
91
+ it ( 'should show the back button if there is history of navigation' , fakeAsync ( ( ) => {
92
+ const fixture = TestBed . createComponent ( NzDemoPageHeaderResponsiveComponent ) ;
93
+ const pageHeader = fixture . debugElement . query ( By . directive ( NzPageHeaderComponent ) ) ;
94
+ fixture . detectChanges ( ) ;
95
+ pageHeader . componentInstance . ngAfterViewInit ( ) ;
96
+ tick ( ) ;
97
+ fixture . detectChanges ( ) ;
98
+ const back = pageHeader . nativeElement . querySelector ( '.ant-page-header-back-button' ) ;
99
+ expect ( back as HTMLDivElement ) . toBeTruthy ( ) ;
100
+ } ) ) ;
101
+
70
102
it ( 'should content work' , ( ) => {
71
103
const fixture = TestBed . createComponent ( NzDemoPageHeaderContentComponent ) ;
72
104
const pageHeader = fixture . debugElement . query ( By . directive ( NzPageHeaderComponent ) ) ;
0 commit comments