66import { BidiModule , Dir , Direction } from '@angular/cdk/bidi' ;
77import { Location } from '@angular/common' ;
88import { 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' ;
1010import { By } from '@angular/platform-browser' ;
1111import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
1212
@@ -27,6 +27,7 @@ describe('NzPageHeaderComponent', () => {
2727 providers : [ provideNzIconsTesting ( ) ]
2828 } ) ;
2929 location = TestBed . inject ( Location ) ;
30+ spyOn ( location , 'getState' ) . and . returnValue ( { navigationId : 2 } ) ;
3031 } ) ) ;
3132
3233 it ( 'should basic work' , ( ) => {
@@ -39,6 +40,14 @@ describe('NzPageHeaderComponent', () => {
3940 expect ( pageHeader . nativeElement . querySelector ( '.ant-page-header-heading-sub-title' ) ) . toBeTruthy ( ) ;
4041 } ) ;
4142
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+
4251 it ( 'should ghost work' , ( ) => {
4352 const fixture = TestBed . createComponent ( NzDemoPageHeaderGhostComponent ) ;
4453 const pageHeader = fixture . debugElement . query ( By . directive ( NzPageHeaderComponent ) ) ;
@@ -67,6 +76,29 @@ describe('NzPageHeaderComponent', () => {
6776 expect ( location . back ) . toHaveBeenCalled ( ) ;
6877 } ) ;
6978
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+
70102 it ( 'should content work' , ( ) => {
71103 const fixture = TestBed . createComponent ( NzDemoPageHeaderContentComponent ) ;
72104 const pageHeader = fixture . debugElement . query ( By . directive ( NzPageHeaderComponent ) ) ;
0 commit comments