Skip to content

Commit

Permalink
Added helper to press keys multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Doughty committed Sep 5, 2024
1 parent 3973288 commit 54ddeec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
29 changes: 11 additions & 18 deletions js/test/load-more.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions js/test/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 54ddeec

Please sign in to comment.