import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { test } from 'node:test';
import {
findNamelessIconButtons,
listScannedFiles,
} from './check-icon-button-names.mjs';
const nameless = (file, source) =>
findNamelessIconButtons(file, source).map(({ line, icon }) => ({
line,
icon,
}));
test('reports an icon-only button on the line its tag opens', () => {
const template = [
'
',
' ',
'
',
].join('\n');
assert.deepEqual(nameless('a.html', template), [
{ line: 2, icon: 'close' },
]);
});
test('does not accept a tooltip or a title as the name', () => {
const template = [
'',
'',
'',
].join('\n');
assert.deepEqual(nameless('b.html', template), [
{ line: 1, icon: 'close' },
{ line: 4, icon: 'close' },
{ line: 7, icon: 'close' },
]);
});
test('accepts aria-label, its bindings and aria-labelledby', () => {
const template = [
'',
'',
'',
'',
'',
'',
].join('\n');
assert.deepEqual(nameless('c.html', template), []);
});
test('rejects an empty static aria-label', () => {
const template =
'';
assert.deepEqual(nameless('d.html', template), [
{ line: 1, icon: 'close' },
]);
});
test('accepts a button whose content includes text', () => {
const template = [
'',
"",
'',
'',
].join('\n');
assert.deepEqual(nameless('e.html', template), []);
});
test('ignores text and components hidden from assistive technology', () => {
const template = [
'',
'',
'',
'',
].join('\n');
assert.deepEqual(nameless('e2.html', template), [
{ line: 1, icon: 'close' },
{ line: 2, icon: 'star' },
]);
});
test('looks through control flow, wrappers and spinners', () => {
const template = [
'',
'',
'',
'',
].join('\n');
assert.deepEqual(nameless('f.html', template), [
{ line: 1, icon: 'sync' },
{ line: 8, icon: 'play_arrow / pause' },
{ line: 14, icon: 'star' },
{ line: 15, icon: '{{ icon() }}' },
]);
});
test('leaves content it cannot see into to the content', () => {
const template = [
'',
'',
'',
'',
'',
'home',
].join('\n');
assert.deepEqual(nameless('g.html', template), []);
});
test('finds buttons nested in other elements and blocks', () => {
const template = [
'@for (row of rows; track row.id) {',
'