import { test, expect } from '@playwright/test';

test.describe('visual regression', () => {
    test('cookie banner is visible', async ({ page }) => {
        await page.goto('/');
        await expect(page.locator('#cookie-banner')).toBeVisible();
    });

    test('cookie banner is not visible when choices are accepted', async ({ page }) => {
        await page.goto('/');

        await page.evaluate(() => {
            localStorage.setItem('mifi-ventures-cookie-consent', 'accept');
        });

        await page.goto('/');
        await expect(page.locator('#cookie-banner')).not.toBeVisible();
    });

    test('cookie banner is not visible when choices are rejected', async ({ page }) => {
        await page.goto('/');

        await page.evaluate(() => {
            localStorage.setItem('mifi-ventures-cookie-consent', 'reject');
        });

        await page.goto('/');
        await expect(page.locator('#cookie-banner')).not.toBeVisible();
    });

    test('cookie banner is hidden when user selects accept', async ({ page }) => {
        await page.goto('/');
        await expect(page.locator('#cookie-banner')).toBeVisible();
        await page.locator('[data-consent="accept"]').click();
        await expect(page.locator('#cookie-banner')).not.toBeVisible();
        await expect(await page.evaluate(() => localStorage.getItem('mifi-ventures-cookie-consent'))).toBe('accept');
    });

    test('cookie banner is hidden when user selects reject', async ({ page }) => {
        await page.goto('/');
        await expect(page.locator('#cookie-banner')).toBeVisible();
        await page.locator('[data-consent="reject"]').click();
        await expect(page.locator('#cookie-banner')).not.toBeVisible();
        await expect(await page.evaluate(() => localStorage.getItem('mifi-ventures-cookie-consent'))).toBe('reject');
    });
});
