diff --git a/packages/kit/test/apps/basics/src/routes/data-sveltekit/noscroll/+page.svelte b/packages/kit/test/apps/basics/src/routes/data-sveltekit/noscroll/+page.svelte new file mode 100644 index 000000000000..e9ad0b2d6b0d --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/data-sveltekit/noscroll/+page.svelte @@ -0,0 +1,8 @@ +
+ +one + +
+ two + three +
diff --git a/packages/kit/test/apps/basics/src/routes/data-sveltekit/noscroll/target/+page.svelte b/packages/kit/test/apps/basics/src/routes/data-sveltekit/noscroll/target/+page.svelte new file mode 100644 index 000000000000..a0c3426c8a59 --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/data-sveltekit/noscroll/target/+page.svelte @@ -0,0 +1,3 @@ +
+ +

target

diff --git a/packages/kit/test/apps/basics/src/routes/data-sveltekit/prefetch/+page.svelte b/packages/kit/test/apps/basics/src/routes/data-sveltekit/prefetch/+page.svelte new file mode 100644 index 000000000000..04ebcd22ce76 --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/data-sveltekit/prefetch/+page.svelte @@ -0,0 +1,6 @@ +one + +
+ two + three +
diff --git a/packages/kit/test/apps/basics/src/routes/data-sveltekit/prefetch/target/+page.svelte b/packages/kit/test/apps/basics/src/routes/data-sveltekit/prefetch/target/+page.svelte new file mode 100644 index 000000000000..9c40e105a35f --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/data-sveltekit/prefetch/target/+page.svelte @@ -0,0 +1 @@ +

target

diff --git a/packages/kit/test/apps/basics/src/routes/data-sveltekit/reload/+page.svelte b/packages/kit/test/apps/basics/src/routes/data-sveltekit/reload/+page.svelte new file mode 100644 index 000000000000..1de9e3cd21ad --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/data-sveltekit/reload/+page.svelte @@ -0,0 +1,6 @@ +one + +
+ two + three +
diff --git a/packages/kit/test/apps/basics/src/routes/data-sveltekit/reload/target/+page.svelte b/packages/kit/test/apps/basics/src/routes/data-sveltekit/reload/target/+page.svelte new file mode 100644 index 000000000000..9c40e105a35f --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/data-sveltekit/reload/target/+page.svelte @@ -0,0 +1 @@ +

target

diff --git a/packages/kit/test/apps/basics/test/client.test.js b/packages/kit/test/apps/basics/test/client.test.js index 6bd08d9c428c..3d0b41d0053c 100644 --- a/packages/kit/test/apps/basics/test/client.test.js +++ b/packages/kit/test/apps/basics/test/client.test.js @@ -690,3 +690,76 @@ test.describe.serial('Invalidation', () => { expect(await page.textContent('h1')).toBe('a: 4, b: 5'); }); }); + +test.describe('data-sveltekit attributes', () => { + test('data-sveltekit-prefetch', async ({ baseURL, page }) => { + const requests = []; + page.on('request', (r) => requests.push(r.url())); + + await page.goto('/data-sveltekit/prefetch'); + await page.locator('#one').dispatchEvent('mousemove'); + await Promise.all([ + page.waitForTimeout(100), // wait for prefetching to start + page.waitForLoadState('networkidle') // wait for prefetching to finish + ]); + expect(requests).toContain(`${baseURL}/src/routes/data-sveltekit/prefetch/target/+page.svelte`); + + requests.length = 0; + await page.goto('/data-sveltekit/prefetch'); + await page.locator('#two').dispatchEvent('mousemove'); + await Promise.all([ + page.waitForTimeout(100), // wait for prefetching to start + page.waitForLoadState('networkidle') // wait for prefetching to finish + ]); + expect(requests).toContain(`${baseURL}/src/routes/data-sveltekit/prefetch/target/+page.svelte`); + + requests.length = 0; + await page.goto('/data-sveltekit/prefetch'); + await page.locator('#three').dispatchEvent('mousemove'); + await Promise.all([ + page.waitForTimeout(100), // wait for prefetching to start + page.waitForLoadState('networkidle') // wait for prefetching to finish + ]); + expect(requests).not.toContain( + `${baseURL}/src/routes/data-sveltekit/prefetch/target/+page.svelte` + ); + }); + + test('data-sveltekit-reload', async ({ baseURL, page, clicknav }) => { + const requests = []; + page.on('request', (r) => requests.push(r.url())); + + await page.goto('/data-sveltekit/reload'); + await page.click('#one'); + await page.waitForLoadState('networkidle'); + expect(requests).toContain(`${baseURL}/src/routes/data-sveltekit/reload/target`); + + requests.length = 0; + await page.goto('/data-sveltekit/reload'); + await page.click('#two'); + await page.waitForLoadState('networkidle'); + expect(requests).toContain(`${baseURL}/src/routes/data-sveltekit/reload/target`); + + requests.length = 0; + await page.goto('/data-sveltekit/reload'); + await clicknav('#three'); + expect(requests).not.toContain(`${baseURL}/src/routes/data-sveltekit/reload/target`); + }); + + test('data-sveltekit-noscroll', async ({ baseURL, page, clicknav }) => { + await page.goto('/data-sveltekit/noscroll'); + // await page.evaluate(() => window.scrollTo(0, 1000)); + await clicknav('#one'); + expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(1000); + + // await page.goto('/data-sveltekit/noscroll'); + // // await page.evaluate(() => window.scrollTo(0, 1000)); + // await clicknav('#two'); + // expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(1000); + + await page.goto('/data-sveltekit/noscroll'); + // await page.evaluate(() => window.scrollTo(0, 1000)); + await clicknav('#three'); + expect(await page.evaluate(() => window.scrollY)).toBe(0); + }); +});