Skip to content

Commit

Permalink
test: test scroll top on nested pages and
Browse files Browse the repository at this point in the history
  • Loading branch information
huang-julien committed Jul 30, 2023
1 parent c3ef8ad commit 94736ad
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 2 deletions.
42 changes: 42 additions & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,48 @@ describe('nuxt links', () => {

await page.close()
})

it('expect scroll to top on routes with same component', async () => {
// #22402
const page = await createPage('/big-page-1')
await page.setViewportSize({
width: 1000,
height: 1000
})
await page.waitForLoadState('networkidle')
await page.locator('#big-page-2').scrollIntoViewIfNeeded()
expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0)
await page.locator('#big-page-2').click()
console.log('HOOOOOOHOHO' + await page.evaluate(() => window.scrollY))
await page.waitForURL(url => url.href.includes('/big-page-2'))
console.log('HAAAAHAHAHA' + await page.evaluate(() => window.scrollY))
expect(await page.evaluate(() => window.scrollY)).toBe(0)
await page.locator('#big-page-1').scrollIntoViewIfNeeded()
expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0)
await page.locator('#big-page-1').click()
await page.waitForURL(url => url.href.includes('/big-page-1'))
expect(await page.evaluate(() => window.scrollY)).toBe(0)
})

it('expect scroll to top on nested pages', async () => {
// #20523
const page = await createPage('/nested/foo/test')
await page.setViewportSize({
width: 1000,
height: 1000
})
await page.waitForLoadState('networkidle')
await page.locator('#user-test').scrollIntoViewIfNeeded()
expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0)
await page.locator('#user-test').click()
await page.waitForURL(url => url.href.includes('/nested/foo/user-test'))
expect(await page.evaluate(() => window.scrollY)).toBe(0)
await page.locator('#test').scrollIntoViewIfNeeded()
expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0)
await page.locator('#test').click()
await page.waitForURL(url => url.href.includes('/nested/foo/test'))
expect(await page.evaluate(() => window.scrollY)).toBe(0)
})
})

describe('head tags', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ export default defineNuxtModule({
meta: {
name: 'page-extend'
},
setup () {
setup() {

Check failure on line 7 in test/fixtures/basic/modules/page-extend/index.ts

View workflow job for this annotation

GitHub Actions / lint

Missing space before function parentheses
const nuxt = useNuxt()
const resolver = createResolver(import.meta.url)

nuxt.hook('pages:extend', (pages) => {
pages.push({
name: 'page-extend',
path: '/page-extend',
file: resolver.resolve('./runtime/page.vue')
file: resolver.resolve('../runtime/page.vue')
}, {
path: '/big-page-1',
file: '@/modules/page-extend/pages/big-page.vue'
}, {
path: '/big-page-2',
file: '@/modules/page-extend/pages/big-page.vue'
})
})
}
Expand Down
36 changes: 36 additions & 0 deletions test/fixtures/basic/modules/page-extend/pages/big-page.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<div>
<div class="big-block">
big
</div>
<div class="big-block">
page
</div>
<NuxtLink id="big-page-1" to="/big-page-1">
to big page 1
</NuxtLink>
<NuxtLink id="big-page-2" to="/big-page-2">
to big page 2
</NuxtLink>
<NuxtLink id="big-page-2-test-test" to="/big-page-2?test=test">
to big page 2 with ?test=test
</NuxtLink>
<NuxtLink id="big-page-2-test-super-test" to="/big-page-2?test=super-test">
to big page 2 with ?test=super-test
</NuxtLink>
</div>
</template>

<script setup>
definePageMeta({
layout: false
})
</script>

<style scoped>
.big-block {
height: 90vh;
width: 100vw;
background-color: brown;
}
</style>
1 change: 1 addition & 0 deletions test/fixtures/basic/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<component :is="`with${'-'.toString()}suffix`" />
<ClientWrapped ref="clientRef" style="color: red;" class="client-only" />
<ServerOnlyComponent class="server-only" style="background-color: gray;" />
<NuxtLink to="/big-page-1">to big 1</NuxtLink>

Check warning on line 52 in test/fixtures/basic/pages/index.vue

View workflow job for this annotation

GitHub Actions / lint

Expected 1 line break after opening tag (`<NuxtLink>`), but no line breaks found
</div>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,16 @@ const route = useRoute('nested-foo')
<div>
<div>nested/[foo]/index.vue</div>
<div>foo: {{ route.params.foo }}</div>

<div class="big-block" />
<div class="big-block" />
<NuxtPage />
</div>
</template>

<style scoped>
.big-block {
height: 90vh;
width: 100vw;
}
</style>

Check failure on line 21 in test/fixtures/basic/pages/nested/[foo].vue

View workflow job for this annotation

GitHub Actions / lint

Newline required at end of file but not found
2 changes: 2 additions & 0 deletions test/fixtures/basic/pages/nested/[foo]/[bar].vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ const route = useRoute('nested-foo-bar')
<div>nested/[foo]/[bar].vue</div>
<div>foo: {{ route.params.foo }}</div>
<div>bar: {{ route.params.bar }}</div>
<NuxtLink to="/nested/foo/user-test" id="user-test">to /nested/foo/user-test</NuxtLink>
<NuxtLink to="/nested/foo/test" id="test">to /nested/foo/test</NuxtLink>
</div>
</template>
3 changes: 3 additions & 0 deletions test/fixtures/basic/pages/nested/[foo]/user-[group].vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ const route = useRoute('nested-foo-user-group')
<div>nested/[foo]/user-[group].vue</div>
<div>foo: {{ route.params.foo }}</div>
<div>group: {{ route.params.group }}</div>

Check failure on line 10 in test/fixtures/basic/pages/nested/[foo]/user-[group].vue

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
<NuxtLink to="/nested/foo/user-test" id="user-test">to /nested/foo/user-test</NuxtLink>
<NuxtLink to="/nested/foo/test" id="test">to /nested/foo/test</NuxtLink>
</div>
</template>

0 comments on commit 94736ad

Please sign in to comment.