Files
landing-app/landing/src/app/core/routes.spec.ts
pigui 399b8d5450 Add a page for every way to help
/colabora (/en/contribute, /ca/col-labora) — the calls' own section, so
it lists what /colabora/{slug} are — brings the open calls, the good
first issues across the collective's repositories, and a five-step
guide from picking a task to having it reviewed. With nothing open and
nothing labelled, the guide and the other ways to help are still there.
The landing's "contribute" section links to it.

Also fixes the landing's issue list, which @pi/ui's `li + li` margin
spaced twice over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:14:16 +02:00

130 lines
3.6 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from './api';
import {
homeHref,
listingAlternates,
listingPath,
resolveRoute,
SECTIONS,
} from './routes';
describe('resolveRoute', () => {
it('reads a page at the root as the default language', () => {
expect(resolveRoute('/sobre-nosotros')).toEqual({
type: 'page',
locale: DEFAULT_LOCALE,
slug: 'sobre-nosotros',
});
});
it('reads a prefixed page in the language it names', () => {
expect(resolveRoute('/en/about-us')).toEqual({
type: 'page',
locale: 'en',
slug: 'about-us',
});
expect(resolveRoute('/ca/qui-som/')).toEqual({
type: 'page',
locale: 'ca',
slug: 'qui-som',
});
});
it('reads a record under its section, in each language', () => {
expect(resolveRoute('/proyectos/catalogo')).toEqual({
type: 'project',
locale: 'es',
slug: 'catalogo',
});
expect(resolveRoute('/en/projects/catalogo')).toEqual({
type: 'project',
locale: 'en',
slug: 'catalogo',
});
expect(resolveRoute('/ca/equip/ada')).toEqual({
type: 'member',
locale: 'ca',
slug: 'ada',
});
expect(resolveRoute('/ca/col-labora/frontend')).toEqual({
type: 'call',
locale: 'ca',
slug: 'frontend',
});
});
// A section only means something in its own language: `/projects/x` is not
// an address the API hands out for Spanish.
it('refuses a section spelled in another language', () => {
expect(resolveRoute('/projects/catalogo')).toBeNull();
expect(resolveRoute('/en/proyectos/catalogo')).toBeNull();
});
// The API never spells the default language with a prefix, so one record
// has one address rather than two.
it('refuses the default language as a prefix', () => {
expect(resolveRoute('/es/sobre-nosotros')).toBeNull();
expect(resolveRoute('/es/proyectos/catalogo')).toBeNull();
});
it('refuses what is not shaped like a record', () => {
expect(resolveRoute('/')).toBeNull();
expect(resolveRoute('/fr/a-propos')).toBeNull();
expect(resolveRoute('/proyectos/catalogo/extra')).toBeNull();
});
it('knows every section in every language', () => {
for (const sections of Object.values(SECTIONS)) {
expect(Object.keys(sections).sort()).toEqual(
[...SUPPORTED_LOCALES].sort(),
);
}
});
});
describe('listings', () => {
it('reads the radar in every language, before any page of that slug', () => {
expect(resolveRoute('/radar')).toEqual({
type: 'radar',
locale: 'es',
slug: '',
});
expect(resolveRoute('/ca/radar')).toEqual({
type: 'radar',
locale: 'ca',
slug: '',
});
});
it('builds the address resolveRoute reads back', () => {
for (const locale of SUPPORTED_LOCALES) {
expect(resolveRoute(listingPath('radar', locale))?.type).toBe('radar');
}
expect(listingAlternates('radar')).toEqual({
es: '/radar',
en: '/en/radar',
ca: '/ca/radar',
});
});
// The calls' section with nothing after it is the list of ways to help.
it('reads a call section on its own as the contribute listing', () => {
expect(resolveRoute('/colabora')).toEqual({
type: 'contribute',
locale: 'es',
slug: '',
});
expect(resolveRoute('/en/contribute')?.type).toBe('contribute');
expect(resolveRoute('/en/contribute/frontend')?.type).toBe('call');
});
});
describe('homeHref', () => {
it('answers on ?lang= for every language but the default', () => {
expect(homeHref(DEFAULT_LOCALE)).toBe('/');
expect(homeHref('ca')).toBe('/?lang=ca');
});
});