2022-09-09 14:53:28 +00:00
|
|
|
import { expect } from '@playwright/test';
|
|
|
|
|
2022-10-11 08:56:12 +00:00
|
|
|
import { loadFixture } from '../../playwright/paths';
|
|
|
|
import { test } from '../../playwright/test';
|
2022-09-09 14:53:28 +00:00
|
|
|
|
|
|
|
test('can make websocket connection', async ({ app, page }) => {
|
|
|
|
test.slow(process.platform === 'darwin' || process.platform === 'win32', 'Slow app start on these platforms');
|
|
|
|
const statusTag = page.locator('[data-testid="response-status-tag"]:visible');
|
|
|
|
const responseBody = page.locator('[data-testid="response-pane"] >> [data-testid="CodeEditor"]:visible', {
|
|
|
|
has: page.locator('.CodeMirror-activeline'),
|
|
|
|
});
|
|
|
|
|
2023-08-28 13:53:37 +00:00
|
|
|
await page.getByRole('button', { name: 'Create in project' }).click();
|
2022-09-09 14:53:28 +00:00
|
|
|
|
|
|
|
const text = await loadFixture('websockets.yaml');
|
|
|
|
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
|
|
|
|
|
2023-08-28 13:53:37 +00:00
|
|
|
await page.getByRole('menuitemradio', { name: 'Import' }).click();
|
2023-03-31 10:53:22 +00:00
|
|
|
await page.getByText('Clipboard').click();
|
|
|
|
await page.getByRole('button', { name: 'Scan' }).click();
|
2023-06-27 18:46:43 +00:00
|
|
|
await page.getByRole('dialog').getByRole('button', { name: 'Import' }).click();
|
2023-06-27 15:43:51 +00:00
|
|
|
await page.getByText('CollectionWebSocketsjust now').click();
|
2022-09-09 14:53:28 +00:00
|
|
|
|
2023-08-22 16:12:29 +00:00
|
|
|
await page.getByLabel('Request Collection').getByRole('row', { name: 'localhost:4010' }).click();
|
2022-11-08 10:50:53 +00:00
|
|
|
await expect(page.locator('.app')).toContainText('ws://localhost:4010');
|
2022-09-09 14:53:28 +00:00
|
|
|
await page.click('text=Connect');
|
|
|
|
await expect(statusTag).toContainText('101 Switching Protocols');
|
2023-01-20 14:49:52 +00:00
|
|
|
await page.getByRole('tab', { name: 'Timeline' }).click();
|
2022-09-09 14:53:28 +00:00
|
|
|
await expect(responseBody).toContainText('WebSocket connection established');
|
|
|
|
await page.click('text=Disconnect');
|
|
|
|
await expect(responseBody).toContainText('Closing connection with code 1005');
|
|
|
|
|
|
|
|
// Can connect with Basic Auth
|
2023-08-22 16:12:29 +00:00
|
|
|
await page.getByLabel('Request Collection').getByRole('row', { name: 'basic-auth' }).click();
|
2022-11-08 10:50:53 +00:00
|
|
|
await expect(page.locator('.app')).toContainText('ws://localhost:4010/basic-auth');
|
2022-09-09 14:53:28 +00:00
|
|
|
await page.click('text=Connect');
|
|
|
|
await expect(statusTag).toContainText('101 Switching Protocols');
|
2023-01-20 14:49:52 +00:00
|
|
|
await page.getByRole('tab', { name: 'Timeline' }).click();
|
2022-09-09 14:53:28 +00:00
|
|
|
await expect(responseBody).toContainText('> authorization: Basic dXNlcjpwYXNzd29yZA==');
|
|
|
|
|
|
|
|
// Can connect with Bearer Auth
|
2023-08-22 16:12:29 +00:00
|
|
|
await page.getByLabel('Request Collection').getByRole('row', { name: 'bearer' }).click();
|
2022-11-08 10:50:53 +00:00
|
|
|
await expect(page.locator('.app')).toContainText('ws://localhost:4010/bearer');
|
2022-09-09 14:53:28 +00:00
|
|
|
await page.click('text=Connect');
|
|
|
|
await expect(statusTag).toContainText('101 Switching Protocols');
|
2023-01-20 14:49:52 +00:00
|
|
|
await page.getByRole('tab', { name: 'Timeline' }).click();
|
2022-09-09 14:53:28 +00:00
|
|
|
await expect(responseBody).toContainText('> authorization: Bearer insomnia-cool-token-!!!1112113243111');
|
|
|
|
|
|
|
|
// Can handle redirects
|
2023-08-22 16:12:29 +00:00
|
|
|
await page.getByLabel('Request Collection').getByRole('row', { name: 'redirect' }).click();
|
2022-11-08 10:50:53 +00:00
|
|
|
await expect(page.locator('.app')).toContainText('ws://localhost:4010/redirect');
|
2022-09-09 14:53:28 +00:00
|
|
|
await page.click('text=Connect');
|
|
|
|
await expect(statusTag).toContainText('101 Switching Protocols');
|
2023-01-20 14:49:52 +00:00
|
|
|
await page.getByRole('tab', { name: 'Timeline' }).click();
|
2022-09-09 14:53:28 +00:00
|
|
|
await expect(responseBody).toContainText('WebSocket connection established');
|
|
|
|
|
2022-10-04 13:49:41 +00:00
|
|
|
const webSocketActiveConnections = page.locator('[data-testid="WebSocketSpinner__Connected"]');
|
|
|
|
|
|
|
|
// Basic auth, Bearer auth, and Redirect connections are displayed as open
|
|
|
|
await expect(webSocketActiveConnections).toHaveCount(3);
|
|
|
|
|
|
|
|
// Can disconnect from all connections
|
|
|
|
await page.locator('button[name="DisconnectDropdown__DropdownButton"]').click();
|
2023-01-20 14:49:52 +00:00
|
|
|
await page.getByRole('menuitem', { name: 'Disconnect all requests' }).click();
|
2022-10-04 13:49:41 +00:00
|
|
|
await expect(webSocketActiveConnections).toHaveCount(0);
|
2022-09-09 14:53:28 +00:00
|
|
|
});
|