ci(docs-infra): reduce flakyness (#26459)

PR Close #26459
This commit is contained in:
George Kalpakas 2018-10-09 17:52:32 +03:00 committed by Miško Hevery
parent 5183bbffbe
commit 95d0626a1e
2 changed files with 17 additions and 11 deletions

View File

@ -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', () => {

View File

@ -349,13 +349,18 @@ 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;
const headerEl = el.querySelector('.app-toolbar');
const footerEl = el.querySelector('footer');
if (headerEl && footerEl) {
this.tocMaxHeightOffset =
el.querySelector('footer')!.clientHeight +
el.querySelector('.app-toolbar')!.clientHeight +
headerEl.clientHeight +
footerEl.clientHeight +
24; // fudge margin
}
}
this.tocMaxHeight = (document.body.scrollHeight - window.pageYOffset - this.tocMaxHeightOffset).toFixed(2);
}