Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ const WSRequestBodyMode = ({ mode, onModeChange }) => {

const Icon = forwardRef((props, ref) => {
return (
<div ref={ref} className="flex items-center justify-center pl-3 py-1 select-none selected-body-mode">
<div
ref={ref}
className="flex items-center justify-center pl-3 py-1 select-none selected-body-mode"
data-testid="ws-body-mode-label"
>
{humanizeRequestBodyMode(mode)}
{' '}
<IconCaretDown className="caret ml-2" size={14} strokeWidth={2} />
Expand All @@ -35,12 +39,18 @@ const WSRequestBodyMode = ({ mode, onModeChange }) => {

return (
<StyledWrapper>
<div className="inline-flex items-center cursor-pointer body-mode-selector">
<Dropdown onCreate={onDropdownCreate} icon={<Icon />} placement="bottom-end">
<div className="inline-flex items-center cursor-pointer body-mode-selector" data-testid="ws-body-mode-selector">
<Dropdown
onCreate={onDropdownCreate}
icon={<Icon />}
placement="bottom-end"
appendTo={() => document.body}
>
<div className="label-item font-medium">Raw</div>
{RAW_MODES.map((d) => (
<div
className="dropdown-item"
data-testid={`ws-body-mode-item-${d.key}`}
key={d.key}
onClick={() => {
dropdownTippyRef.current.hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ const StyledWrapper = styled.div`
top: 0;
z-index: 1;
background: ${(props) => props.theme.bg};

&:hover {
z-index: 2;
Comment thread
sid-bruno marked this conversation as resolved.
Resolved
}

display: flex;
align-items: center;
justify-content: space-between;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ export const SingleWSMessage = ({
</div>
<div className="accordion-actions" onClick={(e) => e.stopPropagation()}>
<div className="hover-actions">
<ToolHint text="Send" toolhintId={`send-msg-${index}`}>
<ToolHint text="Send" toolhintId={`send-msg-${index}`} place="bottom">
<button onClick={onSendMessage} className="hover-action-btn" data-testid={`ws-send-msg-${index}`}>
<IconSend size={14} strokeWidth={1.5} />
</button>
</ToolHint>
{(body.ws || []).length > 1 && (
<ToolHint text="Delete" toolhintId={`delete-msg-${index}`}>
<ToolHint text="Delete" toolhintId={`delete-msg-${index}`} place="bottom">
<button onClick={onDeleteMessage} className="hover-action-btn delete" data-testid={`ws-delete-msg-${index}`}>
<IconTrash size={14} strokeWidth={1.5} />
</button>
Expand Down
20 changes: 19 additions & 1 deletion tests/utils/page/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
// causing Playwright's "element is stable" actionability check to fail
// intermittently on slower machines. Use force to skip the stability check;
// visibility is already verified above via waitFor.
await page.getByRole('button', { name: 'Discard All and Remove' }).click({ force: true });

Check failure on line 73 in tests/utils/page/actions.ts

View workflow job for this annotation

GitHub Actions / Playwright E2E Tests (Linux)

[default] › tests/request/body-scroll/body-scroll-restoration.spec.ts:80:7 › Request Body Scroll Position Restoration › should restore scroll position when switching tabs and back

6) [default] › tests/request/body-scroll/body-scroll-restoration.spec.ts:80:7 › Request Body Scroll Position Restoration › should restore scroll position when switching tabs and back Error: locator.click: Target page, context or browser has been closed Call log: - waiting for getByRole('button', { name: 'Discard All and Remove' }) at tests/utils/page/actions.ts:73 71 | // intermittently on slower machines. Use force to skip the stability check; 72 | // visibility is already verified above via waitFor. > 73 | await page.getByRole('button', { name: 'Discard All and Remove' }).click({ force: true }); | ^ 74 | } else { 75 | // Regular modal - click the submit button 76 | await page.locator('.bruno-modal-footer .submit').click(); at /home/runner/work/bruno/bruno/tests/utils/page/actions.ts:73:76 at closeAllCollections (/home/runner/work/bruno/bruno/tests/utils/page/actions.ts:46:3) at /home/runner/work/bruno/bruno/tests/request/body-scroll/body-scroll-restoration.spec.ts:77:5
} else {
// Regular modal - click the submit button
await page.locator('.bruno-modal-footer .submit').click();
Expand Down Expand Up @@ -487,7 +487,7 @@
await test.step(`Import collection from "${filePath}"`, async () => {
const locators = buildCommonLocators(page);

await page.getByTestId('collections-header-add-menu').click();

Check failure on line 490 in tests/utils/page/actions.ts

View workflow job for this annotation

GitHub Actions / Playwright E2E Tests (Linux)

[default] › tests/import/postman/import-many-issues-collection.spec.ts:12:7 › Import Postman Collection with many issues (URL too long warning) › should show URL-too-long warning when include failed request data is checked

5) [default] › tests/import/postman/import-many-issues-collection.spec.ts:12:7 › Import Postman Collection with many issues (URL too long warning) › should show URL-too-long warning when include failed request data is checked › Import collection from "/home/runner/work/bruno/bruno/tests/import/postman/fixtures/postman-with-many-import-issues.json" Error: locator.click: Target page, context or browser has been closed Call log: - waiting for getByTestId('collections-header-add-menu') - locator resolved to <button tabindex="-1" aria-expanded="false" data-tabindex="inline" title="Add new collection" data-testid="collections-header-add-menu" class="StyledWrapper-iYvzMB btWNSr action-icon">…</button> - attempting click action 2 × waiting for element to be visible, enabled and stable - element is visible, enabled and stable - scrolling into view if needed - done scrolling - <div class="bruno-modal-backdrop"></div> from <div class="StyledWrapper__Wrapper-jjqtyM DwvBf">…</div> subtree intercepts pointer events - retrying click action - waiting 20ms 2 × waiting for element to be visible, enabled and stable - element is visible, enabled and stable - scrolling into view if needed - done scrolling - <div class="bruno-modal-backdrop"></div> from <div class="StyledWrapper__Wrapper-jjqtyM DwvBf">…</div> subtree intercepts pointer events - retrying click action - waiting 100ms 58 × waiting for element to be visible, enabled and stable - element is visible, enabled and stable - scrolling into view if needed - done scrolling - <div class="bruno-modal-backdrop"></div> from <div class="StyledWrapper__Wrapper-jjqtyM DwvBf">…</div> subtree intercepts pointer events - retrying click action - waiting 500ms at tests/utils/page/actions.ts:490 488 | const locators = buildCommonLocators(page); 489 | > 490 | await page.getByTestId('collections-header-add-menu').click(); | ^ 491 | await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Import collection' }).click(); 492 | 493 | // Wait for import modal at /home/runner/work/bruno/bruno/tests/utils/page/actions.ts:490:59 at importCollection (/home/runner/work/bruno/bruno/tests/utils/page/actions.ts:487:14) at /home/runner/work/bruno/bruno/tests/import/postman/import-many-issues-collection.spec.ts:17:27
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Import collection' }).click();

// Wait for import modal
Expand Down Expand Up @@ -804,7 +804,7 @@
) => {
await test.step(`Add row "${name}" to the active environment tab`, async () => {
const nameInput = page.locator('input[placeholder="Name"]').last();
await nameInput.waitFor({ state: 'visible' });

Check failure on line 807 in tests/utils/page/actions.ts

View workflow job for this annotation

GitHub Actions / Playwright E2E Tests (Linux)

[default] › tests/environments/create-environment/global-env-create.spec.ts:23:7 › Global Environment Create Tests › should import collection and create global environment for request usage

4) [default] › tests/environments/create-environment/global-env-create.spec.ts:23:7 › Global Environment Create Tests › should import collection and create global environment for request usage › Create global environment with variables › Add 5 environment variables › Add environment variable "postBody" › Add row "postBody" to the active environment tab TimeoutError: locator.waitFor: Timeout 30000ms exceeded. Call log: - waiting for locator('input[placeholder="Name"]').last() to be visible at tests/utils/page/actions.ts:807 805 | await test.step(`Add row "${name}" to the active environment tab`, async () => { 806 | const nameInput = page.locator('input[placeholder="Name"]').last(); > 807 | await nameInput.waitFor({ state: 'visible' }); | ^ 808 | await nameInput.fill(name); 809 | 810 | const row = page.getByTestId(`env-var-row-${name}`); at /home/runner/work/bruno/bruno/tests/utils/page/actions.ts:807:21 at addRowToActiveTab (/home/runner/work/bruno/bruno/tests/utils/page/actions.ts:805:14) at /home/runner/work/bruno/bruno/tests/utils/page/actions.ts:770:11 at addEnvironmentVariable (/home/runner/work/bruno/bruno/tests/utils/page/actions.ts:763:3) at /home/runner/work/bruno/bruno/tests/utils/page/actions.ts:784:7 at addEnvironmentVariables (/home/runner/work/bruno/bruno/tests/utils/page/actions.ts:782:3) at /home/runner/work/bruno/bruno/tests/environments/create-environment/global-env-create.spec.ts:39:7 at /home/runner/work/bruno/bruno/tests/environments/create-environment/global-env-create.spec.ts:36:5

Check failure on line 807 in tests/utils/page/actions.ts

View workflow job for this annotation

GitHub Actions / Playwright E2E Tests (Linux)

[default] › tests/environments/create-environment/collection-env-create.spec.ts:15:7 › Collection Environment Create Tests › should import collection and create environment for request usage

3) [default] › tests/environments/create-environment/collection-env-create.spec.ts:15:7 › Collection Environment Create Tests › should import collection and create environment for request usage › Create environment with variables › Add 5 environment variables › Add environment variable "postBody" › Add row "postBody" to the active environment tab Error: locator.waitFor: Target page, context or browser has been closed Call log: - waiting for locator('input[placeholder="Name"]').last() to be visible at tests/utils/page/actions.ts:807 805 | await test.step(`Add row "${name}" to the active environment tab`, async () => { 806 | const nameInput = page.locator('input[placeholder="Name"]').last(); > 807 | await nameInput.waitFor({ state: 'visible' }); | ^ 808 | await nameInput.fill(name); 809 | 810 | const row = page.getByTestId(`env-var-row-${name}`); at /home/runner/work/bruno/bruno/tests/utils/page/actions.ts:807:21 at addRowToActiveTab (/home/runner/work/bruno/bruno/tests/utils/page/actions.ts:805:14) at /home/runner/work/bruno/bruno/tests/utils/page/actions.ts:770:11 at addEnvironmentVariable (/home/runner/work/bruno/bruno/tests/utils/page/actions.ts:763:3) at /home/runner/work/bruno/bruno/tests/utils/page/actions.ts:784:7 at addEnvironmentVariables (/home/runner/work/bruno/bruno/tests/utils/page/actions.ts:782:3) at /home/runner/work/bruno/bruno/tests/environments/create-environment/collection-env-create.spec.ts:31:7 at /home/runner/work/bruno/bruno/tests/environments/create-environment/collection-env-create.spec.ts:28:5
await nameInput.fill(name);

const row = page.getByTestId(`env-var-row-${name}`);
Expand Down Expand Up @@ -1345,7 +1345,7 @@
}

throw new Error(`Tab "${tabName}" not found in visible tabs or overflow dropdown`);
}).toPass({ timeout: 15000 });

Check failure on line 1348 in tests/utils/page/actions.ts

View workflow job for this annotation

GitHub Actions / Playwright E2E Tests (Linux)

[default] › tests/request/timeline/timeline-runrequest-skip.spec.ts:18:7 › Timeline — bru.runRequest skips unsupported item types › shows Skipped rows for WS and gRPC targets

7) [default] › tests/request/timeline/timeline-runrequest-skip.spec.ts:18:7 › Timeline — bru.runRequest skips unsupported item types › shows Skipped rows for WS and gRPC targets › Timeline has main + two Skipped runRequest rows › Select tab "Timeline" in [data-testid="response-pane"] Error: Timed out 2000ms waiting for expect(locator).toContainClass(expected) Locator: locator('[data-testid="response-pane"]').locator('.tabs').getByRole('tab', { name: 'Timeline' }) Expected string: "active" Received: <element(s) not found> Call log: - expect.toContainClass with timeout 2000ms - waiting for locator('[data-testid="response-pane"]').locator('.tabs').getByRole('tab', { name: 'Timeline' }) Call Log: - Timeout 15000ms exceeded while waiting on the predicate at tests/utils/page/actions.ts:1348 1346 | 1347 | throw new Error(`Tab "${tabName}" not found in visible tabs or overflow dropdown`); > 1348 | }).toPass({ timeout: 15000 }); | ^ 1349 | }); 1350 | }; 1351 | at /home/runner/work/bruno/bruno/tests/utils/page/actions.ts:1348:8 at selectPaneTab (/home/runner/work/bruno/bruno/tests/utils/page/actions.ts:1308:3) at selectResponsePaneTab (/home/runner/work/bruno/bruno/tests/utils/page/actions.ts:1353:3) at /home/runner/work/bruno/bruno/tests/request/timeline/timeline-runrequest-skip.spec.ts:43:7 at /home/runner/work/bruno/bruno/tests/request/timeline/timeline-runrequest-skip.spec.ts:42:5
});
};

Expand Down Expand Up @@ -2455,6 +2455,23 @@
return tooltip;
};

/**
* Returns true if the element is on top at its centre (not hidden behind a header),
* i.e. the topmost element at its centre is inside a dropdown/tippy container.
* @param locator - The dropdown item locator
* @returns Whether the item is the topmost element at its own centre
*/
const elementIsInsideDropdown = async (locator: Locator) => {
const box = await locator.boundingBox();
expect(box, 'dropdown item should have a layout box').not.toBeNull();
const x = box!.x + box!.width / 2;
const y = box!.y + box!.height / 2;
return locator.page().evaluate(
({ x, y }) => Boolean(document.elementFromPoint(x, y)?.closest('.tippy-box, .dropdown')),
{ x, y }
);
};

export {
waitForReadyPage,
setRequestUrlAndSave,
Expand Down Expand Up @@ -2556,7 +2573,8 @@
getAppWebviewHtml,
createApp,
selectAppView,
renameWsMessage
renameWsMessage,
elementIsInsideDropdown
};

export type { SandboxMode, EnvironmentType, EnvironmentVariable, ImportCollectionOptions, CreateRequestOptions, CreateUntitledRequestOptions, CreateTransientRequestOptions, AssertionInput };
33 changes: 1 addition & 32 deletions tests/utils/page/locators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { buildApiSpecPanelLocators } from './openapi/render-spec';
import { buildFileModeLocators } from './file-mode';
import { buildPreferencesLocators } from './preferences';
import { buildAiPreferencesLocators } from './ai';
import { buildWebsocketCommonLocators } from './websocket';

export const buildCommonLocators = (page: Page) => ({
runner: () => page.getByTestId('run-button'),
Expand Down Expand Up @@ -367,38 +368,6 @@ export const buildCommonLocators = (page: Page) => ({
}
});

export const buildWebsocketCommonLocators = (page: Page) => ({
connectionControls: {
connect: () => page.getByTestId('ws-connect-button'),
disconnect: () => page.getByTestId('ws-disconnect-button')
},
messages: () => page.locator('.ws-message'),
message: {
container: () => page.getByTestId('ws-messages-container'),
addButton: () => page.getByTestId('ws-add-message'),
headers: () => page.getByTestId(/^ws-message-header-/),
header: (index: number) => page.getByTestId(`ws-message-header-${index}`),
body: (index: number) => page.getByTestId(`ws-message-body-${index}`),
editor: (index: number) => page.getByTestId(`ws-message-body-${index}`).locator('.CodeMirror'),
editorPlaceholder: (index: number) =>
page.getByTestId(`ws-message-body-${index}`).locator('.CodeMirror-placeholder'),
editorCode: (index: number) => page.getByTestId(`ws-message-body-${index}`).locator('.CodeMirror-code'),
labels: () => page.getByTestId(/^ws-message-label-/),
label: (index: number) => page.getByTestId(`ws-message-label-${index}`),
nameInputs: () => page.getByTestId(/^ws-message-name-input-/),
nameInput: (index: number) => page.getByTestId(`ws-message-name-input-${index}`),
nameTooltip: () => page.getByTestId('ws-message-name-tooltip'),
prettifyAll: () => page.getByTestId('ws-prettify-all'),
sendButton: (index: number) => page.getByTestId(`ws-send-msg-${index}`),
deleteButton: (index: number) => page.getByTestId(`ws-delete-msg-${index}`)
},
toolbar: {
latestFirst: () => page.getByRole('button', { name: 'Latest First' }),
latestLast: () => page.getByRole('button', { name: 'Latest Last' }),
clearResponse: () => page.getByTestId('response-clear-btn')
}
});

export const getTableCell = (row, index) => row.locator('td').nth(index + 1);

export const buildGrpcCommonLocators = (page: Page) => ({
Expand Down
38 changes: 38 additions & 0 deletions tests/utils/page/websocket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Page } from '../../../playwright';

export const buildWebsocketCommonLocators = (page: Page) => ({
connectionControls: {
connect: () => page.getByTestId('ws-connect-button'),
disconnect: () => page.getByTestId('ws-disconnect-button')
},
messages: () => page.locator('.ws-message'),
message: {
container: () => page.getByTestId('ws-messages-container'),
addButton: () => page.getByTestId('ws-add-message'),
headers: () => page.getByTestId(/^ws-message-header-/),
header: (index: number) => page.getByTestId(`ws-message-header-${index}`),
body: (index: number) => page.getByTestId(`ws-message-body-${index}`),
editor: (index: number) => page.getByTestId(`ws-message-body-${index}`).locator('.CodeMirror'),
editorPlaceholder: (index: number) =>
page.getByTestId(`ws-message-body-${index}`).locator('.CodeMirror-placeholder'),
editorCode: (index: number) => page.getByTestId(`ws-message-body-${index}`).locator('.CodeMirror-code'),
labels: () => page.getByTestId(/^ws-message-label-/),
label: (index: number) => page.getByTestId(`ws-message-label-${index}`),
nameInputs: () => page.getByTestId(/^ws-message-name-input-/),
nameInput: (index: number) => page.getByTestId(`ws-message-name-input-${index}`),
nameTooltip: () => page.getByTestId('ws-message-name-tooltip'),
prettifyAll: () => page.getByTestId('ws-prettify-all'),
sendButton: (index: number) => page.getByTestId(`ws-send-msg-${index}`),
deleteButton: (index: number) => page.getByTestId(`ws-delete-msg-${index}`),
bodyModeSelector: (index: number) =>
page.getByTestId(`ws-message-header-${index}`).getByTestId('ws-body-mode-selector'),
bodyModeLabel: (index: number) =>
page.getByTestId(`ws-message-header-${index}`).getByTestId('ws-body-mode-label'),
bodyModeItem: (mode: 'json' | 'xml' | 'text') => page.getByTestId(`ws-body-mode-item-${mode}`)
},
toolbar: {
latestFirst: () => page.getByRole('button', { name: 'Latest First' }),
latestLast: () => page.getByRole('button', { name: 'Latest Last' }),
clearResponse: () => page.getByTestId('response-clear-btn')
}
});
110 changes: 110 additions & 0 deletions tests/websockets/ws-header.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { expect, test } from '../../playwright';
import { closeAllTabs, createTransientRequest, elementIsInsideDropdown, selectRequestPaneTab } from '../utils/page/actions';
import { buildCommonLocators } from '../utils/page/locators';

test.describe('websocket sticky header dropdown overlap', () => {
test.afterEach(async ({ page }) => {
await closeAllTabs(page);
});

test('body-mode dropdown of an upper message renders above the collapsed headers below it', async ({
page
}) => {
const { websocket } = buildCommonLocators(page);

await test.step('Open a websocket request with several collapsed messages', async () => {
await createTransientRequest(page, { requestType: 'WebSocket' });
await selectRequestPaneTab(page, 'Message');

await expect(websocket.message.headers()).toHaveCount(1);
for (let i = 0; i < 3; i++) {
const before = await websocket.message.headers().count();
await websocket.message.addButton().click();
await expect(websocket.message.headers()).toHaveCount(before + 1);
}

const total = await websocket.message.headers().count();
expect(total).toBeGreaterThanOrEqual(4);

// Collapse every message so all accordions are closed.
for (let i = 0; i < total; i++) {
if (await websocket.message.body(i).isVisible()) {
await websocket.message.header(i).click();
}
}
for (let i = 0; i < total; i++) {
await expect(websocket.message.body(i)).toBeHidden();
}
});

const textItem = websocket.message.bodyModeItem('text');

await test.step('Open the first message dropdown over the headers below', async () => {
await websocket.message.bodyModeSelector(0).click();

// The lowest item is the one most likely to overlap the header below, so
// it is the strongest signal that the menu is not covered.
await expect(textItem).toBeVisible();

// The item must be the topmost element at its own centre. Without the fix
// a lower header paints over it and this resolves to the header instead.
expect(await elementIsInsideDropdown(textItem)).toBe(true);
});

await test.step('Select the item and verify it applies', async () => {
// Playwright's actionability check fails if the item is obscured.
await textItem.click();
await expect(websocket.message.bodyModeLabel(0)).toContainText('TEXT');
});
});

test('open dropdown stays on top when a lower message header is hovered', async ({
page
}) => {
const { websocket } = buildCommonLocators(page);
let total = 0;

await test.step('Open a websocket request with several collapsed messages', async () => {
await createTransientRequest(page, { requestType: 'WebSocket' });
await selectRequestPaneTab(page, 'Message');

await expect(websocket.message.headers()).toHaveCount(1);
for (let i = 0; i < 3; i++) {
const before = await websocket.message.headers().count();
await websocket.message.addButton().click();
await expect(websocket.message.headers()).toHaveCount(before + 1);
}

total = await websocket.message.headers().count();
expect(total).toBeGreaterThanOrEqual(4);

// Collapse every message so all accordions are closed.
for (let i = 0; i < total; i++) {
if (await websocket.message.body(i).isVisible()) {
await websocket.message.header(i).click();
}
}
for (let i = 0; i < total; i++) {
await expect(websocket.message.body(i)).toBeHidden();
}
});

const textItem = websocket.message.bodyModeItem('text');

await test.step('Open the first message dropdown, then hover a header below it', async () => {
// The dropdown renders in a portal (appendTo document.body), so hovering a
// lower header must not raise that header over the open menu.
await websocket.message.bodyModeSelector(0).click();
await expect(textItem).toBeVisible();

// Hover the last message's header — the one furthest under the open menu.
await websocket.message.header(total - 1).hover();
});

await test.step('Dropdown stays on top and is still clickable', async () => {
expect(await elementIsInsideDropdown(textItem)).toBe(true);
await textItem.click();
await expect(websocket.message.bodyModeLabel(0)).toContainText('TEXT');
});
});
});
Loading