import { test, expect } from '@playwright/test';
import { BASE_URL, USER, loginAs, createYoutubeVideoEvent } from '../helpers';

// The navbar "← Back to Game" link only points back to the Live Racing page, so
// it is hidden on the game itself - like every other game page. History and
// Results still show it as the way back to the game.
test.describe('Live Racing — no Back to Game on the game page', () => {
    test.setTimeout(120_000);

    test('hidden on /play/live-racing and the event page, still shown on Bet History', async ({ page }, testInfo) => {
        const eventId = await createYoutubeVideoEvent(page, 'LRNoBack');
        await loginAs(page, USER.mobile, USER.password);
        const backLink = page.locator('[data-testid="nav-link-back-to-game"]');

        await page.goto(`${BASE_URL}/play/live-racing`);
        await expect(page.locator('[data-testid="navbar-user-menu"]')).toBeVisible();
        await expect(backLink).toHaveCount(0);
        await page.screenshot({ path: testInfo.outputPath('lr-no-back-to-game.png') });

        await page.goto(`${BASE_URL}/play/live-racing/${eventId}`);
        await expect(page.locator('[data-testid="navbar-user-menu"]')).toBeVisible();
        await expect(backLink).toHaveCount(0);
        await page.screenshot({ path: testInfo.outputPath('lr-event-no-back-to-game.png') });

        await page.goto(`${BASE_URL}/play/live-racing/history`);
        await expect(backLink).toBeVisible();
        await expect(backLink).toHaveAttribute('href', '/play/live-racing');
        await page.screenshot({ path: testInfo.outputPath('lr-history-back-to-game.png') });
    });
});
