import { describe, expect, it } from 'vitest';
import { analyzeImageAlts, countMissingAltImages, isDecorativeImgTag } from '../../seo/alt-text.js';
describe('isDecorativeImgTag', () => {
    it('treats an explicit empty alt as decorative', () => {
        expect(isDecorativeImgTag('<img src="x.jpg" alt="">')).toBe(true);
        expect(isDecorativeImgTag('<img src="x.jpg" alt="   ">')).toBe(true);
    });
    it('treats role=presentation / none / aria-hidden as decorative when alt is absent', () => {
        expect(isDecorativeImgTag('<img src="x.jpg" role="presentation">')).toBe(true);
        expect(isDecorativeImgTag('<img src="x.jpg" role="none">')).toBe(true);
        expect(isDecorativeImgTag('<img src="x.jpg" aria-hidden="true">')).toBe(true);
    });
    it('is not decorative when it has descriptive alt', () => {
        expect(isDecorativeImgTag('<img src="x.jpg" alt="A cat" role="presentation">')).toBe(false);
        expect(isDecorativeImgTag('<img src="x.jpg" alt="A cat">')).toBe(false);
    });
    it('a bare img with no alt and no role is not decorative (it is missing)', () => {
        expect(isDecorativeImgTag('<img src="x.jpg">')).toBe(false);
    });
});
describe('analyzeImageAlts', () => {
    it('classifies images into withAlt / decorative / missing', () => {
        const html = [
            '<img src="a.jpg" alt="A photo">', // withAlt
            '<img src="b.jpg" alt="">', // decorative (intentional empty)
            '<img src="c.jpg" role="presentation">', // decorative (marked)
            '<img src="d.jpg">', // missing
        ].join('');
        const r = analyzeImageAlts(html);
        expect(r).toMatchObject({ total: 4, withAlt: 1, decorative: 2, missing: 1 });
        expect(r.altTexts).toEqual(['A photo']);
    });
    it('does not mistake hyphenated attributes for alt', () => {
        expect(analyzeImageAlts('<img src="x.jpg" data-default-alt="hi">').missing).toBe(1);
    });
    it('handles empty / non-HTML input', () => {
        expect(analyzeImageAlts('').total).toBe(0);
        expect(analyzeImageAlts(null).missing).toBe(0);
    });
});
describe('countMissingAltImages', () => {
    it('counts only non-decorative images that lack alt', () => {
        const html = '<img src="a.jpg" alt="A"><img src="b.jpg" alt=""><img src="c.jpg"><img src="d.jpg" aria-hidden="true">';
        expect(countMissingAltImages(html)).toBe(1);
    });
});
//# sourceMappingURL=alt-text.test.js.map