mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-12 10:21:30 +00:00
92 lines
4.0 KiB
TypeScript
92 lines
4.0 KiB
TypeScript
import { test, expect } from '../../../playwright';
|
|
import { buildWebsocketCommonLocators } from '../../utils/page/locators';
|
|
import { closeAllCollections, openCollection } from '../../utils/page';
|
|
|
|
const BRU_REQ_NAME = /^ws-interpolation-test$/;
|
|
const MAX_CONNECTION_TIME = 10000; // Increased timeout for external server
|
|
|
|
test.describe.serial('WebSocket Variable Interpolation', () => {
|
|
test.afterAll(async ({ pageWithUserData: page }) => {
|
|
await closeAllCollections(page);
|
|
});
|
|
|
|
test('interpolates variables in WebSocket URL', async ({ pageWithUserData: page, restartApp }) => {
|
|
const locators = buildWebsocketCommonLocators(page);
|
|
|
|
// Open the collection and accept sandbox modal if it appears
|
|
await openCollection(page, 'variable-interpolation');
|
|
|
|
// Open the request
|
|
await expect(page.getByTitle(BRU_REQ_NAME)).toBeVisible();
|
|
await page.getByTitle(BRU_REQ_NAME).click();
|
|
|
|
// Select the test environment (which has url: websocket)
|
|
await page.locator('div.current-environment').click();
|
|
await expect(page.locator('.dropdown-item').filter({ hasText: 'Test' })).toBeVisible();
|
|
await page.locator('.dropdown-item').filter({ hasText: 'Test' }).click();
|
|
await expect(page.locator('.current-environment').filter({ hasText: /Test/ })).toBeVisible();
|
|
|
|
// Connect WebSocket
|
|
await locators.connectionControls.connect().click();
|
|
|
|
// Wait for connection to establish
|
|
await expect(locators.connectionControls.disconnect()).toBeAttached({
|
|
timeout: MAX_CONNECTION_TIME
|
|
});
|
|
|
|
// Verify the connection message shows interpolated URL
|
|
// The URL should be wss://echo.websocket.org (not wss://echo.{{url}}.org)
|
|
await expect(locators.messages().first().getByText(/Connected to wss:\/\/echo\.websocket\.org/)).toBeAttached({
|
|
timeout: 2000
|
|
});
|
|
});
|
|
|
|
test('interpolates variables in WebSocket message content', async ({ pageWithUserData: page, restartApp }) => {
|
|
const locators = buildWebsocketCommonLocators(page);
|
|
|
|
// Wait for collection to be visible (it should auto-load from preferences)
|
|
await expect(page.locator('#sidebar-collection-name').filter({ hasText: 'variable-interpolation' })).toBeVisible({ timeout: 5000 });
|
|
|
|
// Click to expand the collection
|
|
await page.locator('#sidebar-collection-name').filter({ hasText: 'variable-interpolation' }).click();
|
|
|
|
// Open the request
|
|
await expect(page.getByTitle(BRU_REQ_NAME)).toBeVisible();
|
|
await page.getByTitle(BRU_REQ_NAME).click();
|
|
|
|
// Select the test environment (which has data: test-data)
|
|
await page.locator('div.current-environment').click();
|
|
await expect(page.locator('.dropdown-item').filter({ hasText: 'Test' })).toBeVisible();
|
|
await page.locator('.dropdown-item').filter({ hasText: 'Test' }).click();
|
|
await expect(page.locator('.current-environment').filter({ hasText: /Test/ })).toBeVisible();
|
|
|
|
// Clear any previous messages
|
|
await locators.toolbar.clearResponse().click();
|
|
|
|
// Send the request (connect + send messages)
|
|
await locators.runner().click();
|
|
|
|
// Wait for connection
|
|
await expect(locators.connectionControls.disconnect()).toBeAttached({
|
|
timeout: MAX_CONNECTION_TIME
|
|
});
|
|
|
|
// Verify the sent message contains interpolated value
|
|
// Should send {"test": "test-data"} (not {"test": "{{data}}"})
|
|
const messages = locators.messages();
|
|
|
|
// Find the outgoing message with interpolated content
|
|
// The echo server will echo back the same message, so we should see it twice
|
|
const sentMessage = messages.filter({ hasText: 'test-data' }).first();
|
|
await expect(sentMessage).toBeAttached({ timeout: MAX_CONNECTION_TIME });
|
|
|
|
// Verify the message content shows interpolated value, not literal variable
|
|
const messageContent = sentMessage.locator('.text-ellipsis');
|
|
await expect(messageContent).toContainText('test-data');
|
|
await expect(messageContent).not.toContainText('{{data}}');
|
|
|
|
// Verify JSON structure is correct
|
|
await expect(messageContent).toContainText('"test"');
|
|
});
|
|
});
|