/**
 * Check if the given URL was opened in a new window
 * @param  {String}   expectedUrl The URL to check for
 */
/* eslint-disable no-unused-vars */
import {CustomExpect} from "../../common-helpers/custom-expect";
import {browser, $, $$, expect} from '@wdio/globals'

export default async function (expectedUrl: string, obsolete: never) {
    /* eslint-enable no-unused-vars */
    /**
     * All the current window handles
     * @type {Object}
     */
    const windowHandles = await browser.getWindowHandles();

    CustomExpect.expectNotToHaveLength(windowHandles, 1, 'A popup was not opened');


    /**
     * The last opened window handle
     * @type {Object}
     //  */
    const lastWindowHandle = windowHandles.slice(-1);

    // Make sure we focus on the last opened window handle
    browser.switchToWindow(lastWindowHandle[0]);

    /**
     * Get the URL of the current browser window
     * @type {String}
     */
    const windowUrl = await browser.getUrl();

    CustomExpect.expectToContain(windowUrl, expectedUrl, "The popup has a incorrect getUrl");
    await browser.closeWindow();
};
