Functions/Get-Puppeteer_ClickOnSelector.Tests.ps1

describe "BitTitan.Runbooks.UIAutomation/Get-Puppeteer_ClickOnSelector" -Tag "module", "unit" {

    # Import the function to test
    . "$($PSScriptRoot)\Get-Puppeteer_ClickOnSelector.ps1"

    it "returns the code to click on a selector without waiting for the page to load" {
        # Call the function
        $output = Get-Puppeteer_ClickOnSelector -SelectorName "#Selector" -WaitForPageToLoad:$false

        # Verify the output
        $output | Should Be @"
selector = '#selector';
await page.waitForSelector(selector);
await page.click(selector);
"@

    }

    it "returns the code to click on a selector and waiting for the page to load" {
        # Call the function
        $output = Get-Puppeteer_ClickOnSelector -SelectorName "#Selector" -WaitForPageToLoad

        # Verify the output
        $output | Should Be @"
selector = '#selector';
await page.waitForSelector(selector);
await Promise.all([
    page.click(selector),
    page.waitForNavigation()
])
"@

    }
}