Files
next.js/test/e2e/use-link-status/index.test.ts
Arian Tron 61f56f997c
Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
first commit
2026-03-10 19:37:31 +03:30

149 lines
5.3 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
import { retry, waitFor } from 'next-test-utils'
describe('useLinkStatus', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should show pending state for the last link clicked when clicking multiple links in a row', async () => {
const browser = await next.browser('/')
// Click post 1 link
await browser.elementById('post-1-link').click()
// Quickly click post 2 link
await browser.elementById('post-2-link').click()
// The pending state should be shown for post 2 link
expect(await browser.elementById('post-2-loading').text()).toBe('(Loading)')
// Post 1 should not show loading
const post1Loading = await browser.elementsByCss('#post-1-loading')
expect(post1Loading.length).toBe(0)
// Wait for navigation to complete and verify we end up on post 2
await browser.waitForIdleNetwork()
await browser.waitForElementByCss('[data-testid="post-2-page"]')
})
it('should remove pending state after shallow routing', async () => {
const browser = await next.browser('/')
// Click post 1 link
await browser.elementById('post-1-link').click()
// Verify pending state is shown
expect(await browser.elementById('post-1-loading').text()).toBe('(Loading)')
// Trigger shallow routing by clicking debug mode button
await browser.elementById('enable-debug-btn').click()
// Wait for the new render to commit to make sure that the navigation transition is interrupted
await retry(async () => {
expect(
await browser.elementByCss('[data-testid="debug-mode"]').text()
).toBe('Debug Mode Enabled')
})
// Pending state should be gone
const post1LoadingElements = await browser.elementsByCss('#post-1-loading')
expect(post1LoadingElements.length).toBe(0)
})
it('should remove pending state after browser back navigation', async () => {
const browser = await next.browser('/')
// Click post 1 link
await browser.elementById('post-1-link').click()
// Wait for navigation to complete
await browser.waitForIdleNetwork()
await browser.waitForElementByCss('[data-testid="post-1-page"]')
// Click post 2 link
await browser.elementById('post-2-link').click()
// Verify pending state is shown
expect(await browser.elementById('post-2-loading').text()).toBe('(Loading)')
// Go back using browser back button
await browser.back()
// Wait for navigation and verify we're back on home
// We should be on home because page 2 has not been fully loaded yet when we navigated back
await browser.waitForIdleNetwork()
await browser.waitForElementByCss('[data-testid="home-link"]')
// Pending state should be gone
const post2LoadingElements = await browser.elementsByCss('#post-2-loading')
expect(post2LoadingElements.length).toBe(0)
})
it('should show pending state when navigating to the same path', async () => {
const browser = await next.browser('/')
// Click post 1 link
await browser.elementById('post-1-link').click()
// Wait for navigation to complete
await browser.waitForIdleNetwork()
await browser.waitForElementByCss('[data-testid="post-1-page"]')
// Click post 1 link again
await browser.elementById('post-1-link').click()
// Verify pending state is shown even though it's the same path
expect(await browser.elementById('post-1-loading').text()).toBe('(Loading)')
// Wait for navigation to complete and verify we're still on post 1
await browser.waitForIdleNetwork()
await browser.waitForElementByCss('[data-testid="post-1-page"]')
})
it('should remove pending state when navigation starts by router.push', async () => {
const browser = await next.browser('/')
// Click post 1 link
await browser.elementById('post-1-link').click()
// Verify pending state is shown
expect(await browser.elementById('post-1-loading').text()).toBe('(Loading)')
// Click router push button for post 2
await browser.elementById('router-push-2-btn').click()
// Pending state for post 1 should be gone
const post1Loading = await browser.elementsByCss('#post-1-loading')
expect(post1Loading.length).toBe(0)
// Wait for navigation to complete and verify we end up on post 2
await browser.waitForIdleNetwork()
await browser.waitForElementByCss('[data-testid="post-2-page"]')
})
it('should remove pending state when server action triggers a redirect', async () => {
const browser = await next.browser('/post/1')
await browser.waitForIdleNetwork()
await browser.waitForElementByCss('[data-testid="post-1-page"]')
// Click post 2 link
await browser.elementById('post-2-link').click()
// Verify pending state is shown
expect(await browser.elementById('post-2-loading').text()).toBe('(Loading)')
// Click server action button for home
await browser.elementById('server-action-home-btn').click()
await waitFor(1000) // buffer for server action to return a redirect
// Pending state for post 2 should be gone
const post2Loading = await browser.elementsByCss('#post-2-loading')
expect(post2Loading.length).toBe(0)
// Wait for navigation to complete and verify we end up on home
await browser.waitForIdleNetwork()
await browser.waitForElementByCss('[data-testid="home-link"]')
})
})