@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / 948e22d
Fork 0

سامانه صدور فاکتور و حسابداری

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 20:45 UTC

test(ui): linked draft finalize and delete reject before confirmation or RPC

davoodmehraban89 committed Nov 22, 2026 at 17:20 UTC 948e22debb327781452b11936a378eaf1815aff1
1 file changed +59
scripts/accounting-document-workflow.spec.js
+59
@@ -1104,3 +1104,62 @@ test('P0 #229 linked journal drafts do not advertise unsupported source-only edi
1104 expect(observed.saleActions).not.toContainEqual(expect.stringContaining('editInvoice('));
1105 expect(observed.saleActions).not.toContainEqual(expect.stringContaining('beginInvoiceAmendment('));
1106 });
1107 +
1108 +
1109 +test('P0 #229 linked draft direct actions deny before confirm, sync or autopost',async({page})=>{
1110 + const server=fakeServer();
1111 + await installHarness(page,server);
1112 + await authenticatedMockBrowser(page);
1113 + const observed=await page.evaluate(async()=>{
1114 + const ownerUserId=currentUser.id,companyId='QA_CO';
1115 + const sale={id:'QA_SALE_LINK_ACTION',ownerUserId,companyId,kind:'formal',
1116 + kindLabel:'رسمی',companyName:'QA Company',number:'QA-SALE-LINK-ACTION',
1117 + contactId:'QA_CONTACT',contactName:'QA Customer',date:'1405/07/19',
1118 + items:[],grandTotal:170,journalVoucherId:'QA_SALE_JV_LINK_ACTION',
1119 + documentStatus:'draft',accountingStatus:'draft'};
1120 + const purchase={id:'QA_PUR_LINK_ACTION',ownerUserId,companyId,
1121 + number:'QA-PUR-LINK-ACTION',supplierId:'QA_CONTACT',supplierName:'QA Supplier',
1122 + date:'1405/07/19',items:[],grandTotal:170,
1123 + journalVoucherId:'QA_PUR_JV_LINK_ACTION',documentStatus:'draft',accountingStatus:'draft'};
1124 + datastore.invoices.push(sale);datastore.purchases.push(purchase);
1125 + datastore.journalVouchers.push(
1126 + {id:sale.journalVoucherId,ownerUserId,companyId,status:'draft',
1127 + sourceType:'sale',sourceId:sale.id},
1128 + {id:purchase.journalVoucherId,ownerUserId,companyId,status:'draft',
1129 + sourceType:'purchase',sourceId:purchase.id}
1130 + );
1131 + const snapshot=()=>JSON.stringify({
1132 + sale:datastore.invoices.find(x=>x.id===sale.id),
1133 + purchase:datastore.purchases.find(x=>x.id===purchase.id),
1134 + journals:datastore.journalVouchers.filter(x=>x.id.endsWith('_JV_LINK_ACTION'))});
1135 + const before=snapshot(),alerts=[];
1136 + let confirmCalls=0,directDenial='';
1137 + const previousConfirm=window.confirm,previousAlert=window.alert;
1138 + window.confirm=()=>{confirmCalls++;return true;};
1139 + window.alert=value=>alerts.push(String(value));
1140 + try{
1141 + try{await finalizeInvoiceDocument(sale.id)}catch(e){directDenial=String(e.message);}
1142 + await finalizeInvoiceDocumentUi(sale.id);
1143 + await purFinalizeUi(purchase.id);
1144 + purDeleteDraftUi(purchase.id);
1145 + }finally{window.confirm=previousConfirm;window.alert=previousAlert;}
1146 + switchView('view-purchases');refreshAllSurfaces();renderInvoices();
1147 + const saleRow=[...document.querySelectorAll('#invoice-archive-table-body tr')]
1148 + .find(tr=>tr.textContent.includes(sale.number));
1149 + const purchaseRow=[...document.querySelectorAll('#pur-list-body tr')]
1150 + .find(tr=>tr.textContent.includes(purchase.number));
1151 + if(!saleRow||!purchaseRow)throw Error('Linked draft action register row missing');
1152 + return {confirmCalls,directDenial,alerts,unchanged:before===snapshot(),
1153 + saleLabel:saleRow.textContent,purchaseLabel:purchaseRow.textContent};
1154 + });
1155 + expect(observed.confirmCalls).toBe(0);
1156 + expect(observed.directDenial).toContain('سند موقت متصل');
1157 + expect(observed.alerts.filter(x=>x.includes('قطعی‌سازی مستقل'))).toHaveLength(2);
1158 + expect(observed.alerts.some(x=>x.includes('حذف سند موقت متصل'))).toBe(true);
1159 + expect(observed.unchanged).toBe(true);
1160 + expect(observed.saleLabel).toContain('پیش‌نویس متصل');
1161 + expect(observed.saleLabel).not.toContain('پیش‌نویس قابل ویرایش');
1162 + expect(observed.purchaseLabel).toContain('موقت متصل');
1163 + expect(observed.purchaseLabel).not.toContain('موقت قابل اصلاح');
1164 + expect(server.autoPostCount||0).toBe(0);
1165 +});