Alan Agius 3c9697a8c3 feat(@angular/ssr): introduce new hybrid rendering API
This commit introduces the new hybrid rendering API for Angular's Server-Side Rendering (SSR). The API aims to enhance the flexibility of SSR as discussed in https://github.com/angular/angular/discussions/56785

- This API is currently not accessible.
- Additional work is required in the Angular CLI to:
  - Wire up the manifest.
  - Integrate other necessary components.
2024-08-09 09:36:54 +02:00

68 lines
2.4 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { getPotentialLocaleIdFromUrl } from '../src/i18n';
describe('getPotentialLocaleIdFromUrl', () => {
it('should extract locale ID correctly when basePath is present', () => {
const url = new URL('https://example.com/base/en/page');
const basePath = '/base';
const localeId = getPotentialLocaleIdFromUrl(url, basePath);
expect(localeId).toBe('en');
});
it('should extract locale ID correctly when basePath has trailing slash', () => {
const url = new URL('https://example.com/base/en/page');
const basePath = '/base/';
const localeId = getPotentialLocaleIdFromUrl(url, basePath);
expect(localeId).toBe('en');
});
it('should extract locale ID correctly when url has no trailing slash', () => {
const url = new URL('https://example.com/base/en');
const basePath = '/base/';
const localeId = getPotentialLocaleIdFromUrl(url, basePath);
expect(localeId).toBe('en');
});
it('should extract locale ID correctly when url no trailing slash', () => {
const url = new URL('https://example.com/base/en/');
const basePath = '/base/';
const localeId = getPotentialLocaleIdFromUrl(url, basePath);
expect(localeId).toBe('en');
});
it('should handle URL with no pathname after basePath', () => {
const url = new URL('https://example.com/base/');
const basePath = '/base';
const localeId = getPotentialLocaleIdFromUrl(url, basePath);
expect(localeId).toBe('');
});
it('should handle URL where basePath is the entire pathname', () => {
const url = new URL('https://example.com/base');
const basePath = '/base';
const localeId = getPotentialLocaleIdFromUrl(url, basePath);
expect(localeId).toBe('');
});
it('should handle complex basePath correctly', () => {
const url = new URL('https://example.com/base/path/en/page');
const basePath = '/base/path';
const localeId = getPotentialLocaleIdFromUrl(url, basePath);
expect(localeId).toBe('en');
});
it('should handle URL with query parameters and hash', () => {
const url = new URL('https://example.com/base/en?query=param#hash');
const basePath = '/base';
const localeId = getPotentialLocaleIdFromUrl(url, basePath);
expect(localeId).toBe('en');
});
});