-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1f3133
commit 94e629a
Showing
1 changed file
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-env jest */ | ||
const configPaths = require('../config/paths.json') | ||
const PORT = configPaths.testPort | ||
|
||
let browser | ||
let page | ||
let baseUrl = 'http://localhost:' + PORT | ||
|
||
beforeAll(async (done) => { | ||
browser = global.browser | ||
page = await browser.newPage() | ||
await page.evaluateOnNewDocument(() => { | ||
window.__TESTS_RUNNING = true | ||
}) | ||
done() | ||
}) | ||
|
||
afterAll(async (done) => { | ||
await page.close() | ||
done() | ||
}) | ||
|
||
describe('Back to top', () => { | ||
it('is always visible when JavaScript is disabled', async () => { | ||
await page.setJavaScriptEnabled(false) | ||
await page.goto(`${baseUrl}/styles/colour/`, { waitUntil: 'load' }) | ||
const isBackToTopVisible = await page.waitForSelector('[data-module="app-back-to-top"]', { visible: true }) | ||
expect(isBackToTopVisible).toBeTruthy() | ||
}) | ||
it('is hidden when at the top of the page', async () => { | ||
await page.goto(`${baseUrl}/styles/colour/`, { waitUntil: 'load' }) | ||
const isBackToTopHidden = await page.waitForSelector('[data-module="app-back-to-top"]', { visible: false }) | ||
expect(isBackToTopHidden).toBeTruthy() | ||
}) | ||
it('is visible when at the bottom of the page', async () => { | ||
await page.goto(`${baseUrl}/styles/colour/`, { waitUntil: 'load' }) | ||
// Scroll to the bottom of the page | ||
await page.evaluate(() => window.scrollBy(0, document.body.scrollHeight)) | ||
const isBackToTopVisible = await page.waitForSelector('[data-module="app-back-to-top"]', { visible: true }) | ||
expect(isBackToTopVisible).toBeTruthy() | ||
}) | ||
it('goes back to the top of the page when interacted with', async () => { | ||
await page.goto(`${baseUrl}/styles/colour/`, { waitUntil: 'load' }) | ||
// Scroll to the bottom of the page | ||
await page.evaluate(() => window.scrollBy(0, document.body.scrollHeight)) | ||
// Make sure the back to top component is available to click | ||
await page.waitForSelector('[data-module="app-back-to-top"]', { visible: true }) | ||
await page.click('[data-module="app-back-to-top"]') | ||
const isAtTopOfPage = await page.evaluate(() => window.scrollY === 0) | ||
expect(isAtTopOfPage).toBeTruthy() | ||
}) | ||
}) |