import { describe, it, expect, afterEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import PersonCard from './PersonCard.svelte';

afterEach(() => cleanup());

const PERSON_ID = '55555555-5555-5555-5555-555555555555';

const makePerson = (overrides = {}) => ({
	id: PERSON_ID,
	firstName: 'Karl',
	lastName: 'Raddatz',
	displayName: 'Karl Raddatz',
	personType: 'PERSON',
	...overrides
});

describe('PersonCard add-event affordance (#842)', () => {
	it('shows an add-event link pre-seeded with the person to a curator (REQ-003)', () => {
		render(PersonCard, { person: makePerson(), canWrite: true });
		const add = document.querySelector(
			'[data-testid="person-add-event"]'
		) as HTMLAnchorElement | null;
		expect(add).not.toBeNull();
		expect(add?.getAttribute('href')).toBe(`/zeitstrahl/events/new?personId=${PERSON_ID}`);
	});

	it('renders no add-event link to a reader (REQ-004)', () => {
		render(PersonCard, { person: makePerson(), canWrite: false });
		expect(document.querySelector('[data-testid="person-add-event"]')).toBeNull();
	});
});
