From 54ddeec663dae59bbe578538e4ff5d3a794b6f0a Mon Sep 17 00:00:00 2001 From: Travis Doughty Date: Thu, 5 Sep 2024 11:47:02 -0400 Subject: [PATCH] Added helper to press keys multiple times --- js/test/load-more.test.js | 29 +++++++++++------------------ js/test/test-helpers.js | 6 ++++++ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/js/test/load-more.test.js b/js/test/load-more.test.js index 3dd2160e..4348c4e4 100644 --- a/js/test/load-more.test.js +++ b/js/test/load-more.test.js @@ -1,5 +1,6 @@ 'use strict'; import config from './test-config.js'; +import testHelpers from './test-helpers.js'; const exampleImages1 = '#example1 img'; const exampleImages2 = '#example2 img'; @@ -63,9 +64,11 @@ describe('Load More Tests', () => { expect(domInfo.isFirstTileFocused).toBe(true); // Tab to the "View More Categories" button and press it to load the first new set - for (let i = 0; i < numTabPress; i++) { - await page.keyboard.press('Tab'); - } + + // for (let i = 0; i < numTabPress; i++) { + // await page.keyboard.press('Tab'); + // } + testHelpers.keyPressHelper(page, 'Tab', numTabPress); await page.keyboard.press('Enter'); domInfo = await page.evaluate(() => { @@ -92,15 +95,11 @@ describe('Load More Tests', () => { expect(domInfo.isCountTextUpdated).toBe(true); // Tab to the "View More Categories" button and press it to load the second new set - for (let i = 0; i < numTabPress; i++) { - await page.keyboard.press('Tab'); - } + testHelpers.keyPressHelper(page, 'Tab', numTabPress); await page.keyboard.press('Enter'); // Tab to the "Reset Category Grid Demo" - for (let i = 0; i < numTabPress; i++) { - await page.keyboard.press('Tab'); - } + testHelpers.keyPressHelper(page, 'Tab', numTabPress); await page.keyboard.press('Enter'); // Expect the first tile to be selected after resetting the demo @@ -199,9 +198,7 @@ describe('Load More Tests', () => { expect(domInfo.isFirstTileFocused).toBe(true); // Tab to the "View More Categories" button and press it to load the first new set - for (let i = 0; i < numTabPress; i++) { - await page.keyboard.press('Tab'); - } + testHelpers.keyPressHelper(page, 'Tab', numTabPress); await page.keyboard.press('Enter'); domInfo = await page.evaluate(() => { @@ -228,15 +225,11 @@ describe('Load More Tests', () => { expect(domInfo.isCountTextUpdated).toBe(true); // Tab to the "View More Categories" button and press it to load the second new set - for (let i = 0; i < numTabPress; i++) { - await page.keyboard.press('Tab'); - } + testHelpers.keyPressHelper(page, 'Tab', numTabPress); await page.keyboard.press('Enter'); // Tab to the "Reset Category Grid Demo" - for (let i = 0; i < numTabPress; i++) { - await page.keyboard.press('Tab'); - } + testHelpers.keyPressHelper(page, 'Tab', numTabPress); await page.keyboard.press('Enter'); // Expect the first tile to be selected after resetting the demo diff --git a/js/test/test-helpers.js b/js/test/test-helpers.js index 70536294..bb674f42 100644 --- a/js/test/test-helpers.js +++ b/js/test/test-helpers.js @@ -142,6 +142,12 @@ const testHelpers = new (function () { console.log(request.failure().errorText, request.url()); }); */ }; + + this.keyPressHelper = (page, key, numTimes) => { + for (let i = 0; i < numTimes; i++) { + page.keyboard.press(key); + } + }; })(); export default testHelpers;