import {test,expect} from '@playwright/test'; test('owner-confirmed imported payment is blue even when the source total is unknown',async({page})=>{ await page.goto('/index.html',{waitUntil:'domcontentloaded'}); await page.waitForFunction(()=>window.sunOrderPaymentState); const states=await page.evaluate(()=>{ const unknown={total:0,prepayment:0,telegramImport:{totalUnknown:true}}; const confirmed={...unknown,paymentStatus:'paid',paymentConfirmedAt:'2026-09-18T12:00:00Z'}; return [window.sunOrderPaymentState(unknown),window.sunOrderPaymentState(confirmed),window.sunOrderPaymentState({...confirmed,status:'Отменён'}),window.sunOrderPaymentState({...confirmed,total:1000,deliveryCost:1000}),window.sunOrderPaymentState({...confirmed,total:1000,deliveryCost:1000,prepayment:1000})]; }); expect(states).toEqual(['unpaid','paid','cancelled','unpaid','paid']); }); test('new companies start empty and workspace catalogs survive reload without shared seeds',async({page})=>{ await page.goto('/index.html',{waitUntil:'domcontentloaded'}); await page.waitForFunction(()=>window.CateriumDataV1773); expect(await page.evaluate(()=>({count:boxes.length,starter:window.SUN_OFFICIAL_CATALOG.length,legacy:window.SUN_LEGACY_CATALOG_V175.length}))).toEqual({count:0,starter:0,legacy:0}); await page.evaluate(()=>{boxes.push({id:'own-menu',name:'Свой бокс',category:0,price:1234,photo:''});persist()}); await page.reload();await page.waitForFunction(()=>window.CateriumDataV1773); expect(await page.evaluate(()=>boxes.map(b=>b.id))).toEqual(['own-menu']); await page.evaluate(()=>localStorage.clear());await page.reload();await page.waitForFunction(()=>window.CateriumDataV1773); expect(await page.evaluate(()=>boxes.length)).toBe(0); }); test('imported history keeps partial payments and delivery is charged once after save',async({page})=>{ page.on('dialog',d=>d.accept()); await page.goto('/index.html',{waitUntil:'domcontentloaded'}); await page.waitForFunction(()=>window.__cateriumOrderEnhancementsV1775&&window.SunUXFixV1764&&window.sunOrderPricing); const result=await page.evaluate(async()=>{ const item={id:'import-fixture',name:'Исходная позиция',price:9900,category:0};boxes.push(item); const order={id:900001,event:'Исторический заказ',date:'2026-09-10',time:'12:00',contact:'Тест',phone:'',address:'',note:'Источник сохранён',status:'Новый',lines:[{id:item.id,qty:2,price:3500}],total:7500,deliveryCost:1500,promoCode:'TEST',promoDiscountValue:1000,promoDiscountType:'amount',prepayment:2000,autoCompletionDisabled:true}; orders.push(order);persist();window.openOrder(order.id);await new Promise(r=>setTimeout(r,150)); const shown=Number(document.getElementById('orderTotal').value); window.saveOrder();await new Promise(r=>setTimeout(r,150)); window.SunUXFixV1764.autoCompleteOrders(Date.parse('2030-01-01T12:00:00Z'),{silent:true}); const saved=orders.find(x=>x.id===order.id); return {shown,total:saved.total,prepayment:saved.prepayment,status:saved.status,flag:saved.autoCompletionDisabled,rows:document.querySelectorAll('.sun-order-line-row').length}; }); expect(result).toEqual({shown:7500,total:7500,prepayment:2000,status:'Новый',flag:true,rows:1}); }); test('completed import archive stays removed even with an old cached payload',async({page})=>{ await page.route('**/index.html',r=>r.fulfill({contentType:'text/html; charset=utf-8',body:'

Заказы

'})); await page.goto('/index.html'); await page.evaluate(()=>localStorage.setItem('sunTelegramImportArchiveV1',JSON.stringify({orderCount:1,clientCount:1,messages:[{id:'message1',sentAt:'01.01.2026',text:'Заказ \nАдрес: тест'}],attachments:[]}))); await page.addScriptTag({url:'/core/import-archive.js'}); await page.evaluate(()=>{ window.CateriumImportArchive.show();window.CateriumImportArchive.refresh(); window.dispatchEvent(new Event('sun:cloud-state-applied')); window.dispatchEvent(new Event('sun:cloud-permissions-changed')); }); expect(await page.locator('dialog').count()).toBe(0); expect(await page.locator('#cateriumTelegramArchive').count()).toBe(0); }); test('retired import positions leave the working catalogs but preserve historical orders and proposals',async({page})=>{ test.setTimeout(45000); await page.route('https://**',r=>r.abort()); await page.goto('/index.html',{waitUntil:'domcontentloaded'}); await page.waitForFunction(()=>window.SunOpsUXV1762&&window.sunClientOfferDebugCreateSnapshot&&window.__cateriumOrderEnhancementsV1775); await page.evaluate(()=>{ boxes=[{id:'5',name:'Фуршетный бокс №5',price:4900,category:0,photo:'',ingredients:[]}, {id:'tg-item-fixture',name:'Фуршетный набор 8 — Салаты в шотах',price:3900,category:0,hidden:true,catalogSection:'Импорт из Telegram',photo:'',ingredients:[]}]; orders=[{id:900002,event:'История импорта',date:'2026-09-10',time:'12:00',contact:'Тестовый клиент',phone:'+79990000000',address:'Тестовая улица, 1',note:'Исходные сведения',status:'Новый',lines:[{id:'tg-item-fixture',qty:2,price:3500}],total:7000,prepayment:7000,paymentStatus:'paid',autoCompletionDisabled:true}]; draft.lines=[];persist();window.render(); }); await expect(page.locator('#tiles')).toContainText('Фуршетный бокс №5'); await expect(page.locator('#tiles')).not.toContainText('Салаты в шотах'); await page.evaluate(()=>{window.add('tg-item-fixture');window.openManager()}); expect(await page.evaluate(()=>draft.lines.length)).toBe(0); await expect(page.locator('#managerList')).not.toContainText('Салаты в шотах'); await page.evaluate(()=>{window.closeModal('manager');window.SunOpsUXV1762.openMenu()}); await expect(page.locator('#sunMenuCountV1762')).toHaveText('1 поз.'); await expect(page.locator('#sunMenuListV1762')).not.toContainText('Импорт из Telegram'); await page.evaluate(()=>{const input=document.getElementById('sunGlobalSearchInput');input.value='Салаты в шотах';input.dispatchEvent(new Event('input'))}); expect(await page.locator('#sunGlobalSearchResults [data-action="box"]').count()).toBe(0); const catalog=await page.evaluate(async()=>{ window.print=()=>{};await window.sunPrintLiveCatalog(); const text=document.getElementById('sunLiveCatalogPrintRoot').textContent; const pages=await window.sunCatalogDebugPdfPages(0,10); return {text,pages:pages.length}; }); expect(catalog.text).toContain('Фуршетный бокс №5');expect(catalog.text).not.toContain('Салаты в шотах');expect(catalog.pages).toBe(1); await page.evaluate(()=>window.openOrder(900002)); await expect(page.locator('#lines')).toContainText('Салаты в шотах'); await expect(page.locator('#orderTotal')).toHaveValue('7000'); await expect(page.locator('#phone')).toHaveValue('+79990000000'); const snapshot=await page.evaluate(()=>window.sunClientOfferDebugCreateSnapshot(orders[0])); expect(snapshot.items).toHaveLength(1);expect(snapshot.items[0]).toMatchObject({name:'Фуршетный набор 8 — Салаты в шотах',qty:2,unitPrice:3500,sum:7000}); expect(await page.evaluate(()=>window.sunOrderPaymentState(orders[0]))).toBe('paid'); await page.reload();await page.waitForFunction(()=>window.SunOpsUXV1762); await expect(page.locator('#tiles')).not.toContainText('Салаты в шотах'); expect(await page.evaluate(()=>({hidden:boxes.find(b=>b.id==='tg-item-fixture').hidden,lines:orders[0].lines.length,address:orders[0].address}))).toEqual({hidden:true,lines:1,address:'Тестовая улица, 1'}); });