Files
InvenTree/src/frontend/tests/pui_exporting.spec.ts
T
Matthias Mair 879d52041f Fix flaky test (#13038)
* fix machine driver

* fix flaky output tests
2026-10-19 07:21:52 +11:00

140 lines
4.5 KiB
TypeScript

import { test } from './baseFixtures';
import { stevenuser } from './defaults';
import { globalSearch, loadTab, navigate, waitForDataOutput } from './helpers';
import { doCachedLogin } from './login';
// Helper function to open the export data dialog
const openExportDialog = async (page) => {
await page.waitForLoadState('networkidle');
await page.getByRole('button', { name: 'table-export-data' }).click();
await page.getByText('Export Format *', { exact: true }).waitFor();
await page.getByText('Export Plugin *', { exact: true }).waitFor();
};
// Test data export for various order types
test('Exporting - Orders', async ({ browser }) => {
const page = await doCachedLogin(browser, {
user: stevenuser,
url: 'purchasing/index/purchase-orders'
});
await openExportDialog(page);
// // Select export format
await page.getByLabel('choice-field-export_format').click();
await page.getByRole('option', { name: 'Excel' }).click();
// // Select export plugin (should only be one option here)
await page.getByLabel('choice-field-export_plugin').click();
await page.getByRole('option', { name: 'InvenTree Exporter' }).click();
// // Export the data
await waitForDataOutput(page, () =>
page.getByRole('button', { name: 'Export', exact: true }).click()
);
// Download list of purchase order items
await page.getByRole('cell', { name: 'PO0014' }).click();
// Click through to the PurchaseOrder from the detail tab
await page
.getByLabel('Purchase Order PO0014 (PCBWOY)')
.getByRole('cell', { name: 'Ordering some PCBs' })
.waitFor();
await page
.getByRole('link', { name: 'details-purchaseorder-14' })
.first()
.click();
await loadTab(page, 'Line Items');
await openExportDialog(page);
await waitForDataOutput(page, () =>
page.getByRole('button', { name: 'Export', exact: true }).click()
);
// Download a list of build orders
await navigate(page, 'manufacturing/index/buildorders/');
await openExportDialog(page);
await waitForDataOutput(page, () =>
page.getByRole('button', { name: 'Export', exact: true }).click()
);
// Finally, navigate to the admin center and ensure the export data is available
await navigate(page, 'settings/admin/export/');
// Check for expected outputs
await page
.getByRole('link', { name: /InvenTree_Build_.*\.csv/ })
.first()
.waitFor();
await page
.getByRole('link', { name: /InvenTree_PurchaseOrder_.*\.xlsx/ })
.first()
.waitFor();
await page
.getByRole('link', { name: /InvenTree_PurchaseOrderLineItem_.*\.csv/ })
.first()
.waitFor();
// Delete all exported file outputs
await page.getByRole('checkbox', { name: 'Select all records' }).check();
await page.getByLabel('action-button-delete-selected').click();
await page.getByRole('button', { name: 'Delete', exact: true }).click();
await page.getByText('Items Deleted').waitFor();
});
// Test for custom BOM exporter
test('Exporting - BOM', async ({ browser }) => {
const page = await doCachedLogin(browser, {
user: stevenuser
});
await globalSearch(page, 'MAST');
await page.getByLabel('search-group-results-part').locator('a').click();
await page.waitForLoadState('networkidle');
await loadTab(page, 'Bill of Materials');
await openExportDialog(page);
// Select export format
await page.getByLabel('choice-field-export_format').click();
await page.getByRole('option', { name: 'TSV' }).click();
await page.waitForLoadState('networkidle');
// Select BOM plugin
await page.getByLabel('choice-field-export_plugin').click();
await page.getByRole('option', { name: 'BOM Exporter' }).click();
await page.waitForLoadState('networkidle');
// Now, adjust the settings specific to the BOM exporter
await page.getByLabel('number-field-export_levels').fill('3');
await page
.locator('label')
.filter({ hasText: 'Pricing DataInclude part' })
.locator('span')
.nth(1)
.click();
await page
.locator('label')
.filter({ hasText: 'Parameter DataInclude part' })
.locator('span')
.nth(1)
.click();
await waitForDataOutput(page, () =>
page.getByRole('button', { name: 'Export', exact: true }).click()
);
// Finally, navigate to the admin center and ensure the export data is available
await navigate(page, 'settings/admin/export/');
await page.getByRole('cell', { name: 'bom-exporter' }).first().waitFor();
await page
.getByRole('link', { name: /InvenTree_BomItem_.*\.tsv/ })
.first()
.waitFor();
// Required because we downloaded a file
await page.context().close();
});