import {test} from 'node:test';
import assert from 'node:assert/strict';
import {loadPage} from './learnrun.js';
const texts = (page, selector) => [...page.document.querySelectorAll(selector)].map((el) => el.textContent);
test('The placeholder is gone', async () => {
const page = await loadPage();
assert.equal(page.document.querySelector('#placeholder'), null, 'the placeholder is still on the page');
});
test('Only the dishes that are not sold out are shown', async () => {
const page = await loadPage();
const names = texts(page, '#menu .name');
assert.deepEqual(names, ['Soup', 'Salad'], 'the menu shows ' + JSON.stringify(names));
});
test('Each row shows its price with two decimals', async () => {
const page = await loadPage();
const prices = texts(page, '#menu .price');
assert.deepEqual(prices, ['€4.00', '€6.50'], 'the prices are ' + JSON.stringify(prices));
});
test('Every row in the menu is a copy of the template', async () => {
const page = await loadPage();
const classes = [...page.document.querySelectorAll('#menu li')].map((li) => li.className);
assert.deepEqual(classes, ['dish', 'dish'], 'the rows have the classes ' + JSON.stringify(classes));
});
test('The template itself stays empty', async () => {
const page = await loadPage();
const content = page.document.querySelector('#dish').content;
assert.equal(content.querySelector('.name').textContent, '', 'the template was filled in: copy it, then fill the copy');
});