From 13a9f9b8efda7268c9eaaf2c53712b41d584c016 Mon Sep 17 00:00:00 2001 From: sharan-bruno Date: Wed, 29 Apr 2026 11:19:43 +0530 Subject: [PATCH] Fix 1086: Even after clearing the response, the test count keeps on displaying on the tests tab (#7852) --- .../ReduxStore/slices/collections/index.js | 4 + tests/response/response-clearing.spec.ts | 117 ++++++++++++++++++ tests/utils/page/actions.ts | 44 ++++++- 3 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 tests/response/response-clearing.spec.ts diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index 574beefbb..23710c326 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -734,6 +734,10 @@ export const collectionsSlice = createSlice({ return; } item.response = null; + item.assertionResults = []; + item.preRequestTestResults = []; + item.postResponseTestResults = []; + item.testResults = []; } } }, diff --git a/tests/response/response-clearing.spec.ts b/tests/response/response-clearing.spec.ts new file mode 100644 index 000000000..472cc8669 --- /dev/null +++ b/tests/response/response-clearing.spec.ts @@ -0,0 +1,117 @@ +import { test, expect } from '../../playwright'; +import { + closeAllCollections, + createCollection, + createRequest, + sendRequest, + addAssertion, + addPreRequestScript, + addPostResponseScript, + addTestScript, + selectRequestPaneTab, + clickResponseAction, + selectResponsePaneTab +} from '../utils/page/actions'; +import { buildCommonLocators } from '../utils/page/locators'; + +test.describe('Response Clearing', () => { + test.afterEach(async ({ page }) => { + await closeAllCollections(page); + }); + + const getScripts = (mode: 'all-pass' | 'all-fail' | 'mixed') => { + if (mode === 'all-pass') { + return { + assertion: { expr: 'res.status', value: '200', operator: 'eq' }, + preRequest: `test('pre-request runs', () => { expect(1).to.equal(1); });`, + postResponse: `test('post-response runs', () => { expect(res.status).to.equal(200); });`, + testScript: `test('test script runs', () => { expect(res.status).to.equal(200); });` + }; + } + + if (mode === 'all-fail') { + return { + assertion: { expr: 'res.status', value: '201', operator: 'eq' }, + preRequest: `test('pre-request runs', () => { expect(11).to.equal(0); });`, + postResponse: `test('post-response runs', () => { expect(res.status).to.equal(201); });`, + testScript: `test('test script runs', () => { expect(res.status).to.equal(201); });` + }; + } + + // mixed: 2 pass + 2 fail + return { + assertion: { expr: 'res.status', value: '200', operator: 'eq' }, + preRequest: `test('pre-request runs', () => { expect(1).to.equal(0); });`, + postResponse: `test('post-response runs', () => { expect(res.status).to.equal(201); });`, + testScript: `test('test script runs', () => { expect(res.status).to.equal(200); });` + }; + }; + + const runScenario = (mode: 'all-pass' | 'all-fail' | 'mixed', expectedCount: string) => { + test(`should clear response and test results (${mode})`, async ({ + page, + createTmpDir + }) => { + const collectionName = `response-clear-${mode}`; + const requestName = `test-${mode}`; + + const scripts = getScripts(mode); + + await test.step('Setup collection and request', async () => { + await createCollection(page, collectionName, await createTmpDir(collectionName)); + await createRequest(page, requestName, collectionName, { + url: 'https://testbench-sanity.usebruno.com/ping' + }); + }); + + await test.step('Add assertion test', async () => { + await selectRequestPaneTab(page, 'Assert'); + + await addAssertion(page, scripts.assertion); + }); + + await test.step('Add pre-request script test', async () => { + await addPreRequestScript(page, scripts.preRequest); + }); + + await test.step('Add post-response script test', async () => { + await addPostResponseScript(page, scripts.postResponse); + }); + + await test.step('Add test script', async () => { + await addTestScript(page, scripts.testScript); + }); + + const locators = buildCommonLocators(page); + const testsTab = locators.response.pane().getByTestId('responsive-tab-tests'); + + await test.step('Send request and verify tests appear', async () => { + await sendRequest(page, 200); + + await locators.response.pane().waitFor({ state: 'visible' }); + + await selectResponsePaneTab(page, 'Tests'); + + await expect(testsTab).toBeVisible(); + + await expect(testsTab.locator('sup')).toHaveText(expectedCount); + }); + + await test.step('Clear response', async () => { + await clickResponseAction(page, 'response-clear-btn'); + }); + + await test.step('Verify all test results are cleared', async () => { + await selectResponsePaneTab(page, 'Tests'); + + await expect(testsTab).toBeVisible(); + await expect(testsTab.locator('sup')).toHaveCount(0); + }); + }); + }; + + // Run all scenarios + runScenario('all-pass', '4'); + runScenario('all-fail', '4'); + runScenario('mixed', '2'); +}); diff --git a/tests/utils/page/actions.ts b/tests/utils/page/actions.ts index 6be8a8bdc..8347d64b0 100644 --- a/tests/utils/page/actions.ts +++ b/tests/utils/page/actions.ts @@ -828,7 +828,10 @@ const selectPaneTab = async (page: Page, paneSelector: string, tabName: string) // Wait for dropdown to appear and click the menu item const dropdownItem = page.locator('.tippy-box .dropdown-item').filter({ hasText: tabName }); - await dropdownItem.click(); + await dropdownItem.waitFor({ state: 'visible' }); + + await page.waitForTimeout(50); + await dropdownItem.click({ force: true }); await expect(visibleTab).toContainClass('active'); return; } @@ -1127,6 +1130,42 @@ const editCodeMirrorEditor = async (page: Page, editorTestId: string, newContent }); }; +/** + * Add a pre-request script (navigates to Script > Pre Request and replaces editor content) + * @param page - The page object + * @param content - The script content to add + */ +const addPreRequestScript = async (page: Page, content: string) => { + await test.step('Add pre-request script', async () => { + await selectScriptSubTab(page, 'pre-request'); + await editCodeMirrorEditor(page, 'pre-request-script-editor', content); + }); +}; + +/** + * Add a post-response script (navigates to Script > Post Response and replaces editor content) + * @param page - The page object + * @param content - The script content to add + */ +const addPostResponseScript = async (page: Page, content: string) => { + await test.step('Add post-response script', async () => { + await selectScriptSubTab(page, 'post-response'); + await editCodeMirrorEditor(page, 'post-response-script-editor', content); + }); +}; + +/** + * Add a test script (navigates to Tests tab and replaces editor content) + * @param page - The page object + * @param content - The test script content to add + */ +const addTestScript = async (page: Page, content: string) => { + await test.step('Add test script', async () => { + await selectRequestPaneTab(page, 'Tests'); + await editCodeMirrorEditor(page, 'test-script-editor', content); + }); +}; + /** * Click send and wait for at least one error card to appear. * @param page - The page object @@ -1194,6 +1233,9 @@ export { switchWorkspace, selectScriptSubTab, editCodeMirrorEditor, + addPreRequestScript, + addPostResponseScript, + addTestScript, sendAndWaitForErrorCard, sendAndWaitForResponse };