mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
Fix 1086: Even after clearing the response, the test count keeps on displaying on the tests tab (#7852)
This commit is contained in:
@@ -734,6 +734,10 @@ export const collectionsSlice = createSlice({
|
||||
return;
|
||||
}
|
||||
item.response = null;
|
||||
item.assertionResults = [];
|
||||
item.preRequestTestResults = [];
|
||||
item.postResponseTestResults = [];
|
||||
item.testResults = [];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
117
tests/response/response-clearing.spec.ts
Normal file
117
tests/response/response-clearing.spec.ts
Normal file
@@ -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');
|
||||
});
|
||||
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user