54 lines
3.0 KiB
Python
54 lines
3.0 KiB
Python
import pytest
|
|
from django.urls import reverse
|
|
from django.utils import timezone
|
|
from playwright.sync_api import expect
|
|
|
|
from apps.accounts.models import User
|
|
from apps.payments import services
|
|
from apps.payments.models import BankInstitution, CompanyBankAccount
|
|
from apps.staff.models import StaffProfile
|
|
from apps.tickets.models import Ticket, TicketCategory
|
|
from tests.e2e.pages.auth import AuthenticationPage
|
|
from tests.e2e.pages.ticket_notices import TicketNoticesPage
|
|
|
|
pytestmark = [pytest.mark.e2e, pytest.mark.django_db(transaction=True)]
|
|
|
|
|
|
@pytest.mark.parametrize('width', [1440, 390])
|
|
def test_ticket_notices_toggle_and_customer_navigation(live_server, browser_page, width):
|
|
password = 'TicketNotices-e2e-2026'
|
|
staff = User.objects.create_user(username='notice-staff', password=password, account_type='STAFF')
|
|
StaffProfile.objects.create(user=staff, display_name='کارشناس اعلامیه')
|
|
customer = User.objects.create_user(username='notice-customer', account_type='CUSTOMER')
|
|
bank, _ = BankInstitution.objects.get_or_create(code='melli', defaults={'name': 'ملی'})
|
|
account = CompanyBankAccount.objects.create(name='حساب اعلامیه', holder='شرکت', bank=bank, account_number='123')
|
|
notices = [services.issue_notice(staff, {'customer': customer, 'account': account,
|
|
'subject': f'اعلامیه نمونه {index}', 'amount': 12345}) for index in range(4)]
|
|
ticket = Ticket.objects.create(customer=customer,
|
|
category=TicketCategory.objects.create(title='مالی', slug='ticket-notices'),
|
|
subject='تیکت اعلامیه', owner=staff, selected_expert=staff,
|
|
origin_visibility='SELECTED', last_activity_at=timezone.now())
|
|
ticket_url = reverse('staff_tickets:detail', args=[ticket.public_id])
|
|
with browser_page() as page:
|
|
page.set_viewport_size({'width': width, 'height': 900})
|
|
AuthenticationPage(page, live_server.url).login_staff(staff, password)
|
|
view = TicketNoticesPage(page, live_server.url)
|
|
view.goto(ticket_url)
|
|
view.open_customer_panel()
|
|
view.expect_closed()
|
|
view.toggle_notices()
|
|
view.expect_open()
|
|
expect(page.get_by_role('list', name='اعلامیههای اخیر مشتری')).to_contain_text('در انتظار واریز')
|
|
expect(page.get_by_role('list', name='اعلامیههای اخیر مشتری')).not_to_contain_text(notices[0].subject)
|
|
view.toggle_notices()
|
|
view.expect_closed()
|
|
view.toggle_notices()
|
|
view.open_notice(notices[-1].subject)
|
|
expect(page).to_have_url(live_server.url + reverse('staff_payments:notice_detail', args=[notices[-1].public_id]))
|
|
view.goto(ticket_url)
|
|
view.open_customer_panel()
|
|
view.toggle_notices()
|
|
view.open_all()
|
|
expect(page).to_have_url(live_server.url + reverse('staff_payments:desk') + f'?tab=notices&customer={customer.pk}')
|
|
expect(page.get_by_text(notices[0].subject, exact=True)).to_be_visible()
|