@@ -21,6 +21,7 @@ const {
2121 waitForTableLength,
2222 goToPage,
2323 getInnerText,
24+ fillInput,
2425} = require ( '../defaults.js' ) ;
2526const { resetDatabaseContent } = require ( '../../utilities/resetDatabaseContent.js' ) ;
2627
@@ -33,6 +34,9 @@ module.exports = () => {
3334 let table ;
3435 let firstRowId ;
3536
37+ const amountSelectorSelector = '#amountSelector' ;
38+ const amountSelectorButtonSelector = `${ amountSelectorSelector } button` ;
39+
3640 before ( async ( ) => {
3741 [ page , browser ] = await defaultBefore ( page , browser ) ;
3842 await page . setViewport ( {
@@ -108,8 +112,6 @@ module.exports = () => {
108112 await page . waitForSelector ( 'table tbody tr:nth-child(2)' ) ;
109113 expect ( await page . $ ( `table tbody tr:nth-child(${ INFINITE_SCROLL_CHUNK } )` ) ) . to . be . null ;
110114
111- const amountSelectorButtonSelector = '#amountSelector button' ;
112-
113115 // Expect the dropdown options to be visible when it is selected
114116 await pressElement ( page , amountSelectorButtonSelector ) ;
115117
@@ -133,23 +135,19 @@ module.exports = () => {
133135
134136 it ( 'can set how many flps are available per page' , async ( ) => {
135137 // Expect the amount selector to currently be set to Infinite (after the previous test)
136- const amountSelectorId = '#amountSelector' ;
137- await expectInnerText ( page , `${ amountSelectorId } button` , 'Rows per page: Infinite ' ) ;
138+ await expectInnerText ( page , `${ amountSelectorSelector } button` , 'Rows per page: Infinite ' ) ;
138139
139- await pressElement ( page , `${ amountSelectorId } button` ) ;
140- await page . waitForSelector ( `${ amountSelectorId } .dropup-menu` ) ;
140+ await pressElement ( page , `${ amountSelectorSelector } button` ) ;
141+ await page . waitForSelector ( `${ amountSelectorSelector } .dropup-menu` ) ;
141142
142143 // Expect the amount of visible flps to reduce when the first option (5) is selected
143- await pressElement ( page , `${ amountSelectorId } .dropup-menu .menu-item` ) ;
144+ await pressElement ( page , `${ amountSelectorSelector } .dropup-menu .menu-item` ) ;
144145 await waitForTableLength ( page , 5 ) ;
145146 } ) ;
146147
147148 it ( 'dynamically switches between visible pages in the page selector' , async ( ) => {
148- // Override the amount of flps visible per page manually
149- await page . evaluate ( ( ) => {
150- // eslint-disable-next-line no-undef
151- model . flps . pagination . itemsPerPage = 1 ;
152- } ) ;
149+ await pressElement ( page , amountSelectorButtonSelector ) ;
150+ await fillInput ( page , `${ amountSelectorSelector } input` , '1' , [ 'input' , 'change' ] ) ;
153151 await waitForTableLength ( page , 1 ) ;
154152
155153 // Expect the page five button to now be visible, but no more than that
@@ -164,22 +162,13 @@ module.exports = () => {
164162 } ) ;
165163
166164 it ( 'notifies if table loading returned an error' , async ( ) => {
167- /*
168- * As an example, override the amount of flps visible per page manually
169- * We know the limit is 100 as specified by the Dto
170- */
171- await page . evaluate ( ( ) => {
172- // eslint-disable-next-line no-undef
173- model . flps . pagination . itemsPerPage = 200 ;
174- } ) ;
165+ await pressElement ( page , amountSelectorButtonSelector ) ;
166+ await fillInput ( page , `${ amountSelectorSelector } input` , '200' , [ 'input' , 'change' ] ) ;
175167
176168 // We expect there to be a fitting error message
177169 await expectInnerText ( page , '.alert-danger' , 'Invalid Attribute: "query.page.limit" must be less than or equal to 100' ) ;
178170
179- // Revert changes for next test
180- await page . evaluate ( ( ) => {
181- // eslint-disable-next-line no-undef
182- model . flps . pagination . itemsPerPage = 10 ;
183- } ) ;
171+ await pressElement ( page , amountSelectorButtonSelector ) ;
172+ await fillInput ( page , `${ amountSelectorSelector } input` , '10' , [ 'input' , 'change' ] ) ;
184173 } ) ;
185174} ;
0 commit comments