Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Add a test to show the default behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayphen committed Jul 15, 2020
1 parent 3081946 commit 0874397
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 7 additions & 2 deletions test/apps/scroll/src/routes/search-form.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<script>
import { goto } from "@sapper/app";
function handleSearch() {
function preserveScroll() {
goto("/a-third-tall-page", { noscroll: true });
}
function scroll() {
goto("/a-third-tall-page");
}
</script>

<h1>A search form</h1>

<div style="height: 9999px" />

<div id="search">
<button on:click={handleSearch}>Search</button>
<button id="scroll" on:click={scroll}>Don't preserve scroll</button>
<button id="preserve" on:click={preserveScroll}>Preserve scroll</button>
</div>

17 changes: 15 additions & 2 deletions test/apps/scroll/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,27 @@ describe('scroll', function () {
assert.equal(firstScrollY, secondScrollY);
});

it('preserves scroll when noscroll is passed to goto', async () => {
it('scrolls to the top when navigating with goto', async () => {
await r.load(`/search-form#search`);
await r.sapper.start();

let initialScrollY = await r.page.evaluate(() => window.scrollY);
assert.ok(initialScrollY > 0, String(initialScrollY));

await r.page.click("button");
await r.page.click("button#scroll");

let scrollY = await r.page.evaluate(() => window.scrollY);
assert.ok(scrollY === 0, String(scrollY));
});

it('preserves scroll when noscroll: true is passed to goto', async () => {
await r.load(`/search-form#search`);
await r.sapper.start();

let initialScrollY = await r.page.evaluate(() => window.scrollY);
assert.ok(initialScrollY > 0, String(initialScrollY));

await r.page.click("button#preserve");

let scrollY = await r.page.evaluate(() => window.scrollY);
assert.ok(scrollY === initialScrollY, String(scrollY));
Expand Down

0 comments on commit 0874397

Please sign in to comment.