import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render } from '@testing-library/svelte';
import Carousel from './Carousel.svelte';
HTMLElement.prototype.scrollIntoView = vi.fn();
class MockIntersectionObserver {
    cb;
    constructor(cb) {
        this.cb = cb;
    }
    observe() { }
    disconnect() { }
}
vi.stubGlobal('IntersectionObserver', MockIntersectionObserver);
describe('m-carousel component', () => {
    beforeEach(() => {
        vi.clearAllMocks();
    });
    it('sets accessibility attributes on root container', () => {
        const { container } = render(Carousel);
        const root = container.querySelector('.mc-carousel');
        expect(root.getAttribute('role')).toBe('group');
        expect(root.getAttribute('aria-roledescription')).toBe('carousel');
        expect(root.getAttribute('aria-labelledby')).toBe('mc-carousel__title');
    });
    it('disables previous button when first item is active', () => {
        const { getByLabelText } = render(Carousel, {
            slots: {
                default: `
          <div>Item 1</div>
          <div>Item 2</div>
        `,
            },
        });
        const prevButton = getByLabelText('previous');
        expect(prevButton.disabled).toBe(true);
    });
    it('enables next button when not at last item', () => {
        const { getByLabelText } = render(Carousel, {
            slots: {
                default: `
          <div>Item 1</div>
          <div>Item 2</div>
        `,
            },
        });
        const nextButton = getByLabelText('next');
        expect(nextButton.disabled).toBe(false);
    });
});
