Skip to content

Commit

Permalink
duplicate new tests to ssg and dev server
Browse files Browse the repository at this point in the history
  • Loading branch information
mtwilliams-code committed Dec 11, 2024
1 parent 13f61b4 commit c5f8957
Showing 1 changed file with 53 additions and 5 deletions.
58 changes: 53 additions & 5 deletions packages/astro/test/i18n-routing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2000,12 +2000,14 @@ describe('Fallback rewrite dev server', () => {
root: './fixtures/i18n-routing-fallback/',
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
locales: ['en', 'fr', 'es', 'it', 'pt'],
routing: {
prefixDefaultLocale: false,
},
fallback: {
fr: 'en',
it: 'en',
es: 'pt',
},
fallbackType: 'rewrite',
},
Expand All @@ -2021,6 +2023,27 @@ describe('Fallback rewrite dev server', () => {
assert.match(html, /Hello/);
// assert.fail()
});

it('should render fallback locale paths with path parameters correctly (fr)', async () => {
let response = await fixture.fetch('/fr/blog/1');
assert.equal(response.status, 200);
const text = await response.text();
assert.match(text, /Hello world/);
});

it('should render fallback locale paths with path parameters correctly (es)', async () => {
let response = await fixture.fetch('/es/blog/1');
assert.equal(response.status, 200);
const text = await response.text();
assert.match(text, /Hola mundo/);
});

it('should render fallback locale paths with query parameters correctly (it)', async () => {
let response = await fixture.fetch('/it/blog/1');
assert.equal(response.status, 200);
const text = await response.text();
assert.match(text, /Hello world/);
});
});

describe('Fallback rewrite SSG', () => {
Expand All @@ -2032,13 +2055,15 @@ describe('Fallback rewrite SSG', () => {
root: './fixtures/i18n-routing-fallback/',
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
locales: ['en', 'fr', 'es', 'it', 'pt'],
routing: {
prefixDefaultLocale: false,
fallbackType: 'rewrite',
},
fallback: {
fr: 'en',
it: 'en',
es: 'pt',
},
},
});
Expand All @@ -2051,6 +2076,21 @@ describe('Fallback rewrite SSG', () => {
assert.match(html, /Hello/);
// assert.fail()
});

it('should render fallback locale paths with path parameters correctly (fr)', async () => {
const html = await fixture.readFile('/fr/blog/1/index.html');
assert.match(html, /Hello world/);
});

it('should render fallback locale paths with path parameters correctly (es)', async () => {
const html = await fixture.readFile('/es/blog/1/index.html');
assert.match(html, /Hola mundo/);
});

it('should render fallback locale paths with query parameters correctly (it)', async () => {
const html = await fixture.readFile('/it/blog/1/index.html');
assert.match(html, /Hello world/);
});
});

describe('Fallback rewrite SSR', () => {
Expand All @@ -2073,7 +2113,7 @@ describe('Fallback rewrite SSR', () => {
},
fallback: {
fr: 'en',
it: 'pt',
it: 'en',
es: 'pt',
},
},
Expand All @@ -2090,19 +2130,27 @@ describe('Fallback rewrite SSR', () => {
assert.match(html, /Hello/);
});

it('should render the first fallback locale paths with path parameters correctly', async () => {
it('should render fallback locale paths with path parameters correctly (fr)', async () => {
let request = new Request('http://example.com/new-site/fr/blog/1');
let response = await app.render(request);
assert.equal(response.status, 200);
const text = await response.text();
assert.match(text, /Hello world/);
});

it('should render other fallback locale paths with path parameters correctly', async () => {
it('should render fallback locale paths with path parameters correctly (es)', async () => {
let request = new Request('http://example.com/new-site/es/blog/1');
let response = await app.render(request);
assert.equal(response.status, 200);
const text = await response.text();
assert.match(text, /Hola mundo/);
});

it('should render fallback locale paths with query parameters correctly (it)', async () => {
let request = new Request('http://example.com/new-site/it/blog/1');
let response = await app.render(request);
assert.equal(response.status, 200);
const text = await response.text();
assert.match(text, /Hello world/);
});
});

0 comments on commit c5f8957

Please sign in to comment.