@@ -9,24 +9,22 @@ import { loadDocument, nextRenderIdle, scrollSettled } from './helpers.js';
99
1010describe ( 'keyboard' , ( ) => {
1111 let viewer : PdfViewer ;
12-
13- function getContent ( ) {
14- return viewer . shadowRoot ! . querySelector < HTMLElement > ( '[part="content"]' ) ! ;
15- }
12+ let content : HTMLElement ;
1613
1714 beforeEach ( async ( ) => {
1815 viewer = fixtureSync ( '<vaadin-pdf-viewer style="width: 400px; height: 400px"></vaadin-pdf-viewer>' ) ;
1916 await nextRender ( ) ;
17+ content = viewer . shadowRoot ! . querySelector < HTMLElement > ( '[part="content"]' ) ! ;
2018 } ) ;
2119
2220 it ( 'should not make the page area focusable without a document' , ( ) => {
23- expect ( getContent ( ) . getAttribute ( 'tabindex' ) ) . to . equal ( '-1' ) ;
21+ expect ( content . getAttribute ( 'tabindex' ) ) . to . equal ( '-1' ) ;
2422 } ) ;
2523
2624 it ( 'should make the page area focusable once a document has loaded' , async ( ) => {
2725 await loadDocument ( viewer , 'multi-page.pdf' ) ;
2826 await nextUpdate ( viewer ) ;
29- expect ( getContent ( ) . getAttribute ( 'tabindex' ) ) . to . equal ( '0' ) ;
27+ expect ( content . getAttribute ( 'tabindex' ) ) . to . equal ( '0' ) ;
3028 } ) ;
3129
3230 describe ( 'with a document' , ( ) => {
@@ -37,41 +35,39 @@ describe('keyboard', () => {
3735 } ) ;
3836
3937 it ( 'should scroll the pages with the arrow keys' , async ( ) => {
40- getContent ( ) . focus ( ) ;
41- const scrolled = oneEvent ( getContent ( ) , 'scroll' ) ;
38+ content . focus ( ) ;
39+ const scrolled = oneEvent ( content , 'scroll' ) ;
4240 // WebKit stops the scroll animation on keyup, so hold the key
4341 await sendKeys ( { down : 'ArrowDown' } ) ;
4442 await aTimeout ( 50 ) ;
4543 await sendKeys ( { up : 'ArrowDown' } ) ;
4644 await scrolled ;
47- expect ( getContent ( ) . scrollTop ) . to . be . greaterThan ( 0 ) ;
45+ expect ( content . scrollTop ) . to . be . greaterThan ( 0 ) ;
4846 } ) ;
4947
5048 it ( 'should scroll by a page with PageDown' , async ( ) => {
51- getContent ( ) . focus ( ) ;
49+ content . focus ( ) ;
5250 await sendKeys ( { press : 'PageDown' } ) ;
53- await scrollSettled ( getContent ( ) ) ;
54- expect ( getContent ( ) . scrollTop ) . to . be . greaterThan ( getContent ( ) . clientHeight * 0.5 ) ;
51+ await scrollSettled ( content ) ;
52+ expect ( content . scrollTop ) . to . be . greaterThan ( content . clientHeight * 0.5 ) ;
5553 } ) ;
5654
5755 it ( 'should scroll to the end with End' , async ( ) => {
58- getContent ( ) . focus ( ) ;
56+ content . focus ( ) ;
5957 await sendKeys ( { press : 'End' } ) ;
60- await scrollSettled ( getContent ( ) ) ;
61- const content = getContent ( ) ;
58+ await scrollSettled ( content ) ;
6259 expect ( content . scrollTop ) . to . be . closeTo ( content . scrollHeight - content . clientHeight , 2 ) ;
6360 } ) ;
6461
6562 it ( 'should go to the last page with Ctrl+End' , async ( ) => {
66- getContent ( ) . focus ( ) ;
63+ content . focus ( ) ;
6764 const idle = nextRenderIdle ( viewer ) ;
6865 await sendKeys ( { press : 'Control+End' } ) ;
6966 await idle ;
7067 expect ( viewer . page ) . to . equal ( 6 ) ;
7168 } ) ;
7269
7370 it ( 'should scroll to the top of the current first page with Ctrl+Home' , async ( ) => {
74- const content = getContent ( ) ;
7571 const scrolled = oneEvent ( content , 'scroll' ) ;
7672 content . scrollTop = 50 ;
7773 await scrolled ;
@@ -91,7 +87,6 @@ describe('keyboard', () => {
9187 it ( 'should scroll to the top of the current last page with Ctrl+End' , async ( ) => {
9288 viewer . page = 6 ;
9389 await nextRenderIdle ( viewer ) ;
94- const content = getContent ( ) ;
9590 const top = content . scrollTop ;
9691 const scrolled = oneEvent ( content , 'scroll' ) ;
9792 content . scrollTop = top - 50 ;
@@ -107,7 +102,7 @@ describe('keyboard', () => {
107102 it ( 'should go to the first page with Ctrl+Home' , async ( ) => {
108103 viewer . page = 4 ;
109104 await nextRenderIdle ( viewer ) ;
110- getContent ( ) . focus ( ) ;
105+ content . focus ( ) ;
111106 await sendKeys ( { press : 'Control+Home' } ) ;
112107 await nextFrame ( ) ;
113108 expect ( viewer . page ) . to . equal ( 1 ) ;
0 commit comments