Files
klz-cables.com/.pnpm-store/v10/files/50/e7f0b6374c35a780a2518a580d0a314c5d2dd6c8a480f228b1fdeeaf3524e4cc122c7249ac695ef19686326d157925db1555282373e37fc6f4d8af518beffc
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

168 lines
6.6 KiB
Plaintext

import { describe, it, expect } from 'vitest';
import { formatAdminURL } from './formatAdminURL.js';
describe('formatAdminURL', ()=>{
const serverURL = 'https://example.com';
const defaultAdminRoute = '/admin';
const rootAdminRoute = '/';
const dummyPath = '/collections/posts';
describe('relative URLs', ()=>{
it('should ignore `serverURL` when relative=true', ()=>{
const result = formatAdminURL({
adminRoute: defaultAdminRoute,
path: dummyPath,
serverURL,
relative: true
});
expect(result).toBe(`${defaultAdminRoute}${dummyPath}`);
});
it('should force relative URL when `serverURL` is omitted', ()=>{
const result = formatAdminURL({
adminRoute: defaultAdminRoute,
path: dummyPath,
relative: false
});
expect(result).toBe(`${defaultAdminRoute}${dummyPath}`);
});
});
describe('absolute URLs', ()=>{
it('should return absolute URL with serverURL', ()=>{
const result = formatAdminURL({
adminRoute: defaultAdminRoute,
path: dummyPath,
serverURL
});
expect(result).toBe(`${serverURL}${process.env.NEXT_BASE_PATH || ''}${defaultAdminRoute}${dummyPath}`);
});
it('should handle serverURL with trailing slash', ()=>{
const result = formatAdminURL({
adminRoute: defaultAdminRoute,
path: '/collections/posts',
serverURL: 'https://example.com/'
});
expect(result).toBe(`https://example.com${process.env.NEXT_BASE_PATH || ''}/admin/collections/posts`);
});
it('should handle serverURL with subdirectory', ()=>{
const result = formatAdminURL({
adminRoute: defaultAdminRoute,
path: '/collections/posts',
serverURL: 'https://example.com/api/v1'
});
expect(result).toBe(`https://example.com${process.env.NEXT_BASE_PATH || ''}/admin/collections/posts`);
});
});
describe('admin route handling', ()=>{
it('should return relative URL for adminRoute="/", no path, no `serverURL`', ()=>{
const result = formatAdminURL({
adminRoute: rootAdminRoute
});
expect(result).toBe('/');
});
it('should handle relative URL for adminRoute="/", with path, no `serverURL`', ()=>{
const result = formatAdminURL({
adminRoute: rootAdminRoute,
path: dummyPath
});
expect(result).toBe(dummyPath);
});
it('should return absolute URL for adminRoute="/", no path, with `serverURL`', ()=>{
const result = formatAdminURL({
adminRoute: rootAdminRoute,
serverURL
});
expect(result).toBe('https://example.com/');
});
it('should handle absolute URL for adminRoute="/", with path and `serverURL`', ()=>{
const result = formatAdminURL({
adminRoute: rootAdminRoute,
serverURL,
path: dummyPath
});
expect(result).toBe(`${serverURL}${process.env.NEXT_BASE_PATH || ''}${dummyPath}`);
});
});
describe('base path handling', ()=>{
it('should include basePath in URL', ()=>{
const result = formatAdminURL({
adminRoute: defaultAdminRoute,
basePath: '/v1',
path: dummyPath,
serverURL
});
expect(result).toBe(`${serverURL}${process.env.NEXT_BASE_PATH || ''}/v1${defaultAdminRoute}${dummyPath}`);
});
it('should handle basePath with adminRoute="/"', ()=>{
const result = formatAdminURL({
adminRoute: rootAdminRoute,
basePath: '/v1',
serverURL
});
expect(result).toBe(`${serverURL}${process.env.NEXT_BASE_PATH || ''}/v1`);
});
it('should handle basePath with no adminRoute', ()=>{
const result = formatAdminURL({
adminRoute: undefined,
basePath: '/v1',
path: dummyPath,
serverURL
});
expect(result).toBe(`${serverURL}${process.env.NEXT_BASE_PATH || ''}/v1${dummyPath}`);
});
it('should handle empty basePath', ()=>{
const result = formatAdminURL({
adminRoute: defaultAdminRoute,
basePath: '',
path: dummyPath,
serverURL
});
expect(result).toBe(`${serverURL}${process.env.NEXT_BASE_PATH || ''}${defaultAdminRoute}${dummyPath}`);
});
});
describe('path handling', ()=>{
it('should handle empty string path', ()=>{
const result = formatAdminURL({
adminRoute: defaultAdminRoute,
path: '',
serverURL
});
expect(result).toBe(`${serverURL}${process.env.NEXT_BASE_PATH || ''}${defaultAdminRoute}`);
});
it('should handle null path', ()=>{
const result = formatAdminURL({
adminRoute: defaultAdminRoute,
path: null,
serverURL
});
expect(result).toBe(`${serverURL}${process.env.NEXT_BASE_PATH || ''}${defaultAdminRoute}`);
});
it('should handle undefined path', ()=>{
const result = formatAdminURL({
adminRoute: defaultAdminRoute,
path: undefined,
serverURL
});
expect(result).toBe(`${serverURL}${process.env.NEXT_BASE_PATH || ''}${defaultAdminRoute}`);
});
it('should handle path with query parameters', ()=>{
const path = `${dummyPath}?page=2`;
const result = formatAdminURL({
adminRoute: defaultAdminRoute,
path,
serverURL
});
expect(result).toBe(`${serverURL}${process.env.NEXT_BASE_PATH || ''}${defaultAdminRoute}${path}`);
});
});
describe('edge cases', ()=>{
it('should return "/" when given minimal args', ()=>{
const result = formatAdminURL({
adminRoute: undefined,
basePath: '',
path: '',
relative: true
});
expect(result).toBe('/');
});
});
});
//# sourceMappingURL=formatAdminURL.spec.js.map