Files
bruno/tests/response/response-format-select-and-preview/response-format-select-and-preview.spec.ts
Abhishek S Lal a798b32f25 feat: add response data type selector in response viewer (#6100)
* feat: add response data type selector in response viewer

* chore: fixed lint issue

* test: add test for resonse format change and preview.

* refactor: streamline response format tests with utility functions for navigation and format switching

* refactor: simplify ButtonDropdown component and enhance QueryResultTypeSelector with header and toggle switch

* feat: enhance ButtonDropdown with prefix and suffix props; implement content type detection and update QueryResult for improved format handling

* fix: lint errors resolved

* fix: remove unnecessary blank line to resolve lint issues

* fix: update response format tests

* refactor: remove preview tab locator from response format tests

* fix: update dependency in useEffect to include previewFormatOptions for accurate format handling

* refactor: reorganize imports and enhance QueryResult component for improved format handling and error display

* fix: update error messages in response format preview tests and adjust version in JSON fixture

* feat: add drag detection to HtmlPreview component and update structure for improved user interaction

* refactor: update ResponsePane components for improved structure and functionality;

replace QueryResult with QueryResponse, enhance layout handling, and streamline response actions

* refactor: remove ButtonDropdown component and associated styles;

* refactor: moved ErrorAlert to ui folder

* fix: lint error

* feat: add data-testid attributes to Collection and CollectionItem components for improved testability

* feat: hide dropdown on select in response selector

* fix: update QueryResult component to use detectedContentType for format handling

* test: update ResponseLayoutToggle tests to use data-testid for button selection

* feat: add data-testid attribute to ResponseClear component for improved testability

* refactor: implement clickResponseAction utility for streamlined response action handling in tests

* feat: add data-testid attribute to ResponseCopy component for enhanced testability

* fix: unwanted code in test
2025-12-09 23:45:01 +05:30

162 lines
7.2 KiB
TypeScript

import { test, expect } from '../../../playwright';
import { closeAllCollections } from '../../utils/page';
import { buildCommonLocators } from '../../utils/page/locators';
import {
openRequest,
sendRequestAndWaitForResponse,
switchResponseFormat,
switchToPreviewTab,
switchToEditorTab
} from '../../utils/page/actions';
test.describe.serial('Response Format Select and Preview', () => {
test.afterAll(async ({ pageWithUserData: page }) => {
// cleanup: close all collections
await closeAllCollections(page);
});
test('Verify Response Format Select and Preview features are rendering properly for JSON response', async ({ pageWithUserData: page }) => {
await openRequest(page, 'collection', 'request-json');
await sendRequestAndWaitForResponse(page);
const locators = buildCommonLocators(page);
const responseBody = locators.response.body();
const editorContainer = locators.response.editorContainer();
const responseFormatTab = locators.response.formatTab();
const codeLine = locators.response.codeLine();
const previewContainer = locators.response.previewContainer();
await test.step('Verify response pane and default JSON editor formatting', async () => {
await expect(responseBody).toBeVisible();
await expect(responseFormatTab).toHaveText('JSON');
await expect(codeLine.nth(1)).toContainText('"hello": "bruno"');
});
await test.step('Switch to Preview tab and check formatted object', async () => {
await switchToPreviewTab(page);
const jsonTreeLines = locators.response.jsonTreeLine();
await expect(jsonTreeLines.nth(1)).toContainText('"hello":"bruno"');
});
await test.step('Switch to Editor, select HTML, verify editor and preview', async () => {
await switchToEditorTab(page);
await switchResponseFormat(page, 'HTML');
await expect(codeLine.nth(1)).toContainText('"hello": "bruno"');
await switchToPreviewTab(page);
await expect(previewContainer).toContainText('{"hello":"bruno"}');
});
await test.step('Switch to Editor, select XML, verify editor and preview error', async () => {
await switchToEditorTab(page);
await switchResponseFormat(page, 'XML');
await expect(codeLine.nth(1)).toContainText('"hello": "bruno"');
await switchToPreviewTab(page);
await expect(previewContainer).toContainText('Cannot preview as XML');
});
await test.step('Switch to Editor, select JavaScript, verify editor and preview fallback', async () => {
await switchToEditorTab(page);
await switchResponseFormat(page, 'JavaScript');
await expect(codeLine.nth(1)).toContainText('"hello": "bruno"');
await switchToPreviewTab(page);
await expect(previewContainer).toContainText('{"hello":"bruno"}');
});
await test.step('Switch to Editor, select Raw, verify editor and preview', async () => {
await switchToEditorTab(page);
await switchResponseFormat(page, 'Raw');
await expect(codeLine.nth(1)).toContainText('"hello": "bruno"');
await switchToPreviewTab(page);
await expect(previewContainer).toContainText('{"hello":"bruno"}');
});
await test.step('Switch to Editor, select Hex, verify editor and preview', async () => {
await switchToEditorTab(page);
await switchResponseFormat(page, 'Hex');
await expect(editorContainer).toContainText('00000000: 7B 0A 20 20 22 68 65 6C 6C 6F 22 3A 20 22');
await switchToPreviewTab(page);
await expect(previewContainer).toContainText('{"hello":"bruno"}');
});
await test.step('Switch to Editor, select Base64, verify editor and preview', async () => {
await switchToEditorTab(page);
await switchResponseFormat(page, 'Base64');
await expect(editorContainer).toContainText('ewogICJoZWxsbyI6ICJicnVubyIKfQ==');
await switchToPreviewTab(page);
await expect(previewContainer).toContainText('{"hello":"bruno"}');
});
});
test('Verify Response Format Select and Preview features are rendering properly for HTML response', async ({ pageWithUserData: page }) => {
await openRequest(page, 'collection', 'request-html');
await sendRequestAndWaitForResponse(page);
const locators = buildCommonLocators(page);
const responseBody = locators.response.body();
const editorContainer = locators.response.editorContainer();
const responseFormatTab = locators.response.formatTab();
const codeLine = locators.response.codeLine();
const previewContainer = locators.response.previewContainer();
await test.step('Verify response pane and default HTML preview', async () => {
await expect(responseBody).toBeVisible();
await expect(previewContainer.locator('webview')).toBeVisible();
});
await test.step('Switch to Editor tab and check formatted HTML', async () => {
await expect(responseFormatTab).toHaveText('HTML');
await switchToEditorTab(page);
await expect(codeLine.first()).toContainText('<h1>hello</h1>');
});
await test.step('Select JSON, verify editor and preview', async () => {
await switchResponseFormat(page, 'JSON');
await expect(codeLine.first()).toContainText('<h1>hello</h1>');
await switchToPreviewTab(page);
await expect(previewContainer).toContainText('Cannot preview as JSON');
});
await test.step('Switch to Editor, select XML, verify editor and preview', async () => {
await switchToEditorTab(page);
await switchResponseFormat(page, 'XML');
await expect(codeLine.first()).toContainText('<h1>hello</h1>');
await switchToPreviewTab(page);
await expect(previewContainer).toContainText('h1');
await expect(previewContainer).toContainText(':');
await expect(previewContainer).toContainText('hello');
});
await test.step('Switch to Editor, select JavaScript, verify editor and preview fallback', async () => {
await switchToEditorTab(page);
await switchResponseFormat(page, 'JavaScript');
await expect(codeLine.first()).toContainText('<h1>hello</h1>');
await switchToPreviewTab(page);
await expect(previewContainer.locator('webview')).toBeVisible();
});
await test.step('Switch to Editor, select Raw, verify editor and preview', async () => {
await switchToEditorTab(page);
await switchResponseFormat(page, 'Raw');
await expect(codeLine.first()).toContainText('<h1>hello</h1>');
await switchToPreviewTab(page);
await expect(previewContainer).toContainText('<h1>hello</h1>');
});
await test.step('Switch to Editor, select Hex, verify editor and preview', async () => {
await switchToEditorTab(page);
await switchResponseFormat(page, 'Hex');
await expect(editorContainer).toContainText('00000000: 3C 68 31 3E 68 65 6C 6C 6F 3C 2F 68 31 3E');
await switchToPreviewTab(page);
await expect(previewContainer).toContainText('<h1>hello</h1>');
});
await test.step('Switch to Editor, select Base64, verify editor and preview', async () => {
await switchToEditorTab(page);
await switchResponseFormat(page, 'Base64');
await expect(editorContainer).toContainText('PGgxPmhlbGxvPC9oMT4=');
await switchToPreviewTab(page);
await expect(previewContainer).toContainText('<h1>hello</h1>');
});
});
});