|
| 1 | +import { join } from 'path' |
| 2 | +import { createNext, FileRef } from 'e2e-utils' |
| 3 | +import { NextInstance } from 'e2e-utils' |
| 4 | +import { check } from 'next-test-utils' |
| 5 | +import webdriver from 'next-webdriver' |
| 6 | + |
| 7 | +describe('i18n-data-fetching-redirect', () => { |
| 8 | + let next: NextInstance |
| 9 | + |
| 10 | + // TODO: investigate tests failures on deploy |
| 11 | + if ((global as any).isNextDeploy) { |
| 12 | + it('should skip temporarily', () => {}) |
| 13 | + return |
| 14 | + } |
| 15 | + |
| 16 | + beforeAll(async () => { |
| 17 | + next = await createNext({ |
| 18 | + files: { |
| 19 | + pages: new FileRef(join(__dirname, 'app/pages')), |
| 20 | + 'next.config.js': new FileRef(join(__dirname, 'app/next.config.js')), |
| 21 | + }, |
| 22 | + dependencies: {}, |
| 23 | + }) |
| 24 | + }) |
| 25 | + afterAll(() => next.destroy()) |
| 26 | + |
| 27 | + describe('Redirect to locale from context', () => { |
| 28 | + test.each` |
| 29 | + path | locale |
| 30 | + ${'gssp-redirect'} | ${'en'} |
| 31 | + ${'gssp-redirect'} | ${'sv'} |
| 32 | + ${'gsp-blocking-redirect'} | ${'en'} |
| 33 | + ${'gsp-blocking-redirect'} | ${'sv'} |
| 34 | + ${'gsp-fallback-redirect'} | ${'en'} |
| 35 | + ${'gsp-fallback-redirect'} | ${'sv'} |
| 36 | + `('$path $locale', async ({ path, locale }) => { |
| 37 | + const browser = await webdriver(next.url, `/${locale}/${path}/from-ctx`) |
| 38 | + |
| 39 | + await check( |
| 40 | + () => browser.eval('window.location.pathname'), |
| 41 | + `/${locale}/home` |
| 42 | + ) |
| 43 | + expect(await browser.elementByCss('#router-locale').text()).toBe(locale) |
| 44 | + expect(await browser.elementByCss('#router-pathname').text()).toBe( |
| 45 | + '/home' |
| 46 | + ) |
| 47 | + expect(await browser.elementByCss('#router-as-path').text()).toBe('/home') |
| 48 | + }) |
| 49 | + |
| 50 | + test.each` |
| 51 | + path | locale |
| 52 | + ${'gssp-redirect'} | ${'en'} |
| 53 | + ${'gssp-redirect'} | ${'sv'} |
| 54 | + ${'gsp-blocking-redirect'} | ${'en'} |
| 55 | + ${'gsp-blocking-redirect'} | ${'sv'} |
| 56 | + ${'gsp-fallback-redirect'} | ${'en'} |
| 57 | + ${'gsp-fallback-redirect'} | ${'sv'} |
| 58 | + `('next/link $path $locale', async ({ path, locale }) => { |
| 59 | + const browser = await webdriver(next.url, `/${locale}`) |
| 60 | + await browser.eval('window.beforeNav = 1') |
| 61 | + |
| 62 | + await browser.elementByCss(`#to-${path}-from-ctx`).click() |
| 63 | + |
| 64 | + await check( |
| 65 | + () => browser.eval('window.location.pathname'), |
| 66 | + `/${locale}/home` |
| 67 | + ) |
| 68 | + |
| 69 | + expect(await browser.eval('window.beforeNav')).toBe(1) |
| 70 | + expect(await browser.elementByCss('#router-locale').text()).toBe(locale) |
| 71 | + expect(await browser.elementByCss('#router-pathname').text()).toBe( |
| 72 | + '/home' |
| 73 | + ) |
| 74 | + expect(await browser.elementByCss('#router-as-path').text()).toBe('/home') |
| 75 | + }) |
| 76 | + }) |
| 77 | +}) |
0 commit comments