"use strict";
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const lighthouse_helpers_js_1 = require("../helpers/lighthouse-helpers.js");
describe('The Lighthouse start view', () => {
    // TODO (liviurau): Update clearSiteData helper to work in docked mode
    setup({ dockingMode: 'undocked' });
    it('shows a button to generate a new report', async ({ devToolsPage, inspectedPage }) => {
        await (0, lighthouse_helpers_js_1.navigateToLighthouseTab)('empty.html', devToolsPage, inspectedPage);
        const disabled = await (0, lighthouse_helpers_js_1.isGenerateReportButtonDisabled)(devToolsPage);
        const helpText = await (0, lighthouse_helpers_js_1.getHelpText)(devToolsPage);
        chai_1.assert.isFalse(disabled, 'The Generate Report button should not be disabled');
        chai_1.assert.strictEqual(helpText, '');
    });
    it('disables the start button when no categories are selected', async ({ devToolsPage, inspectedPage }) => {
        await (0, lighthouse_helpers_js_1.navigateToLighthouseTab)('empty.html', devToolsPage, inspectedPage);
        await (0, lighthouse_helpers_js_1.selectCategories)([], devToolsPage);
        const disabled = await (0, lighthouse_helpers_js_1.isGenerateReportButtonDisabled)(devToolsPage);
        const helpText = await (0, lighthouse_helpers_js_1.getHelpText)(devToolsPage);
        chai_1.assert.isTrue(disabled, 'The Generate Report button should be disabled');
        chai_1.assert.strictEqual(helpText, 'At least one category must be selected.');
    });
    it('enables the start button if only one category is selected', async ({ devToolsPage, inspectedPage }) => {
        await (0, lighthouse_helpers_js_1.navigateToLighthouseTab)('empty.html', devToolsPage, inspectedPage);
        await (0, lighthouse_helpers_js_1.selectCategories)(['performance'], devToolsPage);
        const disabled = await (0, lighthouse_helpers_js_1.isGenerateReportButtonDisabled)(devToolsPage);
        const helpText = await (0, lighthouse_helpers_js_1.getHelpText)(devToolsPage);
        chai_1.assert.isFalse(disabled, 'The Generate Report button should be enabled');
        chai_1.assert.strictEqual(helpText, '');
    });
    it('disables the start button for internal pages in navigation mode', async ({ devToolsPage, inspectedPage }) => {
        await (0, lighthouse_helpers_js_1.navigateToLighthouseTab)(undefined, devToolsPage, inspectedPage);
        await inspectedPage.goTo('about:blank');
        const disabled = await (0, lighthouse_helpers_js_1.isGenerateReportButtonDisabled)(devToolsPage);
        const helpText = await (0, lighthouse_helpers_js_1.getHelpText)(devToolsPage);
        chai_1.assert.isTrue(disabled, 'The Generate Report button should be disabled');
        chai_1.assert.strictEqual(helpText, 'Can only audit pages on HTTP or HTTPS. Navigate to a different page.');
    });
    it('disables the start button for internal pages in non-navigation mode', async ({ devToolsPage, inspectedPage }) => {
        await (0, lighthouse_helpers_js_1.navigateToLighthouseTab)(undefined, devToolsPage, inspectedPage);
        await inspectedPage.goTo('about:blank');
        await (0, lighthouse_helpers_js_1.selectMode)('timespan', devToolsPage);
        const disabled = await (0, lighthouse_helpers_js_1.isGenerateReportButtonDisabled)(devToolsPage);
        const helpText = await (0, lighthouse_helpers_js_1.getHelpText)(devToolsPage);
        chai_1.assert.isFalse(disabled, 'The Generate Report button should be enabled');
        chai_1.assert.strictEqual(helpText, '');
    });
    it('shows generate report button even when navigating to an unreachable page', async ({ devToolsPage, inspectedPage }) => {
        await (0, lighthouse_helpers_js_1.navigateToLighthouseTab)('empty.html', devToolsPage, inspectedPage);
        await inspectedPage.goToResource('network/unreachable.rawresponse');
        const disabled = await (0, lighthouse_helpers_js_1.isGenerateReportButtonDisabled)(devToolsPage);
        chai_1.assert.isTrue(disabled, 'The Generate Report button should be disabled');
    });
    it('displays warning if important data may affect performance', async ({ devToolsPage, inspectedPage }) => {
        // e2e tests in application/ create indexeddb items and don't clean up after themselves
        await (0, lighthouse_helpers_js_1.clearSiteData)(devToolsPage, inspectedPage);
        await (0, lighthouse_helpers_js_1.navigateToLighthouseTab)('empty.html', devToolsPage, inspectedPage);
        let warningElem = await devToolsPage.waitFor('.lighthouse-warning-text.hidden');
        const warningText1 = await warningElem.evaluate(node => node.textContent?.trim());
        chai_1.assert.strictEqual(warningText1, '');
        await (0, lighthouse_helpers_js_1.navigateToLighthouseTab)('lighthouse/lighthouse-storage.html', devToolsPage, inspectedPage);
        // Wait for storage state to lazily update
        await (0, lighthouse_helpers_js_1.waitForStorageUsage)(quota => quota > 0, devToolsPage);
        warningElem = await devToolsPage.waitFor('.lighthouse-warning-text:not(.hidden)');
        const expected = 'There may be stored data affecting loading performance in this location: IndexedDB. Audit this page in an incognito window to prevent those resources from affecting your scores.';
        const warningText2 = await warningElem.evaluate(node => node.textContent?.trim());
        chai_1.assert.strictEqual(warningText2, expected);
    });
});
//# sourceMappingURL=start-view.test.js.map