import { jsx as _jsx } from "react/jsx-runtime";
// @vitest-environment happy-dom
import { describe, expect, it, vi } from 'vitest';
import { fireEvent, render, screen } from '@testing-library/react';
import { EditorTopBar } from '../../views/page-editor/EditorTopBar.js';
const baseProps = {
    title: 'About',
    status: 'DRAFT',
    dirty: false,
    saveState: 'idle',
    publishing: false,
    canEdit: true,
    canPublish: true,
    viewport: '1080p',
    onViewport: vi.fn(),
    onBack: vi.fn(),
    onPreview: vi.fn(),
    onOpenSettings: vi.fn(),
    onSaveDraft: vi.fn(),
    onPublish: vi.fn(),
};
describe('EditorTopBar publish gating', () => {
    it('disables Publish when publishReady is false and shows the blocking reason', () => {
        render(_jsx(EditorTopBar, { ...baseProps, publishReady: false, publishDisabledReason: "Add at least one visible section before publishing." }));
        const btn = screen.getByRole('button', { name: 'Publish' });
        expect(btn.disabled).toBe(true);
        expect(btn.getAttribute('title')).toBe('Add at least one visible section before publishing.');
    });
    it('enables Publish when the user can publish and the document is ready', () => {
        render(_jsx(EditorTopBar, { ...baseProps, publishReady: true }));
        expect(screen.getByRole('button', { name: 'Publish' }).disabled).toBe(false);
    });
    it('stays disabled without publish permission even when publishReady', () => {
        render(_jsx(EditorTopBar, { ...baseProps, canPublish: false, publishReady: true, publishDisabledReason: "Should not show for role block" }));
        const btn = screen.getByRole('button', { name: 'Publish' });
        expect(btn.disabled).toBe(true);
        expect(btn.getAttribute('title')).toBe('You do not have permission to publish');
    });
    it('calls onPublish when enabled and clicked', () => {
        const onPublish = vi.fn();
        render(_jsx(EditorTopBar, { ...baseProps, publishReady: true, onPublish: onPublish }));
        fireEvent.click(screen.getByRole('button', { name: 'Publish' }));
        expect(onPublish).toHaveBeenCalledOnce();
    });
    it('shows Schedule when onSchedule is provided and calls it when ready', () => {
        const onSchedule = vi.fn();
        render(_jsx(EditorTopBar, { ...baseProps, publishReady: true, scheduleReady: true, onSchedule: onSchedule, scheduledAt: "2026-07-11T16:00:00.000Z" }));
        const btn = screen.getByRole('button', { name: 'Reschedule publish' });
        expect(btn.disabled).toBe(false);
        fireEvent.click(btn);
        expect(onSchedule).toHaveBeenCalledOnce();
    });
    it('disables Schedule when scheduleReady is false', () => {
        render(_jsx(EditorTopBar, { ...baseProps, publishReady: true, scheduleReady: false, onSchedule: vi.fn() }));
        expect(screen.getByRole('button', { name: 'Schedule publish' }).disabled).toBe(true);
    });
});
//# sourceMappingURL=editor-top-bar.render.test.js.map