caterium-app/tests/order-import.spec.mjs
2026-09-17 20:27:07 +03:00

45 lines
3.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {test,expect} from '@playwright/test';
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('private import archive safely shows messages and clears on workspace change',async({page})=>{
await page.route('**/index.html',r=>r.fulfill({contentType:'text/html',body:'<html><body><section id="orders"><h1>Заказы</h1></section></body></html>'}));
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:'Заказ <img src=x onerror=alert(1)>\nАдрес: тест'}],attachments:[]})));
await page.addScriptTag({url:'/core/import-archive.js'});
await page.getByRole('button',{name:'Исходный архив Telegram'}).click();
await page.getByRole('searchbox').fill('Адрес');
await page.locator('summary').click();
await expect(page.locator('dialog pre')).toContainText('<img src=x');
expect(await page.locator('dialog img').count()).toBe(0);
await page.evaluate(()=>{localStorage.removeItem('sunTelegramImportArchiveV1');window.dispatchEvent(new Event('sun:cloud-state-applied'))});
expect(await page.locator('dialog').count()).toBe(0);
expect(await page.locator('#cateriumTelegramArchive').count()).toBe(0);
});