import {
    waitForElement,
    waitForElementText,
    findElement,
    waitForElementAndClick,
    waitForElementAndSendKeys,
    waitForElementRemoved,
    waitForUrl,
    screenshot,
    loginMetabase,
    describeE2E
} from "../support/utils";

jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;

describeE2E("dashboards/dashboards", () => {
    fdescribe("dashboards list", () => {
        it("should let you create new dashboards, see them, filter them and enter them", async () => {
            await driver.get(`${server.host}/`);
            await loginMetabase(driver, "bob@metabase.com", "12341234");
            await waitForUrl(driver, `${server.host}/`);
            await driver.get(`${server.host}/dashboard`);
            await screenshot(driver, "screenshots/dashboards.png");

            // Create a new dashboard in the empty state (EmptyState react component)
            await waitForElementAndClick(driver, ".Button.Button--primary");
            await waitForElementAndSendKeys(driver, "#CreateDashboardModal input[name='name']", "Customer Feedback Analysis")
            await waitForElementAndSendKeys(driver, "#CreateDashboardModal input[name='description']", "For seeing the usual response times, feedback topics, our response rate, how often customers are directed to our knowledge base instead of providing a customized response")
            await waitForElementAndClick(driver, "#CreateDashboardModal .Button--primary");

            // Make sure that the redirect was successful
            await waitForUrl(driver, `${server.host}/dashboard/1`)

            // Return to the dashboard list and re-enter the card through the list item
            await driver.get(`${server.host}/dashboard`);
            await waitForElementAndClick(driver, ".Grid-cell > a");
            await waitForUrl(driver, `${server.host}/dashboard/1`)

            // Create another one
            await driver.get(`${server.host}/dashboard`);
            await waitForElementAndClick(driver, "svg[name='add']");
            await waitForElementAndSendKeys(driver, "#CreateDashboardModal input[name='name']", "Some Excessively Long Dashboard Title Just For Fun")
            await waitForElementAndSendKeys(driver, "#CreateDashboardModal input[name='description']", "")
            await waitForElementAndClick(driver, "#CreateDashboardModal .Button--primary");
            await waitForUrl(driver, `${server.host}/dashboard/2`)

            // Test filtering
            await driver.get(`${server.host}/dashboard`);
            await waitForElementAndSendKeys(driver, "input[type='text']", "this should produce no results")
            await waitForElement(driver, "img[src*='empty_dashboard']");

            // Should search from both title and description
            await waitForElementAndSendKeys(driver, "input[type='text']", "usual response times");
            await waitForElementAndClick(driver, ".Grid-cell > a");
            await waitForUrl(driver, `${server.host}/dashboard/1`)
        });

    });
});

@@ -2991,16 +2991,651 @@
 oard/1%60)
+;%0A%0A            // Remove the created dashboards to prevent clashes with other tests%0A            const removeCurrentDash = async () =%3E %7B%0A                await waitForElementAndClick(driver, %22svg%5Bname='pencil'%5D %3E path%22);%0A                await waitForElementAndClick(driver, %22.EditHeader .flex-align-right a:nth-of-type(2)%22);%0A                await waitForElementAndClick(driver, %22.Button.Button--danger%22);%0A            %7D%0A%0A            await removeCurrentDash();%0A            // Should return to dashboard page where only one dash left%0A            await waitForElementAndClick(driver, %22.Grid-cell %3E a%22);%0A            await removeCurrentDash();
 %0A       

Remove created dashboards in E2E test