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

afterEach(() => {
	cleanup();
	localStorage.removeItem('theme');
});

describe('ThemeToggle — label derivation (light mode)', () => {
	beforeEach(() => {
		localStorage.setItem('theme', 'light');
	});

	it('aria-label invites switching to dark mode when theme is light', async () => {
		render(ThemeToggle);
		const btn = await page.getByRole('button').element();
		expect(btn.getAttribute('aria-label')).toBe('Zu dunklem Design wechseln');
	});

	it('title equals aria-label in light mode', async () => {
		render(ThemeToggle);
		const btn = await page.getByRole('button').element();
		expect(btn.getAttribute('title')).toBe(btn.getAttribute('aria-label'));
	});
});

describe('ThemeToggle — label derivation (dark mode)', () => {
	beforeEach(() => {
		localStorage.setItem('theme', 'dark');
	});

	it('aria-label invites switching to light mode when theme is dark', async () => {
		render(ThemeToggle);
		const btn = await page.getByRole('button').element();
		expect(btn.getAttribute('aria-label')).toBe('Zu hellem Design wechseln');
	});

	it('title equals aria-label in dark mode', async () => {
		render(ThemeToggle);
		const btn = await page.getByRole('button').element();
		expect(btn.getAttribute('title')).toBe(btn.getAttribute('aria-label'));
	});
});
