import pytest from django.urls import reverse from apps.accounts.models import User from apps.customers.models import CustomerProfile from apps.staff.models import StaffProfile from apps.tickets.models import TicketCategory from apps.tickets.services import create_ticket from tests.e2e.pages.auth import AuthenticationPage from tests.e2e.pages.tickets import TicketConversationPage pytestmark = [pytest.mark.e2e, pytest.mark.django_db(transaction=True)] PASSWORD = "E2e-safe-password-2026" def test_customer_sees_chat_guidance_after_two_rapid_messages(live_server, browser_page): category = TicketCategory.objects.create(title="فروش E2E", slug="e2e-customer-chat") customer = User.objects.create_user( username="e2e-customer-chat", mobile="09120009001", password=PASSWORD, account_type=User.AccountType.CUSTOMER, ) CustomerProfile.objects.create(user=customer, first_name="مشتری", last_name="آزمایشی") ticket = create_ticket(customer=customer, category=category, subject="تست هشدار مشتری", body="سلام") with browser_page() as page: AuthenticationPage(page, live_server.url).login_customer(customer, PASSWORD) conversation = TicketConversationPage(page, live_server.url) conversation.goto(reverse("tickets:detail", args=[ticket.public_id])) conversation.expect_guidance_hidden() conversation.send_reply("قیمت چنده؟") conversation.expect_guidance_visible() conversation.dismiss_guidance() conversation.send_reply("موجود دارید؟") conversation.expect_guidance_visible() conversation.dismiss_guidance() def test_staff_sees_chat_guidance_after_two_rapid_replies(live_server, browser_page): category = TicketCategory.objects.create(title="پشتیبانی E2E", slug="e2e-staff-chat") customer = User.objects.create_user( username="e2e-staff-customer", mobile="09120009002", password=PASSWORD, account_type=User.AccountType.CUSTOMER, ) staff = User.objects.create_user( username="e2e-staff-chat", mobile="09120009003", password=PASSWORD, account_type=User.AccountType.STAFF, ) StaffProfile.objects.create(user=staff, display_name="کارشناس E2E") ticket = create_ticket( customer=customer, category=category, subject="تست هشدار کارشناس", selected_expert=staff, body="درخواست مشتری", ) ticket.owner = staff ticket.selected_expert = None ticket.save(update_fields=["owner", "selected_expert", "updated_at"]) with browser_page() as page: AuthenticationPage(page, live_server.url).login_staff(staff, PASSWORD) conversation = TicketConversationPage(page, live_server.url) conversation.goto(reverse("staff_tickets:detail", args=[ticket.public_id])) conversation.send_reply("پاسخ اول کارشناس") conversation.expect_guidance_hidden() conversation.send_reply("پاسخ دوم کارشناس") conversation.expect_guidance_visible() conversation.dismiss_guidance() conversation.send_reply("پاسخ سوم کارشناس") conversation.expect_guidance_visible() conversation.dismiss_guidance()