import { expect, test } from '@playwright/test'
import {
  createAuthenticatedApiContext,
  createTroubleshootingTree,
  disposeApiContext,
} from './helpers/api'

test.describe('flow library smoke tests', () => {
  test('can search for an API-created troubleshooting flow', async ({ page }) => {
    const api = await createAuthenticatedApiContext()
    const tree = await createTroubleshootingTree(api)

    try {
      await page.goto('/trees')

      await expect(
        page.getByRole('heading', { name: 'Flow Library' }),
      ).toBeVisible()

      await page.getByPlaceholder('Search flows...').fill(tree.name)
      await page.getByRole('button', { name: 'Search', exact: true }).click()

      await expect(page.getByText(tree.name)).toBeVisible()
    } finally {
      await disposeApiContext(api)
    }
  })
})
