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

test.describe('Navegacion', () => {

    test.beforeEach(async ({ page }) => {
        await page.goto('/dashboard')
    })

    test('dashboard carga con saludo', async ({ page }) => {
        await expect(page.locator('h1')).toBeVisible()
    })

    test('header muestra nombre de la empresa', async ({ page }) => {
        await page.waitForLoadState('networkidle')
        await expect(page.getByText('Aduanasoft S.A. de C.V.').first())
            .toBeVisible({ timeout: 10000 })
    })

    test.describe('Menu lateral', () => {

        test('tiene enlace a Audit Logs', async ({ page }) => {
            await expect(page.getByRole('link', { name: 'Audit Logs' })).toBeVisible()
        })

        test('tiene enlace a Customs Brokers', async ({ page }) => {
            await expect(page.getByRole('link', { name: 'Customs Brokers' })).toBeVisible()
        })

        test('Fractions aparece en el menu', async ({ page }) => {
            await expect(page.getByText('Fractions').first()).toBeVisible()
        })

        test('Pedimentos aparece en el menu', async ({ page }) => {
            await expect(page.getByText('Pedimentos').first()).toBeVisible()
        })

    })

    test.describe('Modulos accesibles', () => {

        test('Audit Logs carga sin error', async ({ page }) => {
            await page.getByRole('link', { name: 'Audit Logs' }).click()
            await expect(page).toHaveURL(/audit/)
            await expect(page.locator('h1')).toBeVisible()
        })

        test('Customs Brokers carga sin error', async ({ page }) => {
            await page.getByRole('link', { name: 'Customs Brokers' }).click()
            await expect(page).toHaveURL(/customs/)
            await expect(page.locator('h1')).toBeVisible()
        })

        test('Fraction Sitar carga sin error', async ({ page }) => {
            await page.goto('/dashboard/general_catalogs/tariff-fractions/sitar')
            await expect(page).toHaveURL(/tariff-fractions/)
            await expect(page.locator('main')).toBeVisible()
        })

        test('Pedimentos carga sin error', async ({ page }) => {
            await page.goto('/dashboard/reference_data/code_pedimento_regimens')
            await expect(page).toHaveURL(/reference_data/)
            await expect(page.locator('main')).toBeVisible()
        })

    })

})