mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 14:35:03 +00:00
fix(openapi):validate API spec imports (#8322)
* fix(openapi):validate API spec imports and resolve preview to error state instead of hanging * fix(openapi):allows opening of malformed files with correct extension * fix(openapi):reject non-OpenAPI content in spec preview before timeout * test(openapi): add unit + e2e coverage for spec import validation * refactor(openapi):centralise spec error messages and fix dialog restore * fix:removed nested try catch * test:added common locators * refactor:removed repeated lines * refactor:removed redundant file reads --------- Co-authored-by: Adwait Aayush <adwaitaayush@Adwaits-MacBook-Air.local>
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import { Page, Locator } from '../../../playwright';
|
||||
import { buildApiSpecPanelLocators } from './openapi/render-spec';
|
||||
|
||||
export const buildCommonLocators = (page: Page) => ({
|
||||
runner: () => page.getByTestId('run-button'),
|
||||
openApi: {
|
||||
render: buildApiSpecPanelLocators(page)
|
||||
},
|
||||
saveButton: () => page
|
||||
.locator('.infotip')
|
||||
.filter({ hasText: /^Save/ }),
|
||||
|
||||
30
tests/utils/page/openapi/render-spec.ts
Normal file
30
tests/utils/page/openapi/render-spec.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { test, Page, ElectronApplication } from '../../../../playwright';
|
||||
|
||||
export const buildApiSpecPanelLocators = (page: Page) => ({
|
||||
addMenuButton: () => page.getByTestId('api-specs-header-add-menu'),
|
||||
openApiSpecMenuItem: () => page.getByTestId('api-specs-header-add-menu-open-api-spec'),
|
||||
sidebarItem: (name: string) => page.locator('.api-spec-item').filter({ hasText: name })
|
||||
});
|
||||
|
||||
export const openApiSpecFromDialog = async (
|
||||
page: Page,
|
||||
electronApp: ElectronApplication,
|
||||
filePath: string
|
||||
): Promise<void> => {
|
||||
await test.step(`Open API spec from path: ${filePath}`, async () => {
|
||||
await electronApp.evaluate(({ dialog }, filePath) => {
|
||||
dialog.showOpenDialog = async () => ({ canceled: false, filePaths: [filePath] });
|
||||
}, filePath);
|
||||
|
||||
const { addMenuButton, openApiSpecMenuItem } = buildApiSpecPanelLocators(page);
|
||||
await addMenuButton().click();
|
||||
await openApiSpecMenuItem().click();
|
||||
});
|
||||
};
|
||||
|
||||
export const openApiSpecSidebarItem = async (page: Page, name: string): Promise<void> => {
|
||||
await test.step(`Open API spec sidebar item "${name}"`, async () => {
|
||||
const { sidebarItem } = buildApiSpecPanelLocators(page);
|
||||
await sidebarItem(name).click();
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user