Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -23,14 +23,11 @@ const StyledWrapper = styled.div`
}
}

&:not(.disabled) .accordion-header {
.accordion-header {
position: sticky;
top: 0;
z-index: 1;
background: ${(props) => props.theme.bg};
}

.accordion-header {
display: flex;
align-items: center;
justify-content: space-between;
Expand Down
2 changes: 1 addition & 1 deletion packages/bruno-lang/v2/src/jsonToBru.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ ${indentString(body.sparql)}
}

// Convert content to JSON string if it's an object
let contentValue = typeof content === 'object' ? JSON.stringify(content, null, 2) : content || '{}';
let contentValue = typeof content === 'object' ? JSON.stringify(content, null, 2) : content || '';

// Wrap content with triple quotes for multiline support, without extra indentation
bru += `${indentString(`content: '''\n${indentString(contentValue)}\n'''`)}\n`;
Expand Down
8 changes: 7 additions & 1 deletion tests/utils/page/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1653,11 +1653,17 @@ const closeAllTabs = async (page: Page) => {
// Click "Close All" menu item
await dropdown.locator('[role="menuitem"][data-item-id="close-all"]').click();

// Handle "Unsaved Transient Requests" modal if it appears
// Handle "Unsaved Transient Requests" modal if it appears (multiple transient requests)
const discardAllButton = page.getByRole('button', { name: 'Discard All' });
if (await discardAllButton.isVisible({ timeout: 1000 }).catch(() => false)) {
await discardAllButton.click();
}

const saveTransientModal = page.getByTestId('save-transient-request-modal');
if (await saveTransientModal.isVisible({ timeout: 1000 }).catch(() => false)) {
await saveTransientModal.getByRole('button', { name: 'Cancel' }).click();
await expect(saveTransientModal).toBeHidden();
}
});
};

Expand Down
9 changes: 8 additions & 1 deletion tests/utils/page/locators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,16 @@ export const buildWebsocketCommonLocators = (page: Page) => ({
},
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}`),
label: (index: number) => page.getByTestId(`ws-message-label-${index}`),
nameInput: (index: number) => page.getByTestId(`ws-message-name-input-${index}`),
nameTooltip: () => page.getByTestId('ws-message-name-tooltip')
nameTooltip: () => page.getByTestId('ws-message-name-tooltip'),
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' }),
Expand Down
46 changes: 32 additions & 14 deletions tests/websockets/message-body-default.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import { expect, test } from '../../playwright';
import { closeAllCollections } from '../utils/page/actions';

const REQ_NAME = /^ws-default-body-request$/;
import { closeAllTabs, createTransientRequest, selectRequestPaneTab } from '../utils/page/actions';
import { buildWebsocketCommonLocators } from '../utils/page/locators';

test.describe('websocket message default body', () => {
test.afterAll(async ({ pageWithUserData: page }) => {
await closeAllCollections(page);
test.afterEach(async ({ page }) => {
await closeAllTabs(page);
});

test('a newly added message defaults to an empty body showing the placeholder', async ({
pageWithUserData: page
page
}) => {
// Open the preloaded websocket request
await page.getByTestId('sidebar-collection-row').click();
await page.getByTitle(REQ_NAME).click();
const ws = buildWebsocketCommonLocators(page);

await createTransientRequest(page, { requestType: 'WebSocket' });
await selectRequestPaneTab(page, 'Message');

const headers = page.getByTestId(/^ws-message-header-/);
const beforeCount = await headers.count();
const beforeCount = await ws.message.headers().count();

await page.getByTestId('ws-add-message').click();
await expect(headers).toHaveCount(beforeCount + 1);
await ws.message.addButton().click();
await expect(ws.message.headers()).toHaveCount(beforeCount + 1);

// The newly added message is the last one and auto-expands.
const newBody = page.getByTestId(`ws-message-body-${beforeCount}`);
const newBody = ws.message.body(beforeCount);
await expect(newBody).toBeVisible();

const editor = newBody.locator('.CodeMirror');
Expand All @@ -31,4 +30,23 @@ test.describe('websocket message default body', () => {
await expect(editor.locator('.CodeMirror-placeholder')).toHaveText('...');
await expect(editor.locator('.CodeMirror-code')).not.toContainText('{}');
});

test('the default first message of a newly created websocket request has an empty body', async ({
page
}) => {
const ws = buildWebsocketCommonLocators(page);

await createTransientRequest(page, { requestType: 'WebSocket' });
await selectRequestPaneTab(page, 'Message');

// The default first message auto-expands.
const body = ws.message.body(0);
await expect(body).toBeVisible();

const editor = body.locator('.CodeMirror');
// Body must be empty (previously defaulted to '{}'); the editor should surface
// the '...' placeholder rather than any '{}' content.
await expect(editor.locator('.CodeMirror-placeholder')).toHaveText('...');
Comment thread
sid-bruno marked this conversation as resolved.
Resolved
await expect(editor.locator('.CodeMirror-code')).not.toContainText('{}');
});
});
Loading