Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/app/(organizer)/app/(chrome)/layout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import '@testing-library/jest-dom/vitest';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, render, screen } from '@testing-library/react';
import { CATALOG_LOCALES } from '@/i18n/config';
import { TEST_LOCALES } from '@/i18n/testing/locales';
import { ship } from '@/i18n/testing/ship';
import { INSTANCE_NAME } from '@/lib/site-config';

Expand All @@ -23,9 +23,6 @@ vi.mock('@/i18n/server', async () => ({

const { default: OrganizerLayout, generateMetadata } = await import('./layout');

/** Every language with a catalog besides English, each tried in turn. */
const OTHER_LANGUAGES = CATALOG_LOCALES.filter((locale) => locale !== 'en');

afterEach(() => {
cleanup();
organizer.locale = null;
Expand All @@ -51,7 +48,7 @@ describe('the organizer app’s header', () => {
});
});

it.each(OTHER_LANGUAGES)('is in the organizer’s language, %s, and marked so', async (other) => {
it.each(TEST_LOCALES)('is in the organizer’s language, %s, and marked so', async (other) => {
ship('organizer', ['en', other]);
organizer.locale = other;
await renderLayout();
Expand Down
32 changes: 13 additions & 19 deletions src/app/(organizer)/app/(chrome)/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import '@testing-library/jest-dom/vitest';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, render, screen } from '@testing-library/react';
import { CATALOG_LOCALES } from '@/i18n/config';
import { TEST_LOCALES } from '@/i18n/testing/locales';
import { ship, shipOnlyEnglish } from '@/i18n/testing/ship';
import { ok } from '@/lib/result';
import { INSTANCE_NAME } from '@/lib/site-config';
Expand Down Expand Up @@ -40,9 +40,6 @@ vi.mock('@/i18n/server', async () => ({

const { default: DashboardPage, generateMetadata } = await import('./page');

/** Every language with a catalog besides English, each tried in turn. */
const OTHER_LANGUAGES = CATALOG_LOCALES.filter((locale) => locale !== 'en');

afterEach(() => {
cleanup();
request.session.defaultWorkspaceId = 'ws_1';
Expand Down Expand Up @@ -135,7 +132,7 @@ describe('Your signups', () => {

// A title is in its signup's language: shown only once that language has
// shipped to participants, as the signup's own pages show it.
it.each(OTHER_LANGUAGES)('marks the title of a signup in %s', async (other) => {
it.each(TEST_LOCALES)('marks the title of a signup in %s', async (other) => {
ship('participant', ['en', other]);
request.rows = [
{ id: 'sig_1', title: 'Bake Sale', slug: 'bake-sale', status: 'open', locale: other },
Expand All @@ -148,19 +145,16 @@ describe('Your signups', () => {
expect(screen.getByText('/s/bake-sale').closest('[lang]')).toBeNull();
});

it.each(OTHER_LANGUAGES)(
'leaves a signup stored in %s unmarked until it ships',
async (other) => {
shipOnlyEnglish();
request.rows = [
{ id: 'sig_1', title: 'Bake Sale', slug: 'bake-sale', status: 'open', locale: other },
];
await renderPage();
expect(screen.getByText('Bake Sale')).not.toHaveAttribute('lang');
},
);
it.each(TEST_LOCALES)('leaves a signup stored in %s unmarked until it ships', async (other) => {
shipOnlyEnglish();
request.rows = [
{ id: 'sig_1', title: 'Bake Sale', slug: 'bake-sale', status: 'open', locale: other },
];
await renderPage();
expect(screen.getByText('Bake Sale')).not.toHaveAttribute('lang');
});

it.each(OTHER_LANGUAGES)(
it.each(TEST_LOCALES)(
'marks English titles for an organizer whose screens are in %s, and not their own language’s',
async (other) => {
ship('organizer', ['en', other]);
Expand All @@ -176,7 +170,7 @@ describe('Your signups', () => {
},
);

it.each(OTHER_LANGUAGES)('is in the organizer’s language, %s', async (other) => {
it.each(TEST_LOCALES)('is in the organizer’s language, %s', async (other) => {
ship('organizer', ['en', other]);
request.session.locale = other;
request.rows = [{ id: 'sig_2', title: 'Picnic', slug: 'picnic', status: 'draft' }];
Expand All @@ -189,7 +183,7 @@ describe('Your signups', () => {
expect(await generateMetadata()).toEqual({ title: ask('title') });
});

it.each(OTHER_LANGUAGES)('pages in the organizer’s language, %s', async (other) => {
it.each(TEST_LOCALES)('pages in the organizer’s language, %s', async (other) => {
ship('organizer', ['en', other]);
request.session.locale = other;
onAMiddlePage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import '@testing-library/jest-dom/vitest';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, render, screen, within } from '@testing-library/react';
import { CATALOG_LOCALES } from '@/i18n/config';
import { TEST_LOCALES } from '@/i18n/testing/locales';
import { ship } from '@/i18n/testing/ship';
import { getTranslator } from '@/i18n/translator';
import type { ConnectedApp } from '@/oauth/grants';
Expand Down Expand Up @@ -59,9 +59,6 @@ vi.mock('@/i18n/server', async () => {

const { default: ConnectedAppsPage, generateMetadata } = await import('./page');

/** Every language with a catalog besides English, each tried in turn. */
const OTHER_LANGUAGES = CATALOG_LOCALES.filter((locale) => locale !== 'en');

/** Noon on a day, in the zone the tests run in, which is the zone dates are written in. */
const noon = (year: number, month: number, day: number) => new Date(year, month - 1, day, 12);

Expand Down Expand Up @@ -169,7 +166,7 @@ describe('Connected apps', () => {
expect(screen.getByRole('alert')).toHaveTextContent(/^Couldn't disconnect\. Try again\.$/);
});

it.each(OTHER_LANGUAGES)(
it.each(TEST_LOCALES)(
'says a disconnect was refused in the organizer’s language, %s',
async (other) => {
ship('organizer', ['en', other]);
Expand All @@ -187,7 +184,7 @@ describe('Connected apps', () => {
},
);

it.each(OTHER_LANGUAGES)('is in the organizer’s language, %s', async (other) => {
it.each(TEST_LOCALES)('is in the organizer’s language, %s', async (other) => {
ship('organizer', ['en', other]);
request.session.locale = other;
request.apps = [app()];
Expand All @@ -213,7 +210,7 @@ describe('Connected apps', () => {
expect(screen.getByText(ask('empty.body'))).toBeInTheDocument();
});

it.each(OTHER_LANGUAGES)('writes the dates in the organizer’s language, %s', async (other) => {
it.each(TEST_LOCALES)('writes the dates in the organizer’s language, %s', async (other) => {
ship('organizer', ['en', other]);
request.session.locale = other;
request.realText = true;
Expand Down
45 changes: 20 additions & 25 deletions src/app/(organizer)/app/(chrome)/settings/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
languageName,
languageNameInSentence,
} from '@/i18n/config';
import { TEST_LOCALES } from '@/i18n/testing/locales';
import type { Namespace } from '@/i18n/translator';
import { ship, shipOnlyEnglish } from '@/i18n/testing/ship';

Expand Down Expand Up @@ -72,9 +73,6 @@ vi.mock('@/services/signups', () => ({ openSignupsToSwitch }));

const { default: SettingsPage, generateMetadata } = await import('./page');

/** Every language with a catalog besides English, each tried in turn. */
const OTHER_LANGUAGES = CATALOG_LOCALES.filter((locale) => locale !== 'en');

async function renderPage(searchParams: Record<string, string> = {}) {
return render(await SettingsPage({ searchParams: Promise.resolve(searchParams) }));
}
Expand Down Expand Up @@ -105,7 +103,7 @@ describe('Account Settings', () => {
expect(await generateMetadata()).toEqual({ title: 'Settings' });
});

it.each(OTHER_LANGUAGES)('is in the organizer’s language, %s', async (other) => {
it.each(TEST_LOCALES)('is in the organizer’s language, %s', async (other) => {
ship('organizer', ['en', other]);
request.saved = other;
await renderPage();
Expand Down Expand Up @@ -199,7 +197,7 @@ describe('Account Settings: Language', () => {
expect(screen.queryByRole('status')).not.toBeInTheDocument();
});

it.each(OTHER_LANGUAGES)('is in the organizer’s language, %s', async (other) => {
it.each(TEST_LOCALES)('is in the organizer’s language, %s', async (other) => {
ship('participant', ['en', other]);
ship('organizer', ['en', other]);
request.saved = other;
Expand Down Expand Up @@ -300,28 +298,25 @@ describe('Account Settings: switching the open signups', () => {
expect(switchButton()).not.toHaveClass('border-surface-sunk');
});

it.each(OTHER_LANGUAGES)(
'writes a large count as before, without grouping (%s)',
async (other) => {
ship('participant', ['en', other]);
request.saved = other;
const name = languageName(other);
toSwitch(1234);
await renderPage();
expect(screen.getByText(/of your signups/)).toHaveTextContent(
`1234 of your signups are open and aren't in ${name} yet.`,
);
cleanup();
it.each(TEST_LOCALES)('writes a large count as before, without grouping (%s)', async (other) => {
ship('participant', ['en', other]);
request.saved = other;
const name = languageName(other);
toSwitch(1234);
await renderPage();
expect(screen.getByText(/of your signups/)).toHaveTextContent(
`1234 of your signups are open and aren't in ${name} yet.`,
);
cleanup();

toSwitch(0, 1234);
await renderPage({ switched: '1' });
expect(screen.getByRole('status')).toHaveTextContent(
`Saved. 1234 of your signups are open, and they're all in ${name} now.`,
);
},
);
toSwitch(0, 1234);
await renderPage({ switched: '1' });
expect(screen.getByRole('status')).toHaveTextContent(
`Saved. 1234 of your signups are open, and they're all in ${name} now.`,
);
});

it.each(OTHER_LANGUAGES)('is in the organizer’s language, %s', async (other) => {
it.each(TEST_LOCALES)('is in the organizer’s language, %s', async (other) => {
ship('participant', ['en', other]);
ship('organizer', ['en', other]);
request.saved = other;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { organizers } from '@/db/schema/organizers';
import { signups } from '@/db/schema/signups';
import { slots as slotsTable } from '@/db/schema/slots';
import { workspaces } from '@/db/schema/workspaces';
import { CATALOG_LOCALES } from '@/i18n/config';
import { TEST_LOCALES } from '@/i18n/testing/locales';
import { ship } from '@/i18n/testing/ship';
import { makeId } from '@/lib/ids';
import { getTestTranslator } from '@/i18n/testing/translator';
Expand Down Expand Up @@ -849,7 +849,7 @@ describe('removeCommitmentAction (db)', () => {
expect(revalidatePath).not.toHaveBeenCalled();
});

it.each(CATALOG_LOCALES.filter((locale) => locale !== 'en'))(
it.each(TEST_LOCALES)(
'words each refusal in the language stored on the organizer’s account, %s',
async (locale) => {
ship('organizer', ['en', locale]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, render, screen, within } from '@testing-library/react';

import { CATALOG_LOCALES } from '@/i18n/config';
import { TEST_LOCALES } from '@/i18n/testing/locales';
import { ship } from '@/i18n/testing/ship';
import { formatSlotDate, formatSlotTime } from '@/lib/slot-label';

Expand Down Expand Up @@ -92,9 +93,6 @@ async function renderTab() {
return render(await ResponsesTab({ params: Promise.resolve({ id: 'sig_1' }) }));
}

/** Every language with a catalog but English. */
const OTHER_LOCALES = CATALOG_LOCALES.filter((locale) => locale !== 'en');

/**
* Pat holds one spot, Sam two on the slot with nothing written in it, Kim one
* on a slot that's gone. Ann was taken off, Bo cancelled.
Expand Down Expand Up @@ -255,7 +253,7 @@ describe('Responses tab: its words', () => {
});
});

it.each(OTHER_LOCALES)('is in the organizer’s language, %s', async (other) => {
it.each(TEST_LOCALES)('is in the organizer’s language, %s', async (other) => {
ship('organizer', ['en', other]);
stored.organizerLocale = other;
const say = (key: string) => `organizer.responses.${key} in ${other}`;
Expand Down Expand Up @@ -373,7 +371,7 @@ describe('Responses tab: nobody signed up', () => {
expect(screen.queryByRole('link')).not.toBeInTheDocument();
});

it.each(OTHER_LOCALES)('says so in the organizer’s language, %s', async (other) => {
it.each(TEST_LOCALES)('says so in the organizer’s language, %s', async (other) => {
ship('organizer', ['en', other]);
stored.organizerLocale = other;
for (const status of Object.keys(english)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { CATALOG_LOCALES } from '@/i18n/config';
import { TEST_LOCALES } from '@/i18n/testing/locales';
import { getStandInTranslator, getTestTranslator } from '@/i18n/testing/translator';
import { removeRefusal } from './remove-refusal';

Expand All @@ -23,20 +23,17 @@ describe('removeRefusal', () => {
expect(removeRefusal(code, english)).toBe("Couldn't remove them. Try again.");
});

it.each(CATALOG_LOCALES.filter((locale) => locale !== 'en'))(
'takes each line from the catalog in %s',
(locale) => {
const t = {
responses: getStandInTranslator(locale, 'organizer.responses'),
errors: getStandInTranslator(locale, 'organizer.errors'),
};
expect(removeRefusal('not_found', t)).toBe(
`organizer.responses.remove.refusal.notFound in ${locale}`,
);
expect(removeRefusal('forbidden', t)).toBe(`organizer.errors.code.forbidden in ${locale}`);
expect(removeRefusal('internal', t)).toBe(
`organizer.responses.remove.refusal.failed in ${locale}`,
);
},
);
it.each(TEST_LOCALES)('takes each line from the catalog in %s', (locale) => {
const t = {
responses: getStandInTranslator(locale, 'organizer.responses'),
errors: getStandInTranslator(locale, 'organizer.errors'),
};
expect(removeRefusal('not_found', t)).toBe(
`organizer.responses.remove.refusal.notFound in ${locale}`,
);
expect(removeRefusal('forbidden', t)).toBe(`organizer.errors.code.forbidden in ${locale}`);
expect(removeRefusal('internal', t)).toBe(
`organizer.responses.remove.refusal.failed in ${locale}`,
);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { CATALOG_LOCALES } from '@/i18n/config';
import { TEST_LOCALES } from '@/i18n/testing/locales';
import { getStandInTranslator, getTestTranslator } from '@/i18n/testing/translator';
import { noResponsesLine, summarizeResponses } from './responses-summary';

Expand Down Expand Up @@ -88,10 +88,7 @@ describe('noResponsesLine', () => {
});
});

/** Every language with a catalog but English. */
const OTHER_LOCALES = CATALOG_LOCALES.filter((locale) => locale !== 'en');

describe.each(OTHER_LOCALES)('in %s', (locale) => {
describe.each(TEST_LOCALES)('in %s', (locale) => {
const t = getStandInTranslator(locale, 'organizer.responses');
const say = (key: string) => `organizer.responses.${key} in ${locale}`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { cleanup, fireEvent, render, screen, within } from '@testing-library/react';

import { CATALOG_LOCALES, languageName } from '@/i18n/config';
import { OTHER_LOCALE } from '@/i18n/testing/locales';
import { OTHER_LOCALE, TEST_LOCALES } from '@/i18n/testing/locales';
import { ship, shipOnlyEnglish } from '@/i18n/testing/ship';

// Unit tests have no server environment. The instance sets no language
Expand Down Expand Up @@ -64,9 +64,6 @@ async function renderTab(searchParams: { error?: string; saved?: string } = {})

const languageSection = () => screen.queryByRole('region', { name: 'Language' });

/** Every language with a catalog but English. */
const OTHER_LOCALES = CATALOG_LOCALES.filter((locale) => locale !== 'en');

afterEach(() => {
cleanup();
stored.settings = {};
Expand Down Expand Up @@ -98,7 +95,7 @@ describe('Settings tab: a refused save or delete', () => {
}
});

it.each(OTHER_LOCALES)('is in the organizer’s language, %s', async (other) => {
it.each(TEST_LOCALES)('is in the organizer’s language, %s', async (other) => {
ship('organizer', ['en', other]);
stored.organizerLocale = other;
await renderTab({ error: 'forbidden' });
Expand Down Expand Up @@ -277,7 +274,7 @@ describe('Settings tab: Reminders', () => {
expect(remindersCard().queryByRole('button')).not.toBeInTheDocument();
});

it.each(OTHER_LOCALES)('is in the organizer’s language, %s', async (other) => {
it.each(TEST_LOCALES)('is in the organizer’s language, %s', async (other) => {
ship('organizer', ['en', other]);
stored.organizerLocale = other;
stored.fields = [what, shift];
Expand Down Expand Up @@ -361,7 +358,7 @@ describe('Settings tab: its words', () => {
await expectTab((key) => english[key] ?? `no English for ${key}`, 'Saved');
});

it.each(OTHER_LOCALES)('is in the organizer’s language, %s', async (other) => {
it.each(TEST_LOCALES)('is in the organizer’s language, %s', async (other) => {
ship('organizer', ['en', other]);
stored.organizerLocale = other;
await expectTab(
Expand Down
Loading