mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-18 14:07:41 +00:00
Add CI checks for /api-doc/ endpoint (#13210)
* Add CI checks for /api-doc/ endpoint Ref: https://github.com/inventree/InvenTree/issues/13200 * fix playwright test * Reduce flakiness
This commit is contained in:
1 parent
3866f7dbf5
commit
df2a5d853e
3 files changed
+110
-12
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { type Page, expect } from '@playwright/test';
|
||||
import { type Locator, type Page, expect } from '@playwright/test';
|
||||
import { createApi } from './api';
|
||||
|
||||
export const clickOnParamFilter = async (page: Page, name: string) => {
|
||||
@@ -117,6 +117,31 @@ export const navigate = async (
|
||||
await page.goto(path, { waitUntil: options?.waitUntil ?? 'load' });
|
||||
};
|
||||
|
||||
/**
|
||||
* Ctrl+click a link, and return the new tab which it opens (in the same browser context).
|
||||
*
|
||||
* A modified click occasionally fails to open a new tab in CI - so the
|
||||
* click is retried (with a short per-attempt timeout) rather than
|
||||
* waiting for the entire test timeout on a single attempt.
|
||||
*/
|
||||
export const openInNewTab = async (
|
||||
page: Page,
|
||||
link: Locator,
|
||||
url: string | RegExp
|
||||
): Promise<Page> => {
|
||||
const context = page.context();
|
||||
let popup: Page | undefined;
|
||||
|
||||
await expect(async () => {
|
||||
const popupPromise = context.waitForEvent('page', { timeout: 5000 });
|
||||
await link.click({ modifiers: ['ControlOrMeta'], timeout: 5000 });
|
||||
popup = await popupPromise;
|
||||
}).toPass({ timeout: 30000 });
|
||||
|
||||
await popup!.waitForURL(url);
|
||||
return popup!;
|
||||
};
|
||||
|
||||
/**
|
||||
* CLick on the 'tab' element with the provided name
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect, test } from './baseFixtures.js';
|
||||
import { adminuser, stevenuser } from './defaults.js';
|
||||
import { globalSearch } from './helpers.js';
|
||||
import { adminuser, apiUrl, stevenuser } from './defaults.js';
|
||||
import { globalSearch, openInNewTab } from './helpers.js';
|
||||
import { doCachedLogin } from './login.js';
|
||||
|
||||
/**
|
||||
@@ -45,10 +45,7 @@ test('General - Search', async ({ browser }) => {
|
||||
.first();
|
||||
await expect(customerResult).toHaveAttribute('href', /\/web\/company\/\d+/);
|
||||
|
||||
const popupPromise = page.context().waitForEvent('page');
|
||||
await customerResult.click({ modifiers: ['Control'] });
|
||||
const popup = await popupPromise;
|
||||
await popup.waitForURL('**/web/company/**');
|
||||
const popup = await openInNewTab(page, customerResult, '**/web/company/**');
|
||||
await popup.close();
|
||||
|
||||
// Click through to the "Customer" results
|
||||
@@ -60,10 +57,9 @@ test('General - Search', async ({ browser }) => {
|
||||
/\/web\/sales\/index\/customers\?search=another\+customer/
|
||||
);
|
||||
|
||||
const overviewPopupPromise = page.context().waitForEvent('page');
|
||||
await viewAllCustomers.click({ modifiers: ['Control'] });
|
||||
const overviewPopup = await overviewPopupPromise;
|
||||
await overviewPopup.waitForURL(
|
||||
const overviewPopup = await openInNewTab(
|
||||
page,
|
||||
viewAllCustomers,
|
||||
'**/web/sales/index/customers?search=another+customer'
|
||||
);
|
||||
await overviewPopup.close();
|
||||
@@ -92,3 +88,36 @@ test('General - Search', async ({ browser }) => {
|
||||
await page.waitForURL('**/purchasing/index/manufacturer-parts**');
|
||||
await page.getByRole('cell', { name: 'RT0402BRD07100KL' }).waitFor();
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that the API documentation page actually renders.
|
||||
*
|
||||
* The /api-doc/ view is a thin HTML shell which loads Redoc from a CDN;
|
||||
* a 200 response does not mean that the documentation is displayed.
|
||||
* Ref: https://github.com/inventree/InvenTree/issues/13200
|
||||
*/
|
||||
test('General - API Documentation', async ({ browser }) => {
|
||||
const page = await doCachedLogin(browser, {
|
||||
user: stevenuser
|
||||
});
|
||||
|
||||
const errors: string[] = [];
|
||||
page.on('pageerror', (error) => errors.push(error.message));
|
||||
|
||||
// Note: api-doc page is not forwarded to port 5173
|
||||
const docUrl = new URL('http://localhost:8000/api-doc/', apiUrl).toString();
|
||||
const response = await page.goto(docUrl);
|
||||
await page.waitForLoadState('networkidle');
|
||||
expect(response?.status()).toBe(200);
|
||||
|
||||
// Redoc renders the schema title and the generated API endpoints
|
||||
await page
|
||||
.getByRole('heading', { name: /InvenTree API/ })
|
||||
.first()
|
||||
.waitFor({ timeout: 30000 });
|
||||
|
||||
await page.getByText('Download OpenAPI specification').first().waitFor();
|
||||
await page.getByText('/api/part/', { exact: false }).first().waitFor();
|
||||
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
Reference in new issue
Block a user