/* eslint-env jest */
import { act } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import type { AnalysisResult } from '../../analysis/analyzer';
import { AnalysisList } from '../AnalysisList';
(
globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }
).IS_REACT_ACT_ENVIRONMENT = true;
let root: Root;
let host: HTMLDivElement;
beforeEach(() => {
host = document.createElement('div');
document.body.appendChild(host);
root = createRoot(host);
});
afterEach(() => {
act(() => root.unmount());
host.remove();
});
const test = (
id: string,
max: number,
passed: boolean,
rankMathOnly = false
): AnalysisResult => ({
id,
group: 'title',
max,
score: passed ? max : 0,
passed,
message: id,
fix: rankMathOnly ? 'The Recomaze rules do not ask for it.' : '',
rankMathOnly,
});
const badge = (): string =>
host.querySelector('button[aria-expanded] span:last-child')?.textContent ??
'';
it('counts what is left to do, not the Rank Math comparisons', () => {
act(() => {
root.render(
);
});
expect(badge()).toBe('1 to fix');
// The failing group opens, and a comparison says what it found without a cross.
const rows = Array.from(host.querySelectorAll('li'));
expect(rows).toHaveLength(4);
expect(rows[1].textContent).toContain(
'The Recomaze rules do not ask for it.'
);
expect(rows[1].querySelector('.lucide-x')).toBeNull();
expect(rows[3].querySelector('.lucide-x')).not.toBeNull();
});
it('is all good when only comparisons fail', () => {
act(() => {
root.render(
);
});
expect(badge()).toBe('All good');
expect(host.querySelector('li')).toBeNull();
});