update export

This commit is contained in:
2026-11-11 10:48:31 +07:00
parent 00122e5b4a
commit 03a481f20d
7 changed files with 741 additions and 90 deletions

View File

@@ -37,7 +37,7 @@ class Browser {
}
}
test('Chrome submits project export proposals, approves/rejects, isolates creators and displays saved files on desktop/mobile', {
test('Chrome preserves project export proposals and supports immediate manager exports for others on desktop/mobile', {
skip: process.env.ACCMANAGER_EXPORT_BROWSER_TEST !== '1' ? 'Set ACCMANAGER_EXPORT_BROWSER_TEST=1 for isolated Chrome and SQL checks' : false,
timeout: 120000
}, async () => {
@@ -49,6 +49,9 @@ test('Chrome submits project export proposals, approves/rejects, isolates creato
f.app.get('/api/asset-projects', (_req, res) => res.json({ success: true, data: [
{ ProjectId: 1, ProjectName: 'Dự án A' }, { ProjectId: 2, ProjectName: 'Dự án B' }
] }));
f.app.get('/api/users', (_req, res) => res.json({ success: true, data: [
{ UserId: 1, FullName: 'Nguyễn An' }, { UserId: 2, FullName: 'Trần Bình' }, { UserId: 3, FullName: 'Quản lý kho' }
] }));
f.app.use('/api', (_req, res) => res.json({ success: true, data: [], unreadCount: 0, pagination: { total: 0, totalPages: 1 } }));
f.app.get('/test-xlsx.js', (_req, res) => res.sendFile(require.resolve('xlsx/dist/xlsx.full.min.js')));
f.app.get('/test-notiflix.js', (_req, res) => res.type('js').send('window.Notiflix={Notify:{init(){},success(){},failure(){},warning(){}}};'));
@@ -71,6 +74,7 @@ test('Chrome submits project export proposals, approves/rejects, isolates creato
await client.send('Emulation.setDeviceMetricsOverride', { width: 1600, height: 1050, deviceScaleFactor: 1, mobile: false });
await client.send('Page.navigate', { url: `${f.origin}/pages/index.html#assets` });
await client.until('typeof app !== "undefined" && app?.assets?.length === 3 && !!document.getElementById("borrowAssetBtn")');
assert.equal(await client.evaluate('!!document.getElementById("exportAssetForOthersBtn")'), false);
await client.evaluate(`document.querySelector('.asset-row-checkbox[data-asset-id="1"]').click(); document.getElementById('borrowAssetBtn').click()`);
await client.until('document.getElementById("borrowAssetModal").classList.contains("open")');
assert.equal(await client.evaluate('document.getElementById("borrowAssetUserInput").value'), 'Nguyễn An');
@@ -122,7 +126,57 @@ test('Chrome submits project export proposals, approves/rejects, isolates creato
await client.send('Page.reload');
await client.until('typeof app !== "undefined" && app?.currentUser?.UserId === 2 && !app.assetExportLoading && !!document.getElementById("assetExportsTableBody")');
assert.equal(await client.evaluate('app.assetExportRequests.length'), 0);
assert.equal(await client.evaluate('!!document.getElementById("createAssetExportForOthersBtn")'), false);
// The additional manager action exports immediately; the proposal action remains available.
await client.send('Network.setExtraHTTPHeaders', { headers: { 'x-test-user': '3', 'x-test-role': 'admin' } });
await client.send('Page.reload');
await client.until('typeof app !== "undefined" && app?.currentUser?.Role === "admin" && !!document.getElementById("createAssetExportForOthersBtn")');
await client.evaluate('document.getElementById("createAssetExportForOthersBtn").click()');
await client.until('typeof app !== "undefined" && app?.currentUser?.Role === "admin" && app.assets.length === 3 && !!document.getElementById("exportAssetForOthersBtn")');
await client.evaluate(`app.downloadBlobFile=(blob,name)=>{window.savedDownload={size:blob.size,name}}; document.querySelector('.asset-row-checkbox[data-asset-id="1"]').click(); document.getElementById('exportAssetForOthersBtn').click()`);
await client.until('document.getElementById("borrowAssetModal").classList.contains("open")');
assert.equal(await client.evaluate('document.getElementById("borrowAssetRecipientInput").required'), true);
assert.equal(await client.evaluate('document.getElementById("borrowAssetRequesterField").hidden'), true);
await client.evaluate('document.getElementById("borrowAssetRecipientInput").value="Trần Bình"; document.getElementById("borrowAssetProjectInput").value="Dự án A"; const quantity=document.getElementById("borrowQuantityInput"); quantity.value="2"; quantity.dispatchEvent(new Event("input",{bubbles:true})); document.querySelector("#borrowAssetForm button[type=submit]").scrollIntoView({block:"nearest"})');
await delay(250);
assert.equal(await client.evaluate('document.querySelector("#borrowAssetForm button[type=submit]").getBoundingClientRect().bottom <= innerHeight'), true);
assert.equal(await client.evaluate('document.documentElement.scrollWidth <= innerWidth + 1'), true);
await client.send('Page.captureScreenshot', { format: 'png' }).then(result => fs.writeFileSync(path.join(output, 'export-for-others-mobile.png'), Buffer.from(result.data, 'base64')));
await client.evaluate('document.getElementById("borrowAssetForm").requestSubmit()');
await client.until('!app.assetExportSubmitting && app.assets.find(row=>row.AssetId===1).EndingBalance===7 && window.savedDownload?.size>1000');
assert.equal((await f.pool.request().query('SELECT COUNT(*) AS total FROM AssetExportRequests')).recordset[0].total, 2);
assert.equal(await client.evaluate('location.hash'), '#assets');
await client.evaluate(`app.closeModals(); document.querySelector('.asset-row-checkbox[data-asset-id="1"]').click(); document.getElementById('borrowAssetBtn').click()`);
await client.until('document.getElementById("borrowAssetModal").classList.contains("open")');
assert.equal(await client.evaluate('document.getElementById("borrowAssetForm").dataset.exportForOthers'), 'false');
assert.equal(await client.evaluate('document.getElementById("borrowAssetRecipientInput").disabled'), true);
assert.equal(await client.evaluate('document.querySelector("#borrowAssetForm button[type=submit]").textContent'), 'Gửi đơn chờ duyệt');
// The asset role can export multiple items for a recipient in one saved document.
await client.send('Network.setExtraHTTPHeaders', { headers: { 'x-test-user': '3', 'x-test-role': 'asset' } });
await client.send('Page.reload');
await client.until('typeof app !== "undefined" && app?.currentUser?.Role === "asset" && app.assets.length === 3 && !!document.getElementById("exportAssetForOthersBtn")');
await client.send('Emulation.setDeviceMetricsOverride', { width: 1600, height: 1050, deviceScaleFactor: 1, mobile: false });
await client.evaluate(`app.downloadBlobFile=(blob,name)=>{window.savedDownload={size:blob.size,name}}; document.querySelector('.asset-row-checkbox[data-asset-id="1"]').click(); document.querySelector('.asset-row-checkbox[data-asset-id="2"]').click(); document.getElementById('exportAssetForOthersBtn').click()`);
await client.until('document.getElementById("batchAssetExportModal").classList.contains("open")');
await client.evaluate('document.getElementById("batchAssetExportRecipientInput").value="Nguyễn An"; const common=document.getElementById("batchAssetExportCommonProject"); common.value="Dự án B"; common.dispatchEvent(new Event("change"))');
await client.send('Page.captureScreenshot', { format: 'png' }).then(result => fs.writeFileSync(path.join(output, 'batch-export-for-others.png'), Buffer.from(result.data, 'base64')));
await client.evaluate('document.getElementById("batchAssetExportForm").requestSubmit()');
await client.until('!app.assetExportSubmitting && app.assets.find(row=>row.AssetId===1).EndingBalance===6 && window.savedDownload?.size>1000');
assert.equal((await f.pool.request().query('SELECT EndingBalance FROM AssetInventory WHERE AssetId = 2')).recordset[0].EndingBalance, 3);
assert.equal((await f.pool.request().query('SELECT COUNT(*) AS total FROM AssetExportRequests')).recordset[0].total, 2);
const saved = (await f.pool.request().query('SELECT SnapshotJson FROM AssetExportDocuments ORDER BY ExportedDate DESC')).recordset;
assert.equal(JSON.parse(saved[0].SnapshotJson).requesterName, 'Nguyễn An');
assert.equal(JSON.parse(saved[1].SnapshotJson).requesterName, 'Trần Bình');
await client.evaluate(`app.closeModals(); document.querySelector('.asset-row-checkbox[data-asset-id="1"]').click(); document.querySelector('.asset-row-checkbox[data-asset-id="2"]').click(); document.getElementById('borrowAssetBtn').click()`);
await client.until('document.getElementById("batchAssetExportModal").classList.contains("open")');
assert.equal(await client.evaluate('document.getElementById("batchAssetExportForm").dataset.exportForOthers'), 'false');
assert.equal(await client.evaluate('document.getElementById("batchAssetExportRecipientInput").disabled'), true);
assert.deepEqual(client.errors, []);
} catch (err) {
if (client) console.error('Browser failure state:', await client.evaluate(`({ url: location.href,
role: typeof app !== 'undefined' && app?.currentUser?.Role, page: typeof app !== 'undefined' && app?.currentPage,
assets: typeof app !== 'undefined' && app?.assets?.length, errors: document.body.innerText.slice(-500) })`), client.errors);
throw err;
} finally {
if (client) client.socket.close();
chrome.kill();