-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added OG image, nav image, unit tests
- Loading branch information
Travis Doughty
committed
Sep 5, 2024
1 parent
bfebc6c
commit 3973288
Showing
10 changed files
with
262 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ | |
} | ||
} | ||
#product-count, | ||
#view-count { | ||
#category-count { | ||
text-align: center; | ||
} | ||
#load-more-btn, | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
'use strict'; | ||
import config from './test-config.js'; | ||
|
||
const exampleImages1 = '#example1 img'; | ||
const exampleImages2 = '#example2 img'; | ||
|
||
describe('Load More Tests', () => { | ||
it('Example 1 should have images with non-empty alt tags', async () => { | ||
await page.goto(`${config.BASE_URL}/load-more.php`); | ||
|
||
await page.waitForSelector('#example1'); | ||
|
||
const images = await page.$$eval(exampleImages1, (imgs) => | ||
imgs.map((img) => ({ | ||
src: img.src, | ||
alt: img.alt, | ||
})), | ||
); | ||
|
||
images.forEach((image) => { | ||
expect(image.src).not.toBe(''); | ||
expect(image.alt).not.toBe(''); | ||
}); | ||
}); | ||
|
||
it('Example 1 should initalize with "Showing 3 of 9 Categories" and have aria-live polite', async () => { | ||
await page.goto(`${config.BASE_URL}/load-more.php`); | ||
|
||
await page.waitForSelector('#example1'); | ||
|
||
const domInfo = await page.evaluate(() => { | ||
const categoryCount = document.getElementById('category-count'); | ||
|
||
return { | ||
hasProperCountText: | ||
categoryCount.innerText === 'Showing 3 of 9 Categories', | ||
hasAriaLive: | ||
categoryCount.getAttribute('aria-live') === 'polite', | ||
}; | ||
}); | ||
|
||
expect(domInfo.hasProperCountText).toBe(true); | ||
expect(domInfo.hasAriaLive).toBe(true); | ||
}); | ||
|
||
it('Example 1 keyboard support for "View More Categories" and "Reset Category Grid Demo" buttons', async () => { | ||
const numTabPress = 3; | ||
await page.goto(`${config.BASE_URL}/load-more.php`); | ||
|
||
await page.waitForSelector('#example1'); | ||
|
||
let domInfo; | ||
|
||
// Start on the first category tile | ||
domInfo = await page.evaluate(() => { | ||
const firstTile = document.querySelector('.view-details-link'); | ||
firstTile.focus(); | ||
return { | ||
isFirstTileFocused: document.activeElement === firstTile, | ||
}; | ||
}); | ||
|
||
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'); | ||
} | ||
await page.keyboard.press('Enter'); | ||
|
||
domInfo = await page.evaluate(() => { | ||
const allTiles = Array.from( | ||
document.querySelectorAll('.view-details-link'), | ||
); | ||
return { | ||
isFirstTileInNewSetFocused: | ||
document.activeElement === allTiles[3], | ||
}; | ||
}); | ||
|
||
expect(domInfo.isFirstTileInNewSetFocused).toBe(true); | ||
|
||
// Expect the counter to update | ||
domInfo = await page.evaluate(() => { | ||
const countText = document.querySelector('#category-count'); | ||
return { | ||
isCountTextUpdated: | ||
countText.innerHTML === 'Showing 6 of 9 Categories', | ||
}; | ||
}); | ||
|
||
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'); | ||
} | ||
await page.keyboard.press('Enter'); | ||
|
||
// Tab to the "Reset Category Grid Demo" | ||
for (let i = 0; i < numTabPress; i++) { | ||
await page.keyboard.press('Tab'); | ||
} | ||
await page.keyboard.press('Enter'); | ||
|
||
// Expect the first tile to be selected after resetting the demo | ||
domInfo = await page.evaluate(() => { | ||
const allTiles = Array.from( | ||
document.querySelectorAll('.view-details-link'), | ||
); | ||
return { | ||
isFocusReset: document.activeElement === allTiles[0], | ||
}; | ||
}); | ||
|
||
expect(domInfo.isFocusReset).toBe(true); | ||
}); | ||
|
||
it('Example 2 should have images with non-empty alt tags', async () => { | ||
await page.goto(`${config.BASE_URL}/load-more.php`); | ||
|
||
await page.waitForSelector('#example2'); | ||
|
||
const images = await page.$$eval(exampleImages2, (imgs) => | ||
imgs.map((img) => ({ | ||
src: img.src, | ||
alt: img.alt, | ||
})), | ||
); | ||
|
||
images.forEach((image) => { | ||
expect(image.src).not.toBe(''); | ||
expect(image.alt).not.toBe(''); | ||
}); | ||
}); | ||
|
||
it('Example 2 should have a proper role and aria-labelledby assigned', async () => { | ||
await page.goto(`${config.BASE_URL}/load-more.php`); | ||
|
||
await page.waitForSelector('#example2'); | ||
|
||
const domInfo = await page.evaluate(() => { | ||
const tiles = Array.from( | ||
document.querySelectorAll('.product-tile'), | ||
); | ||
|
||
return { | ||
hasGroupRole: tiles.every( | ||
(tile) => tile.getAttribute('role') === 'group', | ||
), | ||
hasAriaLabelledBy: tiles.every( | ||
(tile) => tile.getAttribute('aria-labelledby') !== '', | ||
), | ||
}; | ||
}); | ||
|
||
expect(domInfo.hasGroupRole).toBe(true); | ||
expect(domInfo.hasAriaLabelledBy).toBe(true); | ||
}); | ||
|
||
it('Example 2 should initalize with "Showing 3 of 9 Products" and have aria-live polite', async () => { | ||
await page.goto(`${config.BASE_URL}/load-more.php`); | ||
|
||
await page.waitForSelector('#example2'); | ||
|
||
const domInfo = await page.evaluate(() => { | ||
const productCount = document.getElementById('product-count'); | ||
|
||
return { | ||
hasProperCountText: | ||
productCount.innerText === 'Showing 3 of 9 Products', | ||
hasAriaLive: | ||
productCount.getAttribute('aria-live') === 'polite', | ||
}; | ||
}); | ||
|
||
expect(domInfo.hasProperCountText).toBe(true); | ||
expect(domInfo.hasAriaLive).toBe(true); | ||
}); | ||
|
||
it('Example 2 keyboard support for "Load More Products" and "Reset Product Grid Demo" buttons', async () => { | ||
const numTabPress = 6; | ||
|
||
await page.goto(`${config.BASE_URL}/load-more.php`); | ||
|
||
await page.waitForSelector('#example2'); | ||
|
||
let domInfo; | ||
|
||
// Start on the first category tile | ||
domInfo = await page.evaluate(() => { | ||
const firstTile = document.querySelector('.product-details-link'); | ||
firstTile.focus(); | ||
return { | ||
isFirstTileFocused: document.activeElement === firstTile, | ||
}; | ||
}); | ||
|
||
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'); | ||
} | ||
await page.keyboard.press('Enter'); | ||
|
||
domInfo = await page.evaluate(() => { | ||
const allTiles = Array.from( | ||
document.querySelectorAll('.product-details-link'), | ||
); | ||
return { | ||
isFirstTileInNewSetFocused: | ||
document.activeElement === allTiles[3], | ||
}; | ||
}); | ||
|
||
expect(domInfo.isFirstTileInNewSetFocused).toBe(true); | ||
|
||
// Expect the counter to update | ||
domInfo = await page.evaluate(() => { | ||
const countText = document.querySelector('#product-count'); | ||
return { | ||
isCountTextUpdated: | ||
countText.innerHTML === 'Showing 6 of 9 Products', | ||
}; | ||
}); | ||
|
||
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'); | ||
} | ||
await page.keyboard.press('Enter'); | ||
|
||
// Tab to the "Reset Category Grid Demo" | ||
for (let i = 0; i < numTabPress; i++) { | ||
await page.keyboard.press('Tab'); | ||
} | ||
await page.keyboard.press('Enter'); | ||
|
||
// Expect the first tile to be selected after resetting the demo | ||
domInfo = await page.evaluate(() => { | ||
const allTiles = Array.from( | ||
document.querySelectorAll('.product-details-link'), | ||
); | ||
return { | ||
isFocusReset: document.activeElement === allTiles[0], | ||
}; | ||
}); | ||
|
||
expect(domInfo.isFocusReset).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ | |
} | ||
|
||
#product-count, | ||
#view-count { | ||
#category-count { | ||
text-align: center; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters