import {test} from 'node:test';
import assert from 'node:assert/strict';
import {render, screen} from '@testing-library/react';
import TodoHeader from './main.jsx';
test("The heading reads Gregorio Y. Zara's Todos", () => {
render(<TodoHeader />);
const heading = screen.getByRole('heading', {level: 1}).textContent;
assert.equal(heading, "Gregorio Y. Zara's Todos", 'the heading reads ' + JSON.stringify(heading));
});
test('The picture reads src and alt from person', () => {
render(<TodoHeader />);
const img = screen.getByRole('img');
assert.equal(img.getAttribute('src'), 'gregorio-zara.jpg', 'the picture has src=' + JSON.stringify(img.getAttribute('src')));
assert.equal(img.getAttribute('alt'), 'Gregorio Y. Zara', 'the picture has alt=' + JSON.stringify(img.getAttribute('alt')));
});
test('The picture is 90px wide and high, from person.imageSize', () => {
render(<TodoHeader />);
const {width, height} = screen.getByRole('img').style;
assert.equal(width, '90px', 'the picture has width ' + JSON.stringify(width));
assert.equal(height, '90px', 'the picture has height ' + JSON.stringify(height));
});
test('The header uses person.theme as its style', () => {
render(<TodoHeader />);
const {backgroundColor, color} = screen.getByRole('banner').style;
assert.equal(backgroundColor, 'black', 'the header has background-color ' + JSON.stringify(backgroundColor));
assert.equal(color, 'pink', 'the header has color ' + JSON.stringify(color));
});
test('React prints no warnings', () => {
const warnings = [];
const original = console.error;
console.error = (...args) => warnings.push(args.join(' '));
try {
render(<TodoHeader />);
} finally {
console.error = original;
}
assert.deepEqual(warnings, [], 'console.error while rendering');
});