import {test} from 'node:test';
import assert from 'node:assert/strict';
import {loadPage} from './learnrun.js';
const buttons = (page) => [...page.document.querySelectorAll('#thumbs li > button')];
const images = (page) => [...page.document.querySelectorAll('#thumbs li > button > img')];
test('Jedes Foto bekommt einen Vorschau-Button', async () => {
const page = await loadPage();
const indexes = buttons(page).map((b) => b.dataset.index);
assert.deepEqual(indexes, ['0', '1', '2'], 'die Vorschau-Buttons haben die data-index-Werte ' + JSON.stringify(indexes));
const types = buttons(page).map((b) => b.getAttribute('type'));
assert.deepEqual(types, ['button', 'button', 'button'], 'die Vorschau-Buttons haben die Typen ' + JSON.stringify(types));
});
test('Jedes Vorschaubild zeigt sein Foto mit alt-Text', async () => {
const page = await loadPage();
const alts = images(page).map((img) => img.getAttribute('alt'));
assert.deepEqual(
alts,
['A red fox in the snow', 'An owl on a branch', 'A heron by the river'],
'die alt-Texte der Vorschaubilder sind ' + JSON.stringify(alts)
);
const data = images(page).map((img) => String(img.getAttribute('src')).startsWith('data:image/svg+xml,'));
assert.deepEqual(data, [true, true, true], 'eine data:-URL als src, je Vorschaubild: ' + JSON.stringify(data));
});
test('Das Hauptbild zeigt das erste Foto', async () => {
const page = await loadPage();
const main = page.document.querySelector('#main');
const same = main.getAttribute('src') === images(page)[0].getAttribute('src');
assert.equal(same, true, 'das Hauptbild hat nicht das src des ersten Vorschaubilds');
const shown = main.getAttribute('alt');
assert.equal(shown, 'A red fox in the snow', 'das Hauptbild hat den alt-Text ' + JSON.stringify(shown));
});
test('Die Bildunterschrift zeigt den alt-Text', async () => {
const page = await loadPage();
const text = page.document.querySelector('#caption').textContent;
assert.equal(text, 'A red fox in the snow', 'die Bildunterschrift zeigt ' + JSON.stringify(text));
});
test('Nur das erste Vorschaubild ist als aktuell markiert', async () => {
const page = await loadPage();
const marks = buttons(page).map((b) => b.classList.contains('selected') + ' ' + b.getAttribute('aria-current'));
assert.deepEqual(marks, ['true true', 'false null', 'false null'], 'Klasse selected und aria-current je Vorschaubild: ' + JSON.stringify(marks));
});