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

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

    test.describe('Import Invoices', () => {

        test('factura TEM carga sin error', async ({ page }) => {
            await page.goto('/dashboard/invoices?operation_type=imp&invoice_type=TEM')
            await expect(page).toHaveURL(/invoices/)
            await expect(page.locator('main')).toBeVisible()
        })

        test('factura DEF carga sin error', async ({ page }) => {
            await page.goto('/dashboard/invoices?operation_type=imp&invoice_type=DEF')
            await expect(page).toHaveURL(/invoices/)
            await expect(page.locator('main')).toBeVisible()
        })

    })

    test.describe('Export Invoices', () => {

        test('exportacion carga sin error', async ({ page }) => {
            await page.goto('/dashboard/invoices?operation_type=exp')
            await expect(page).toHaveURL(/invoices/)
            await expect(page.locator('main')).toBeVisible()
        })

    })

    test.describe('Fixed Catalogs', () => {

        test('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()
        })

    })

    test.describe('General Catalogs', () => {

        test('company information carga sin error', async ({ page }) => {
            await page.goto('/dashboard/general_catalogs/company_information')
            await expect(page).toHaveURL(/company_information/)
            await expect(page.locator('main')).toBeVisible()
        })

    })

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

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

    })

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

        test('fixed asset classes carga sin error', async ({ page }) => {
            await page.goto('/dashboard/goods/fixed-asset-classes')
            await expect(page).toHaveURL(/goods/)
            await expect(page.locator('main')).toBeVisible()
        })

    })

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

        test('general carga sin error', async ({ page }) => {
            await page.goto('/dashboard/settings/general')
            await expect(page).toHaveURL(/settings/)
            await expect(page.locator('body')).toBeVisible()
        })

    })

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

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

    })

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

        test('cerrar sesion redirige a login', async ({ page }) => {
            await page.goto('/dashboard')
            await page.locator('[data-sidebar="footer"]')
                .getByRole('button').first().click()
            await page.getByText('Log out').click()
            await expect(page).toHaveURL(/login/, { timeout: 15000 })
        })

    })

})