import { describe, expect, it } from 'vitest';
import { pageNumbers } from '../../views/Posts/PostsListView.js';
import { renderSnippet } from '../../views/Posts/NewPostTypeInstructions.js';
import { POST_TYPE_PRESETS } from '../../views/Posts/post-type-presets.js';
import { POST_TYPE_ICONS } from '../../components/posts/icons.js';
/**
 * `pageNumbers` is the only pure helper exported from PostsListView.
 * It drives the pagination footer's sliding window so the bug-prone
 * cases (single page, exact-window boundary, ellipsis on either end)
 * have explicit coverage.
 */
describe('pageNumbers', () => {
    it('returns 1..N when total ≤ 7', () => {
        expect(pageNumbers(1, 1)).toEqual([1]);
        expect(pageNumbers(3, 5)).toEqual([1, 2, 3, 4, 5]);
        expect(pageNumbers(4, 7)).toEqual([1, 2, 3, 4, 5, 6, 7]);
    });
    it('shows leading and trailing ellipses for a mid-range page', () => {
        expect(pageNumbers(50, 100)).toEqual([1, '…', 49, 50, 51, '…', 100]);
    });
    it('hides leading ellipsis when current is near the start', () => {
        expect(pageNumbers(2, 20)).toEqual([1, 2, 3, '…', 20]);
    });
    it('hides trailing ellipsis when current is near the end', () => {
        expect(pageNumbers(19, 20)).toEqual([1, '…', 18, 19, 20]);
    });
});
describe('renderSnippet', () => {
    const base = {
        slug: 'reviews',
        singular: 'Review',
        plural: 'Reviews',
        color: 'purple',
        icon: 'file-text',
        description: 'Reviews',
    };
    it('emits a valid-looking collection entry with the slug, labels, and admin metadata', () => {
        const out = renderSnippet({ ...base, extraFields: [] });
        expect(out).toContain("'reviews': {");
        expect(out).toContain("slug: 'reviews'");
        expect(out).toContain("singular: 'Review'");
        expect(out).toContain("type: 'post'");
        expect(out).toContain("group: 'Posts'");
        expect(out).toContain("color: 'purple'");
        // No type-specific block when there are no extra fields.
        expect(out).not.toContain('type-specific fields');
    });
    it('injects preset extra fields after the shared base fields', () => {
        const out = renderSnippet({
            ...base,
            extraFields: ["client: { type: 'text', label: 'Client Name' },"],
        });
        expect(out).toContain('// type-specific fields');
        expect(out).toContain("client: { type: 'text', label: 'Client Name' },");
        // Base fields are still present alongside the injected ones.
        expect(out).toContain("title: { type: 'text', label: 'Title', required: true },");
        expect(out).toContain("metaDescription: { type: 'text', label: 'SEO Description' },");
    });
    it('escapes single quotes in free-text fields so the snippet stays valid', () => {
        const out = renderSnippet({
            ...base,
            description: "Editors' picks",
            extraFields: [],
        });
        expect(out).toContain("description: 'Editors\\' picks'");
    });
    it('falls back to a placeholder slug when slug is empty', () => {
        const out = renderSnippet({ ...base, slug: '', extraFields: [] });
        expect(out).toContain("'new-type': {");
    });
});
describe('POST_TYPE_PRESETS', () => {
    it('has unique keys and slugs', () => {
        const keys = POST_TYPE_PRESETS.map((p) => p.key);
        const slugs = POST_TYPE_PRESETS.map((p) => p.slug);
        expect(new Set(keys).size).toBe(keys.length);
        expect(new Set(slugs).size).toBe(slugs.length);
    });
    it('only references icons that exist in the shared icon registry', () => {
        for (const preset of POST_TYPE_PRESETS) {
            expect(POST_TYPE_ICONS[preset.icon]).toBeDefined();
        }
    });
    it('uses only palette colors the badge component understands', () => {
        const allowed = new Set(['purple', 'green', 'orange', 'blue', 'red', 'pink']);
        for (const preset of POST_TYPE_PRESETS) {
            expect(allowed.has(preset.color)).toBe(true);
        }
    });
    it('every preset extra field line is a complete key: { … }, definition', () => {
        for (const preset of POST_TYPE_PRESETS) {
            for (const line of preset.extraFields) {
                expect(line).toMatch(/^[a-zA-Z][\w]*: \{.*\},$/);
            }
        }
    });
});
//# sourceMappingURL=posts-list-view.test.js.map