|
1 | 1 | import { expect, test } from '../../playwright'; |
2 | | -import { closeAllCollections } from '../utils/page/actions'; |
3 | | - |
4 | | -const REQ_NAME = /^ws-default-body-request$/; |
| 2 | +import { closeAllTabs, createTransientRequest, selectRequestPaneTab } from '../utils/page/actions'; |
| 3 | +import { buildWebsocketCommonLocators } from '../utils/page/locators'; |
5 | 4 |
|
6 | 5 | test.describe('websocket message default body', () => { |
7 | | - test.afterAll(async ({ pageWithUserData: page }) => { |
8 | | - await closeAllCollections(page); |
| 6 | + test.afterEach(async ({ page }) => { |
| 7 | + await closeAllTabs(page); |
9 | 8 | }); |
10 | 9 |
|
11 | 10 | test('a newly added message defaults to an empty body showing the placeholder', async ({ |
12 | | - pageWithUserData: page |
| 11 | + page |
13 | 12 | }) => { |
14 | | - // Open the preloaded websocket request |
15 | | - await page.getByTestId('sidebar-collection-row').click(); |
16 | | - await page.getByTitle(REQ_NAME).click(); |
| 13 | + const ws = buildWebsocketCommonLocators(page); |
| 14 | + |
| 15 | + await createTransientRequest(page, { requestType: 'WebSocket' }); |
| 16 | + await selectRequestPaneTab(page, 'Message'); |
17 | 17 |
|
18 | | - const headers = page.getByTestId(/^ws-message-header-/); |
19 | | - const beforeCount = await headers.count(); |
| 18 | + const beforeCount = await ws.message.headers().count(); |
20 | 19 |
|
21 | | - await page.getByTestId('ws-add-message').click(); |
22 | | - await expect(headers).toHaveCount(beforeCount + 1); |
| 20 | + await ws.message.addButton().click(); |
| 21 | + await expect(ws.message.headers()).toHaveCount(beforeCount + 1); |
23 | 22 |
|
24 | 23 | // The newly added message is the last one and auto-expands. |
25 | | - const newBody = page.getByTestId(`ws-message-body-${beforeCount}`); |
26 | | - await expect(newBody).toBeVisible(); |
| 24 | + await expect(ws.message.body(beforeCount)).toBeVisible(); |
27 | 25 |
|
28 | | - const editor = newBody.locator('.CodeMirror'); |
29 | 26 | // Body should be empty (previously defaulted to '{}'); the editor should |
30 | 27 | // surface the '...' placeholder instead of any '{}' content. |
31 | | - await expect(editor.locator('.CodeMirror-placeholder')).toHaveText('...'); |
32 | | - await expect(editor.locator('.CodeMirror-code')).not.toContainText('{}'); |
| 28 | + await expect(ws.message.editorPlaceholder(beforeCount)).toHaveText('...'); |
| 29 | + await expect(ws.message.editorCode(beforeCount)).not.toContainText('{}'); |
| 30 | + }); |
| 31 | + |
| 32 | + test('the default first message of a newly created websocket request has an empty body', async ({ |
| 33 | + page |
| 34 | + }) => { |
| 35 | + const ws = buildWebsocketCommonLocators(page); |
| 36 | + |
| 37 | + await createTransientRequest(page, { requestType: 'WebSocket' }); |
| 38 | + await selectRequestPaneTab(page, 'Message'); |
| 39 | + |
| 40 | + // The default first message auto-expands. |
| 41 | + await expect(ws.message.body(0)).toBeVisible(); |
| 42 | + |
| 43 | + // Body must be empty (previously defaulted to '{}'); the editor should surface |
| 44 | + // the '...' placeholder rather than any '{}' content. |
| 45 | + await expect(ws.message.editorPlaceholder(0)).toHaveText('...'); |
| 46 | + await expect(ws.message.editorCode(0)).not.toContainText('{}'); |
33 | 47 | }); |
34 | 48 | }); |
0 commit comments