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

test('R14.22.1 top-bar Star this item persists for LaTeX project files', async ({
  page,
}) => {
  const workspaceName = `star-r14-22-1-${Date.now()}`;
  await createBrowserWorkspace(page, { workspaceName });

  const star = page.getByRole('button', { name: 'Star this item' });
  await expect(star).toBeVisible();
  await expect(star).toHaveAttribute('aria-pressed', 'false');
  await star.click();

  const unstar = page.getByRole('button', { name: 'Unstar this item' });
  await expect(unstar).toBeVisible();
  await expect(unstar).toHaveAttribute('aria-pressed', 'true');

  await page.reload();
  await expect(page.getByLabel('LaTeX source editor')).toBeVisible();
  await expect(page.getByRole('button', { name: 'Unstar this item' })).toHaveAttribute(
    'aria-pressed',
    'true',
  );

  await page.getByRole('button', { name: 'Unstar this item' }).click();
  await expect(page.getByRole('button', { name: 'Star this item' })).toHaveAttribute(
    'aria-pressed',
    'false',
  );
});
