mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-24 13:15:40 +00:00
Updated the test cases to utilize a constant for the BRU_FILE_NAME regex pattern for better maintainability and readability.
70 lines
2.6 KiB
TypeScript
70 lines
2.6 KiB
TypeScript
import { expect, test } from '../../playwright';
|
|
import { buildCommonLocators } from './lib/locators';
|
|
|
|
const MAX_CONNECTION_TIME = 3000;
|
|
const BRU_FILE_NAME = /^ws-test-request$/
|
|
|
|
test.describe.serial('websockets', () => {
|
|
test.setTimeout(2 * 10 * 1000);
|
|
test('websocket requests are visible', async ({ pageWithUserData: page, restartApp }) => {
|
|
await page.locator('#sidebar-collection-name').click();
|
|
|
|
expect(page.locator('span.item-name').filter({ hasText: BRU_FILE_NAME })).toBeVisible();
|
|
});
|
|
|
|
test('websocket connects', async ({ pageWithUserData: page, restartApp }) => {
|
|
const locators = buildCommonLocators(page);
|
|
|
|
await page.getByTitle(BRU_FILE_NAME).click();
|
|
await locators.connectionControls.connect().click();
|
|
|
|
await expect(locators.connectionControls.disconnect()).toBeAttached({
|
|
timeout: MAX_CONNECTION_TIME
|
|
});
|
|
});
|
|
|
|
test('websocket closes', async ({ pageWithUserData: page, restartApp }) => {
|
|
const locators = buildCommonLocators(page);
|
|
await locators.connectionControls.disconnect().click();
|
|
|
|
await expect(locators.connectionControls.connect()).toBeVisible();
|
|
});
|
|
|
|
test('websocket messages were recorded', async ({ pageWithUserData: page, restartApp }) => {
|
|
const locators = buildCommonLocators(page);
|
|
|
|
const messages = await locators.messages();
|
|
|
|
expect(messages[0].getByText('Connected to ws://')).toBeAttached();
|
|
expect(messages[1].getByText('Closed')).toBeAttached();
|
|
});
|
|
|
|
test('websocket messages sorting can be changed', async ({ pageWithUserData: page, restartApp }) => {
|
|
const locators = buildCommonLocators(page);
|
|
|
|
await locators.toolbar.latestLast().click();
|
|
|
|
const messages = await locators.messages();
|
|
expect(messages[0].getByText('Closed')).toBeAttached();
|
|
expect(messages[1].getByText('Connected to ws://')).toBeAttached();
|
|
|
|
await locators.toolbar.latestFirst().click();
|
|
const messagesReset = await locators.messages();
|
|
expect(messagesReset[0].getByText('Connected to ws://')).toBeAttached();
|
|
expect(messagesReset[1].getByText('Closed')).toBeAttached();
|
|
});
|
|
|
|
test('websocket request can send messages', async ({ pageWithUserData: page, restartApp }) => {
|
|
const locators = buildCommonLocators(page);
|
|
|
|
await locators.toolbar.clearResponse().click();
|
|
await locators.runner().click();
|
|
|
|
const messages = await locators.messages();
|
|
|
|
expect(await messages[1].locator('.text-ellipsis').innerText()).toMatch('{ "foo": "bar" }');
|
|
|
|
expect(await messages[2].locator('.text-ellipsis').innerText()).toMatch('{ "data": { "foo": "bar" } }');
|
|
});
|
|
});
|