|
| 1 | +import { getPathsForRoute, localizeRoute } from './handlerUtils' |
| 2 | + |
| 3 | +describe('getPathsForRoute', () => { |
| 4 | + it('transforms / (root level) data routes to /index', () => { |
| 5 | + expect(getPathsForRoute('/', 'buildId')).toContainEqual(expect.stringMatching(/index.json/)) |
| 6 | + }) |
| 7 | + it('removes the trailing slash from data routes', () => { |
| 8 | + expect(getPathsForRoute('/foo/', 'buildId')).toContainEqual(expect.stringMatching(/foo.json$/)) |
| 9 | + }) |
| 10 | + it('respects the trailing slash for rsc routes', () => { |
| 11 | + expect(getPathsForRoute('/foo', 'buildId')).toContainEqual(expect.stringMatching(/foo.rsc$/)) |
| 12 | + expect(getPathsForRoute('/foo/', 'buildId')).toContainEqual(expect.stringMatching(/foo.rsc\/$/)) |
| 13 | + }) |
| 14 | +}) |
| 15 | + |
| 16 | +describe('localizeRoute', () => { |
| 17 | + it('returns a non-localized path for the default locale', () => { |
| 18 | + expect( |
| 19 | + localizeRoute('/foo', { |
| 20 | + defaultLocale: 'en', |
| 21 | + locales: ['en', 'fr', 'de'], |
| 22 | + }), |
| 23 | + ).toContain('/foo') |
| 24 | + }) |
| 25 | + it('returns a localized path for each non-default locale', () => { |
| 26 | + expect( |
| 27 | + localizeRoute('/foo', { |
| 28 | + defaultLocale: 'en', |
| 29 | + locales: ['en', 'fr', 'de'], |
| 30 | + }), |
| 31 | + ).toEqual(expect.arrayContaining(['/fr/foo', '/de/foo'])) |
| 32 | + }) |
| 33 | + it('returns every locale for data routes', () => { |
| 34 | + expect( |
| 35 | + localizeRoute( |
| 36 | + '/foo', |
| 37 | + { |
| 38 | + defaultLocale: 'en', |
| 39 | + locales: ['en', 'fr', 'de'], |
| 40 | + }, |
| 41 | + true, |
| 42 | + ), |
| 43 | + ).toEqual([ |
| 44 | + expect.stringMatching(/\/en\/foo/), |
| 45 | + expect.stringMatching(/\/fr\/foo/), |
| 46 | + expect.stringMatching(/\/de\/foo/), |
| 47 | + ]) |
| 48 | + }) |
| 49 | + it('skips localization if i18n not configured', () => { |
| 50 | + expect(localizeRoute('/foo')).toEqual(['/foo']) |
| 51 | + }) |
| 52 | +}) |
0 commit comments