2019-03-28 18:00:51 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2019-03-28 18:00:51 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-04-13 19:40:21 -04:00
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2020-04-13 19:40:21 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2019-03-28 18:00:51 -04:00
|
|
|
|
|
|
|
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
|
|
import {BrowserViewportScroller, ViewportScroller} from '../src/viewport_scroller';
|
|
|
|
|
|
|
|
{
|
|
|
|
describe('BrowserViewportScroller', () => {
|
|
|
|
let scroller: ViewportScroller;
|
|
|
|
let documentSpy: any;
|
2019-05-23 08:44:46 -04:00
|
|
|
let windowSpy: any;
|
|
|
|
|
2019-03-28 18:00:51 -04:00
|
|
|
beforeEach(() => {
|
2019-05-23 08:44:46 -04:00
|
|
|
windowSpy = jasmine.createSpyObj('window', ['history']);
|
|
|
|
windowSpy.scrollTo = 1;
|
|
|
|
windowSpy.history.scrollRestoration = 'auto';
|
|
|
|
|
2019-03-28 18:00:51 -04:00
|
|
|
documentSpy = jasmine.createSpyObj('document', ['querySelector']);
|
2019-05-23 08:44:46 -04:00
|
|
|
scroller = new BrowserViewportScroller(documentSpy, windowSpy, null!);
|
2019-03-28 18:00:51 -04:00
|
|
|
});
|
2019-05-23 08:44:46 -04:00
|
|
|
|
|
|
|
it('should not crash when scrollRestoration is not writable', () => {
|
|
|
|
Object.defineProperty(windowSpy.history, 'scrollRestoration', {
|
|
|
|
value: 'auto',
|
|
|
|
configurable: true,
|
|
|
|
});
|
|
|
|
expect(() => scroller.setHistoryScrollRestoration('manual')).not.toThrow();
|
|
|
|
});
|
|
|
|
|
2019-03-28 18:00:51 -04:00
|
|
|
it('escapes invalid characters selectors', () => {
|
|
|
|
const invalidSelectorChars = `"' :.[],=`;
|
|
|
|
// Double escaped to make sure we match the actual value passed to `querySelector`
|
|
|
|
const escapedInvalids = `\\"\\' \\:\\.\\[\\]\\,\\=`;
|
|
|
|
scroller.scrollToAnchor(`specials=${invalidSelectorChars}`);
|
|
|
|
expect(documentSpy.querySelector).toHaveBeenCalledWith(`#specials\\=${escapedInvalids}`);
|
|
|
|
expect(documentSpy.querySelector)
|
|
|
|
.toHaveBeenCalledWith(`[name='specials\\=${escapedInvalids}']`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|