Skip to content

Commit

Permalink
Fix React hook useOnClickRouteLink tests for Linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydenseric committed Jun 7, 2022
1 parent 0f7cb60 commit 108cbbc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
new Deno `std` APIs, fixing
[#5](https://github.com/jaydenseric/ruck/issues/5).
- Fixed the test script not exiting with an error status when tests fail.
- Fixed the React hook `useOnClickRouteLink` tests failing in Linux environments
due to the different macOS Chrome browser behavior when a “meta” key is
pressed while clicking a link.
- Added a script for finding Ruck’s minimum compatible Deno version.
- Use a more specific Deno version for the setup Deno step in the GitHub Actions
CI config.
Expand Down
23 changes: 19 additions & 4 deletions useOnClickRouteLink.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ Deno.test("`useOnClickRouteLink` in a DOM environment.", async () => {

try {
const browser = await puppeteer.launch();
const browserUserAgent = await browser.userAgent();

try {
await testPuppeteerPage(
browser,
projectFilesOriginUrl,
async (page) => {
const urlPageA = `http://localhost:${ruckAppPort}/`;
const urlPageB = `http://localhost:${ruckAppPort}/b`;

await page.goto(urlPageA);

Expand All @@ -138,14 +140,27 @@ Deno.test("`useOnClickRouteLink` in a DOM environment.", async () => {

assertStrictEquals(page.url(), urlPageA);

// Test holding the meta key when clicking the link prevents a
// client side navigation…
// Test holding a meta key when clicking the link prevents a client
// side navigation…

await page.keyboard.down("Meta");
await page.click('a[href="/b"]');
await page.keyboard.up("Meta");

assertStrictEquals(page.url(), urlPageA);
if (browserUserAgent.includes("Macintosh")) {
// macOS Chrome opens a link clicked while the meta (command) key
// is pressed in a new tab, so the current page URL should not
// have changed.
assertStrictEquals(page.url(), urlPageA);
} else {
// Linux Chrome opens a link clicked while a meta (command) key is
// pressed in the current tab, so the current page URL should have
// changed.
assertStrictEquals(page.url(), urlPageB);

// Manually go to page A to prepare the next test.
await page.goto(urlPageA);
}

// Test holding the shift key when clicking the link prevents a
// client side navigation…
Expand Down Expand Up @@ -192,7 +207,7 @@ Deno.test("`useOnClickRouteLink` in a DOM environment.", async () => {

await page.click('a[href="/a"]');

assertStrictEquals(page.url(), `http://localhost:${ruckAppPort}/b`);
assertStrictEquals(page.url(), urlPageB);
},
);
} finally {
Expand Down

0 comments on commit 108cbbc

Please sign in to comment.