60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
test.describe('Scenario 05: CRM Deal Won -> Commercial Order Flow', () => {
|
|
test('advances deal to Won, confirms linked Order creation, and verifies order in Sales', async ({ page }) => {
|
|
await page.goto('/crm/deals');
|
|
await page.waitForLoadState('domcontentloaded');
|
|
|
|
// Switch to Deals tab if needed
|
|
const dealsTab = page.locator('button:has-text("Воронка сделок")');
|
|
if (await dealsTab.isVisible()) {
|
|
await dealsTab.click({ force: true });
|
|
}
|
|
|
|
// Locate deal cards
|
|
const dealCards = page.locator('[data-testid^="deal-card-"]');
|
|
await expect(dealCards.first()).toBeVisible({ timeout: 15000 });
|
|
|
|
const firstCard = dealCards.first();
|
|
const dealId = await firstCard.getAttribute('data-deal-id');
|
|
expect(dealId).toBeTruthy();
|
|
|
|
const wonColumn = page.locator('[data-testid="kanban-column-won"]');
|
|
await wonColumn.scrollIntoViewIfNeeded().catch(() => {});
|
|
await firstCard.scrollIntoViewIfNeeded().catch(() => {});
|
|
|
|
// Advance deal to Won
|
|
await firstCard.dragTo(wonColumn).catch(() => {});
|
|
|
|
const confirmOrderBtn = page.locator('[data-testid="create-order-confirm-btn"]');
|
|
if (!await confirmOrderBtn.isVisible({ timeout: 2500 }).catch(() => false)) {
|
|
// Advance card through its stage buttons until won
|
|
for (let i = 0; i < 6; i++) {
|
|
if (await confirmOrderBtn.isVisible().catch(() => false)) break;
|
|
const nextBtn = page.locator(`[data-testid="deal-card-${dealId}"] button:has-text("Далее:")`).first();
|
|
if (await nextBtn.count() > 0) {
|
|
await nextBtn.click({ force: true, timeout: 2000 }).catch(() => {});
|
|
await page.waitForTimeout(400);
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Modal "Сделка выиграна! Создать заказ в коммерции?"
|
|
await expect(confirmOrderBtn).toBeVisible({ timeout: 10000 });
|
|
await confirmOrderBtn.click();
|
|
|
|
// Wait for the modal to close and async IndexedDB write to finish
|
|
await expect(confirmOrderBtn).not.toBeVisible({ timeout: 10000 });
|
|
await page.waitForTimeout(500);
|
|
|
|
// Navigate to Sales module
|
|
await page.goto('/sales');
|
|
await page.waitForLoadState('domcontentloaded');
|
|
|
|
// Verify order exists in the Commerce Orders table
|
|
const orderItem = page.locator('tbody tr').filter({ hasText: 'ORD-' }).first();
|
|
await expect(orderItem).toBeVisible({ timeout: 15000 });
|
|
});
|
|
});
|