Files
customerTicket/tests/e2e/test_dispatch_response_opening_e2e.py

106 lines
6.7 KiB
Python

import pytest
from playwright.sync_api import expect
from apps.messaging.models import Message
from apps.notifications.models import SMSTemplate
from apps.tickets.services import dispatch_group_tickets
from tests.e2e.pages.auth import AuthenticationPage
from tests.e2e.pages.dispatches import DispatchWorkspacePage
from tests.e2e.test_dispatch_workspace_e2e import dispatch_case, PASSWORD
pytestmark = [pytest.mark.e2e, pytest.mark.django_db(transaction=True)]
@pytest.mark.parametrize("width", [1440, 390, 320])
def test_sealed_report_requires_confirmation_and_opens_answers_together(live_server, browser_page, dispatch_case, width):
staff, unit, group, category, _, customers = dispatch_case
# Transactional live-server tests flush data migrations between tests.
SMSTemplate.objects.create(unit=unit, event_type="DISPATCH_RESPONSES_OPENED", title="بازگشایی", body="متن دقیق پیامک بازگشایی برای آزمون")
dispatch, tickets = dispatch_group_tickets(user=staff, unit=unit, contact_group=group,
category=category, subject="استعلام محرمانه مرورگر", body="پیشنهاد خود را ثبت کنید.")
answer = "پیشنهاد محرمانه مخاطب اول " * 12 + "پایان کامل پیشنهاد"
Message.objects.create(ticket=tickets[0], author=customers[0], body=answer)
second_answer = Message.objects.create(ticket=tickets[0], author=customers[0], body="توضیح تکمیلی پیشنهاد اول")
Message.objects.create(ticket=tickets[1], author=customers[1], body="پیشنهاد مخاطب دوم")
with browser_page() as page:
page.set_viewport_size({"width": width, "height": 900})
AuthenticationPage(page, live_server.url).login_staff(staff, PASSWORD)
workspace = DispatchWorkspacePage(page, live_server.url)
workspace.open_report(dispatch)
expect(page.get_by_role("heading", name="پاسخ‌ها هنوز بازگشایی نشده‌اند")).to_be_visible()
expect(page.locator("body")).not_to_contain_text(answer)
expect(page.locator('[data-recipient-row] a[href*="/staff/tickets/"]')).to_have_count(0)
workspace.filter_recipients("دارای پاسخ")
expect(workspace.visible_recipients()).to_have_count(2)
expect(workspace.visible_recipients().first).to_contain_text("پاسخ داده است: بله")
workspace.expect_fits_viewport()
workspace.save_screenshot(f"sealed-report-{width}.png")
workspace.review_opening()
expect(page.locator(".opening-sms-preview")).to_have_text("متن دقیق پیامک بازگشایی برای آزمون")
expect(page.locator("body")).not_to_contain_text(answer)
workspace.expect_fits_viewport()
workspace.save_screenshot(f"opening-confirm-{width}.png")
workspace.confirm_opening()
expect(page.locator("body")).to_contain_text(answer)
expect(page.locator("body")).to_contain_text(second_answer.body)
expect(page.locator("body")).to_contain_text("پیشنهاد مخاطب دوم")
expect(page.locator(".recipient-reply")).to_have_count(3)
expect(page.locator('[data-recipient-row] a[href*="/staff/tickets/"]')).to_have_count(0)
from apps.core.templatetags.jalali import jalali_datetime_precise
expect(page.locator(".recipient-reply time").nth(1)).to_have_text(jalali_datetime_precise(second_answer.created_at))
workspace.expect_fits_viewport()
workspace.save_screenshot(f"opened-report-{width}.png")
def test_composer_defaults_to_sealed_and_disables_sms_in_individual_mode(live_server, browser_page, dispatch_case):
staff, unit, group, category, _, _ = dispatch_case
with browser_page() as page:
AuthenticationPage(page, live_server.url).login_staff(staff, PASSWORD)
workspace = DispatchWorkspacePage(page, live_server.url)
workspace.open_composer()
workspace.compose(unit, group, category, "پیش‌فرض پاسخ محرمانه", "متن درخواست")
expect(page.get_by_role("radio", name="بازگشایی یکجا", exact=True)).to_be_checked()
expect(workspace.opening_sms).to_be_checked()
workspace.review()
expect(workspace.review_dialog.locator('[data-review-inquiry-recommendation]')).to_be_hidden()
workspace.cancel_review()
workspace.choose_response_mode("مشاهده جداگانه")
expect(workspace.opening_sms).to_be_disabled()
expect(workspace.opening_sms).not_to_be_checked()
workspace.review()
expect(workspace.review_dialog).to_contain_text("مشاهده جداگانه؛ پیامک بازگشایی: غیرفعال")
expect(workspace.review_dialog.locator('[data-review-inquiry-recommendation]')).to_be_visible()
expect(workspace.review_dialog).to_contain_text("برای تمامی استعلام‌گیری‌ها توصیه می‌کنیم")
workspace.cancel_review()
workspace.choose_response_mode("بازگشایی یکجا")
expect(workspace.opening_sms).to_be_checked()
workspace.opening_sms.uncheck()
workspace.choose_response_mode("مشاهده جداگانه")
workspace.choose_response_mode("بازگشایی یکجا")
expect(workspace.opening_sms).not_to_be_checked()
workspace.review()
expect(workspace.review_dialog.locator('[data-review-inquiry-recommendation]')).to_be_visible()
workspace.save_screenshot("review-inquiry-recommendation.png")
@pytest.mark.parametrize("count", [15, 16])
def test_composer_enforces_opening_sms_recipient_cap(live_server, browser_page, dispatch_case, count):
from tests.test_organizational_ticketing import make_contact
staff, unit, group, category, _, _ = dispatch_case
for i in range(2, count):
make_contact(f"browser-limit-{i}", f"09122100{i:03}").customer_profile.groups.add(group)
with browser_page() as page:
AuthenticationPage(page, live_server.url).login_staff(staff, PASSWORD)
workspace = DispatchWorkspacePage(page, live_server.url)
workspace.open_composer()
workspace.compose(unit, group, category, "آزمون سقف پیامک مرورگر", "متن استعلام")
if count == 15:
expect(workspace.opening_sms).to_be_enabled()
expect(workspace.opening_sms).to_be_checked()
else:
expect(workspace.opening_sms).to_be_disabled()
expect(workspace.opening_sms).not_to_be_checked()
expect(page.locator('[data-opening-sms-hint]')).to_contain_text("بیش از ۱۵")
workspace.review()
expect(workspace.review_dialog.locator('[data-review-inquiry-limit]')).to_be_visible()