import type { AnalysisResult } from '../analysis/analyzer'; /** * The colour of a test's icon, the same on the score card and in the * analysis: passed green, failed red, amber for a failed test that counts * for nothing (advice) or one that earned part of its points, and grey for * a test that is shown for comparison only, whatever it found. * * @param {AnalysisResult} result - One test. * @returns {string} The icon's background and text classes. */ export const resultTone = (result: AnalysisResult): string => { if (result.rankMathOnly) { return 'bg-muted text-muted-foreground'; } if (result.partial) { return 'bg-amber-500/15 text-amber-600 dark:text-amber-400'; } if (result.passed) { return 'bg-emerald-500/15 text-emerald-600 dark:text-emerald-400'; } return result.max === 0 ? 'bg-amber-500/15 text-amber-600 dark:text-amber-400' : 'bg-red-500/15 text-red-600 dark:text-red-400'; }; /** * Whether a test is something to do: failed, or passed for part of its * points, and either weighed or advice. * * @param {AnalysisResult} result - One test. * @returns {boolean} True when it belongs in the list of what to fix. */ export const isToDo = (result: AnalysisResult): boolean => (!result.passed || Boolean(result.partial)) && !result.rankMathOnly; /** * Whether a test costs points outright: weighed and failed, as opposed to * advice or a test that earned part of its points. * * @param {AnalysisResult} result - One test. * @returns {boolean} True when it belongs under "to fix". */ export const isToFix = (result: AnalysisResult): boolean => !result.passed && result.max > 0 && !result.rankMathOnly; /** * What the tests that are not fully passed add up to, in the words the * header's count uses: the ones that cost points outright are "to fix", * the ones that earned part of them and the advice are "to improve". * * @param {AnalysisResult[]} failing - The tests not fully passed. * @returns {string} e.g. "2 to fix, 6 to improve". */ export const todoSummary = (failing: AnalysisResult[]): string => { const toFix = failing.filter(isToFix).length; const toImprove = failing.length - toFix; return [ toFix > 0 ? `${toFix} to fix` : '', toImprove > 0 ? `${toImprove} to improve` : '', ] .filter(Boolean) .join(', '); };