"use strict";
// Copyright 2025 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 network_helpers_js_1 = require("../helpers/network-helpers.js");
const sources_helpers_js_1 = require("../helpers/sources-helpers.js");
const PRETTY_PRINT_BUTTON = '[aria-label="Pretty print"]';
describe('The Network Tab', function () {
    it('can pretty print an inline json subtype file', async ({ devToolsPage, inspectedPage }) => {
        await (0, network_helpers_js_1.navigateToNetworkTab)('code-with-json-subtype-request.html', devToolsPage, inspectedPage);
        await (0, network_helpers_js_1.waitForSomeRequestsToAppear)(2, devToolsPage);
        await (0, network_helpers_js_1.selectRequestByName)('json-subtype-ld.rawresponse', {}, devToolsPage);
        const networkView = await devToolsPage.waitFor('.network-item-view');
        await devToolsPage.click('#tab-headers-component', {
            root: networkView,
        });
        await devToolsPage.click('[aria-label=Response].tabbed-pane-header-tab', {
            root: networkView,
        });
        await devToolsPage.waitFor('[aria-label=Response].tabbed-pane-header-tab[aria-selected=true]', networkView);
        const editor = await devToolsPage.waitFor('[aria-label="Code editor"]');
        const textFromResponse = await (0, sources_helpers_js_1.retrieveCodeMirrorEditorContent)(devToolsPage);
        const expectedTextFromResponse = [
            '{',
            '    "Keys": [',
            '        {',
            '            "Key1": "Value1",',
            '            "Key2": "Value2",',
            '            "Key3": true',
            '        },',
            '        {',
            '            "Key1": "Value1",',
            '            "Key2": "Value2",',
            '            "Key3": false',
            '        }',
            '    ]',
            '}',
        ];
        chai_1.assert.deepEqual(textFromResponse, expectedTextFromResponse);
        await devToolsPage.waitForFunction(async () => await (0, sources_helpers_js_1.isPrettyPrinted)(devToolsPage));
        chai_1.assert.isTrue(await (0, network_helpers_js_1.elementContainsTextWithSelector)(editor, '"Value1"', '.token-string'));
        chai_1.assert.isTrue(await (0, network_helpers_js_1.elementContainsTextWithSelector)(editor, 'true', '.token-atom'));
        await devToolsPage.click(PRETTY_PRINT_BUTTON);
        const actualNotPrettyText = await (0, sources_helpers_js_1.retrieveCodeMirrorEditorContent)(devToolsPage);
        const expectedNotPrettyText = '{"Keys": [{"Key1": "Value1","Key2": "Value2","Key3": true},{"Key1": "Value1","Key2": "Value2","Key3": false}]},';
        chai_1.assert.strictEqual(expectedNotPrettyText, actualNotPrettyText.toString());
        await devToolsPage.waitForFunction(async () => !(await (0, sources_helpers_js_1.isPrettyPrinted)(devToolsPage)));
        chai_1.assert.isTrue(await (0, network_helpers_js_1.elementContainsTextWithSelector)(editor, '"Value1"', '.token-string'));
        chai_1.assert.isTrue(await (0, network_helpers_js_1.elementContainsTextWithSelector)(editor, 'true', '.token-atom'));
    });
    it('can pretty print when there is only one json or json subtype file', async ({ devToolsPage, inspectedPage }) => {
        await (0, network_helpers_js_1.navigateToNetworkTab)('json-subtype-ld.rawresponse', devToolsPage, inspectedPage);
        await (0, network_helpers_js_1.waitForSomeRequestsToAppear)(1, devToolsPage);
        await (0, network_helpers_js_1.selectRequestByName)('json-subtype-ld.rawresponse', {}, devToolsPage);
        const networkView = await devToolsPage.waitFor('.network-item-view');
        await devToolsPage.click('#tab-headers-component', {
            root: networkView,
        });
        await devToolsPage.click('[aria-label=Response].tabbed-pane-header-tab', {
            root: networkView,
        });
        await devToolsPage.waitFor('[aria-label=Response].tabbed-pane-header-tab[aria-selected=true]', networkView);
        const editor = await devToolsPage.waitFor('[aria-label="Code editor"]');
        const textFromResponse = await (0, sources_helpers_js_1.retrieveCodeMirrorEditorContent)(devToolsPage);
        const expectedTextFromResponse = [
            '{',
            '    "Keys": [',
            '        {',
            '            "Key1": "Value1",',
            '            "Key2": "Value2",',
            '            "Key3": true',
            '        },',
            '        {',
            '            "Key1": "Value1",',
            '            "Key2": "Value2",',
            '            "Key3": false',
            '        }',
            '    ]',
            '}',
        ];
        chai_1.assert.deepEqual(textFromResponse, expectedTextFromResponse);
        await devToolsPage.waitForFunction(async () => await (0, sources_helpers_js_1.isPrettyPrinted)(devToolsPage));
        chai_1.assert.isTrue(await (0, network_helpers_js_1.elementContainsTextWithSelector)(editor, '"Value1"', '.token-string'));
        chai_1.assert.isTrue(await (0, network_helpers_js_1.elementContainsTextWithSelector)(editor, 'true', '.token-atom'));
    });
});
//# sourceMappingURL=can-pretty-print-network.test.js.map