From 95d0626a1eb339e4a91515e11c96b55ccf0f222e Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Tue, 9 Oct 2018 17:52:32 +0300 Subject: [PATCH] ci(docs-infra): reduce flakyness (#26459) PR Close #26459 --- aio/src/app/app.component.spec.ts | 13 +++++++------ aio/src/app/app.component.ts | 15 ++++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/aio/src/app/app.component.spec.ts b/aio/src/app/app.component.spec.ts index ca60257b08..79549c767f 100644 --- a/aio/src/app/app.component.spec.ts +++ b/aio/src/app/app.component.spec.ts @@ -164,10 +164,10 @@ describe('AppComponent', () => { describe('onScroll', () => { it('should update `tocMaxHeight` accordingly', () => { - expect(component.tocMaxHeight).toBeUndefined(); - + component.tocMaxHeight = ''; component.onScroll(); - expect(component.tocMaxHeight).toBeGreaterThan(0); + + expect(component.tocMaxHeight).toMatch(/^\d+\.\d{2}$/); }); }); @@ -654,12 +654,13 @@ describe('AppComponent', () => { it('should update the TOC container\'s `maxHeight` based on `tocMaxHeight`', () => { setHasFloatingToc(true); - expect(tocContainer!.style['max-height']).toBe(''); - component.tocMaxHeight = '100'; fixture.detectChanges(); - expect(tocContainer!.style['max-height']).toBe('100px'); + + component.tocMaxHeight = '200'; + fixture.detectChanges(); + expect(tocContainer!.style['max-height']).toBe('200px'); }); it('should restrain scrolling inside the ToC container', () => { diff --git a/aio/src/app/app.component.ts b/aio/src/app/app.component.ts index 7353f7480c..820796fb69 100644 --- a/aio/src/app/app.component.ts +++ b/aio/src/app/app.component.ts @@ -349,12 +349,17 @@ export class AppComponent implements OnInit { @HostListener('window:scroll') onScroll() { if (!this.tocMaxHeightOffset) { - // Must wait until now for mat-toolbar to be measurable. + // Must wait until `mat-toolbar` is measurable. const el = this.hostElement.nativeElement as Element; - this.tocMaxHeightOffset = - el.querySelector('footer')!.clientHeight + - el.querySelector('.app-toolbar')!.clientHeight + - 24; // fudge margin + const headerEl = el.querySelector('.app-toolbar'); + const footerEl = el.querySelector('footer'); + + if (headerEl && footerEl) { + this.tocMaxHeightOffset = + headerEl.clientHeight + + footerEl.clientHeight + + 24; // fudge margin + } } this.tocMaxHeight = (document.body.scrollHeight - window.pageYOffset - this.tocMaxHeightOffset).toFixed(2);