Files
immich-folio/app/admin/__tests__/NewPageDialog.test.tsx
Ralksta ad8b09700b release: v0.19.0
Release v0.19.0. See the `## [0.19.0] — 2026-09-29` section of
[CHANGELOG.md](https://github.com/ralksta/immich-folio/blob/dev/CHANGELOG.md)
for the full list.

Highlights: client proofing links (#683), custom content pages (#738),
asset picker search (#740), concurrent-edit detection (#742), env-locked
settings (#739), an accessibility baseline (#741), three security fixes
with advisories (#737, #755, #759), and a pre-release quality pass
(#780–#797).

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: ralksta <ralksta@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Ralf <rohlenbo79@gmail.com>
Co-authored-by: Paul Thies <110185070+ImScheinox@users.noreply.github.com>
Co-authored-by: lancetm714 <108419425+lancetm714@users.noreply.github.com>
Co-authored-by: Lance Martin <lancetaylor95@gmail.com>
2026-09-29 22:50:30 +02:00

58 lines
2.1 KiB
TypeScript

// @vitest-environment jsdom
import { describe, it, expect, afterEach, vi } from 'vitest';
import { render, screen, cleanup, fireEvent } from '@testing-library/react';
import NewPageDialog from '../components/page-builder/NewPageDialog';
afterEach(cleanup);
const taken = { subpages: [], albums: [], journal: [] };
function setup() {
const onCreate = vi.fn();
render(
<NewPageDialog
taken={taken}
existingPageSlugs={[]}
creating={false}
onCreate={onCreate}
onClose={() => {}}
/>,
);
return { onCreate, slug: screen.getByLabelText('URL') as HTMLInputElement };
}
/** Type one key at a time into a controlled input, as a person does. */
function typeKeys(input: HTMLInputElement, text: string) {
for (const ch of text) fireEvent.change(input, { target: { value: input.value + ch } });
}
describe('NewPageDialog slug field', () => {
it('takes a hyphen typed between two words', () => {
const { slug, onCreate } = setup();
fireEvent.change(screen.getByLabelText('Title'), { target: { value: 'About' } });
// Select all and retype: the first key replaces the derived slug.
fireEvent.change(slug, { target: { value: 'a' } });
typeKeys(slug, 'bout-us');
expect(slug.value).toBe('about-us');
fireEvent.click(screen.getByRole('button', { name: 'Create page' }));
expect(onCreate).toHaveBeenCalledWith(expect.objectContaining({ slug: 'about-us' }));
});
it('creates the finished slug when the field ends in a hyphen', () => {
const { slug, onCreate } = setup();
fireEvent.change(screen.getByLabelText('Title'), { target: { value: 'Pricing' } });
typeKeys(slug, '-');
expect(slug.value).toBe('pricing-');
fireEvent.click(screen.getByRole('button', { name: 'Create page' }));
expect(onCreate).toHaveBeenCalledWith(expect.objectContaining({ slug: 'pricing' }));
});
it('derives a readable slug from a German title', () => {
const { slug } = setup();
fireEvent.change(screen.getByLabelText('Title'), { target: { value: 'Preise für Paare' } });
expect(slug.value).toBe('preise-fur-paare');
});
});