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

test("Product Page: Add To Basket", async ({ page }) => {
    await page.goto("/")
    
    //const addToBasketButton = page.locator('div').filter({ hasText: /^499\$Add to Basket$/ }).getByRole('button')
    
    const addToBasketButton = page.locator('[data-qa="product-button"]').first()
    const basketCounter = page.locator('[data-qa="header-basket-count"]')
    const checkoutLink = page.getByRole('link', { name: 'Checkout' })
   
    addToBasketButton.waitFor()
    basketCounter.waitFor()
    checkoutLink.waitFor()
    
    await expect(addToBasketButton).toHaveText("Add to Basket")
    await expect(basketCounter).toHaveText("0")
    
    await addToBasketButton.click()
    await expect(addToBasketButton).toHaveText("Remove from Basket")
    await expect(basketCounter).toHaveText("1")
    
    await page.pause();
    
    await checkoutLink.click()
    await page.waitForURL("/basket")
    
    
    //console.log("Buttons --- " + await page.locator('[data-qa="product-button"]').count())
})


// productPage.visit()
// productPage.sortProductsByCheapest
// productPage.addItemToBasket(1)
// navigation.moveToCheckout()
// basket.removeCheapestItem()
