1
1
import { ComponentRef } from '@angular/core' ;
2
2
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
3
- import { Title } from '@angular/platform-browser' ;
3
+ import { Title , Meta } from '@angular/platform-browser' ;
4
4
5
5
import { Observable } from 'rxjs/Observable' ;
6
6
import { of } from 'rxjs/observable/of' ;
7
7
8
+ import { FILE_NOT_FOUND_ID , FETCHING_ERROR_ID } from 'app/documents/document.service' ;
8
9
import { EmbedComponentsService } from 'app/embed-components/embed-components.service' ;
9
10
import { Logger } from 'app/shared/logger.service' ;
10
11
import { TocService } from 'app/shared/toc.service' ;
@@ -413,6 +414,24 @@ describe('DocViewerComponent', () => {
413
414
await doRender ( 'Qux content' ) ;
414
415
expect ( addTitleAndTocSpy ) . toHaveBeenCalledTimes ( 4 ) ;
415
416
} ) ;
417
+
418
+ it ( 'should remove "noindex" meta tags if the document is valid' , async ( ) => {
419
+ await doRender ( 'foo' , 'bar' ) ;
420
+ expect ( TestBed . get ( Meta ) . removeTag ) . toHaveBeenCalledWith ( 'name="googlebot"' ) ;
421
+ expect ( TestBed . get ( Meta ) . removeTag ) . toHaveBeenCalledWith ( 'name="robots"' ) ;
422
+ } ) ;
423
+
424
+ it ( 'should add "noindex" meta tags if the document is 404' , async ( ) => {
425
+ await doRender ( 'missing' , FILE_NOT_FOUND_ID ) ;
426
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'googlebot' , content : 'noindex' } ) ;
427
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'robots' , content : 'noindex' } ) ;
428
+ } ) ;
429
+
430
+ it ( 'should add "noindex" meta tags if the document fetching fails' , async ( ) => {
431
+ await doRender ( 'error' , FETCHING_ERROR_ID ) ;
432
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'googlebot' , content : 'noindex' } ) ;
433
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'robots' , content : 'noindex' } ) ;
434
+ } ) ;
416
435
} ) ;
417
436
418
437
describe ( '(embedding components)' , ( ) => {
@@ -538,6 +557,8 @@ describe('DocViewerComponent', () => {
538
557
expect ( logger . output . error ) . toEqual ( [
539
558
[ `[DocViewer] Error preparing document 'foo': ${ error . stack } ` ] ,
540
559
] ) ;
560
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'googlebot' , content : 'noindex' } ) ;
561
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'robots' , content : 'noindex' } ) ;
541
562
} ) ;
542
563
543
564
it ( 'when `EmbedComponentsService.embedInto()` fails' , async ( ) => {
@@ -557,6 +578,8 @@ describe('DocViewerComponent', () => {
557
578
expect ( logger . output . error ) . toEqual ( [
558
579
[ `[DocViewer] Error preparing document 'bar': ${ error . stack } ` ] ,
559
580
] ) ;
581
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'googlebot' , content : 'noindex' } ) ;
582
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'robots' , content : 'noindex' } ) ;
560
583
} ) ;
561
584
562
585
it ( 'when `destroyEmbeddedComponents()` fails' , async ( ) => {
@@ -576,6 +599,8 @@ describe('DocViewerComponent', () => {
576
599
expect ( logger . output . error ) . toEqual ( [
577
600
[ `[DocViewer] Error preparing document 'baz': ${ error . stack } ` ] ,
578
601
] ) ;
602
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'googlebot' , content : 'noindex' } ) ;
603
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'robots' , content : 'noindex' } ) ;
579
604
} ) ;
580
605
581
606
it ( 'when `swapViews()` fails' , async ( ) => {
@@ -595,6 +620,8 @@ describe('DocViewerComponent', () => {
595
620
expect ( logger . output . error ) . toEqual ( [
596
621
[ `[DocViewer] Error preparing document 'qux': ${ error . stack } ` ] ,
597
622
] ) ;
623
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'googlebot' , content : 'noindex' } ) ;
624
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'robots' , content : 'noindex' } ) ;
598
625
} ) ;
599
626
600
627
it ( 'when something fails with non-Error' , async ( ) => {
@@ -611,6 +638,8 @@ describe('DocViewerComponent', () => {
611
638
expect ( logger . output . error ) . toEqual ( [
612
639
[ `[DocViewer] Error preparing document 'qux': ${ error } ` ] ,
613
640
] ) ;
641
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'googlebot' , content : 'noindex' } ) ;
642
+ expect ( TestBed . get ( Meta ) . addTag ) . toHaveBeenCalledWith ( { name : 'robots' , content : 'noindex' } ) ;
614
643
} ) ;
615
644
} ) ;
616
645
0 commit comments