// Jasmine spec for my-sea-seats.js — the one-shot "seated" glow module
// (Phase B of the my-sea invite/voice sprint). Verifies the localStorage-
// gated first-view behaviour + the timed flare-class removal.
describe('my-sea-seats one-shot seated glow', function () {
    var seat;

    beforeEach(function () {
        window.localStorage.clear();
        seat = document.createElement('div');
        seat.className = 'table-seat seated';
        document.body.appendChild(seat);
    });

    afterEach(function () {
        if (seat && seat.parentNode) seat.parentNode.removeChild(seat);
        window.localStorage.clear();
    });

    it('exposes playSeatGlow globally', function () {
        expect(typeof window.playSeatGlow).toBe('function');
    });

    it('adds the seat-just-seated flare class', function () {
        window.playSeatGlow(seat);
        expect(seat.classList.contains('seat-just-seated')).toBe(true);
    });

    it('marks a tokened seat seen in localStorage', function () {
        seat.setAttribute('data-seat-token', 'visit-42');
        window.playSeatGlow(seat);
        expect(window.localStorage.getItem('mysea-seat-seen:visit-42')).toBe('1');
    });

    it('does not replay the flare for an already-seen token', function () {
        seat.setAttribute('data-seat-token', 'visit-42');
        window.localStorage.setItem('mysea-seat-seen:visit-42', '1');
        window.playSeatGlow(seat);
        expect(seat.classList.contains('seat-just-seated')).toBe(false);
    });

    it('always animates a tokenless seat (no persistence)', function () {
        window.playSeatGlow(seat);
        expect(seat.classList.contains('seat-just-seated')).toBe(true);
    });

    it('removes the flare class after the ~1.5s glow window', function () {
        jasmine.clock().install();
        window.playSeatGlow(seat);
        expect(seat.classList.contains('seat-just-seated')).toBe(true);
        jasmine.clock().tick(1600);
        expect(seat.classList.contains('seat-just-seated')).toBe(false);
        jasmine.clock().uninstall();
    });
});
