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;
|
|
|
|
beforeEach(() => {
|
|
|
|
documentSpy = jasmine.createSpyObj('document', ['querySelector']);
|
2020-04-13 19:40:21 -04:00
|
|
|
scroller = new BrowserViewportScroller(documentSpy, {scrollTo: 1}, null!);
|
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}']`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|