78 lines
4.5 KiB
Python
78 lines
4.5 KiB
Python
from urllib.parse import urlsplit
|
|
|
|
import pytest
|
|
from playwright.sync_api import expect
|
|
|
|
from apps.core.models import SiteBranding
|
|
from apps.payments.access import issue_payment_link
|
|
from apps.payments import services
|
|
from tests.e2e.pages.payment_link import PaymentLinkPage
|
|
from tests.e2e.pages.auth import AuthenticationPage
|
|
from tests.e2e.test_payments_e2e import payment_case, PNG
|
|
from tests.e2e.test_payments_e2e import PASSWORD
|
|
from django.urls import reverse
|
|
|
|
pytestmark = [pytest.mark.e2e, pytest.mark.django_db(transaction=True)]
|
|
|
|
|
|
@pytest.mark.parametrize('width,via_link,manual', [(320, True, True), (1440, True, False),
|
|
(320, False, False), (1440, False, True)])
|
|
def test_notice_sharing_and_full_copy(live_server, browser_page, payment_case, width, via_link, manual):
|
|
customer, account, reviewers = payment_case
|
|
notice = services.issue_notice(reviewers[0], {'customer': customer, 'account': account,
|
|
'subject': 'اشتراک اطلاعات واریز', 'amount': 12345, 'deposit_id': '۰۰۰۱۲۳۰۴'})
|
|
_, original_url = issue_payment_link(notice=notice)
|
|
with browser_page() as page:
|
|
page.set_viewport_size({'width': width, 'height': 900})
|
|
view = PaymentLinkPage(page, live_server.url)
|
|
view.prepare_copy(manual)
|
|
if via_link:
|
|
view.open_link(urlsplit(original_url).path)
|
|
else:
|
|
AuthenticationPage(page, live_server.url).login_customer(customer, PASSWORD)
|
|
view.goto(reverse('payments:notice_detail', args=[notice.public_id]))
|
|
expect(page.locator('.pay-deposit-required dd')).to_have_text('12304')
|
|
full_copy = view.copied_text('کپی کامل اطلاعات')
|
|
assert 'شناسه واریز: 12304' in full_copy
|
|
assert 'وارد کردن شناسه واریز هنگام پرداخت الزامی و اجباری است' in full_copy
|
|
assert 'شماره حساب: 000123' in full_copy
|
|
shared_url = view.copy_short_link()
|
|
assert urlsplit(shared_url).path.startswith('/p/')
|
|
if via_link:
|
|
assert shared_url == original_url
|
|
assert page.evaluate('document.documentElement.scrollWidth <= document.documentElement.clientWidth + 1')
|
|
with browser_page() as recipient_page:
|
|
recipient = PaymentLinkPage(recipient_page, live_server.url)
|
|
recipient.open_link(urlsplit(shared_url).path)
|
|
expect(recipient_page.locator('.pay-deposit-required dd')).to_have_text('12304')
|
|
expect(recipient_page.get_by_role('link', name='پروفایل من')).to_have_count(0)
|
|
|
|
|
|
@pytest.mark.parametrize('width,linked', [(1440, True), (320, True), (390, False)])
|
|
def test_sms_payment_without_login_preserves_copy_and_submission(live_server, browser_page, payment_case, width, linked):
|
|
customer, account, reviewers = payment_case
|
|
notice = services.issue_notice(reviewers[0], {'customer': customer, 'account': account,
|
|
'subject': 'اعلامیه بدون ورود', 'amount': 12345, 'deposit_id': '000123', 'description': 'اطلاعات کامل اعلامیه'})
|
|
_, url = issue_payment_link(notice=notice)
|
|
branding = SiteBranding.load()
|
|
branding.developer_credit_text = 'امضای ثابت توسعهدهنده'
|
|
branding.save()
|
|
with browser_page() as page:
|
|
page.set_viewport_size({'width': width, 'height': 900})
|
|
view = PaymentLinkPage(page, live_server.url)
|
|
view.open_link(urlsplit(url).path)
|
|
expect(page.locator('.pay-deposit-required dd')).to_have_text('123')
|
|
expect(page.get_by_text('واریز بدون این شناسه معتبر نخواهد بود.', exact=False)).to_be_visible()
|
|
expect(page.locator('.cs-footer')).to_have_text(branding.developer_credit_text)
|
|
expect(page.get_by_role('link', name='پروفایل من')).to_have_count(0)
|
|
assert page.locator('.pay-deposit-required dd').evaluate('(element) => getComputedStyle(element).color') == 'rgb(159, 31, 31)'
|
|
view.copy_all()
|
|
view.open_receipt_form(linked)
|
|
view.show_required_errors()
|
|
view.submit_payment(PNG, account_id=account.pk if not linked else None)
|
|
expect(page.get_by_text('در انتظار بررسی', exact=False).first).to_be_visible()
|
|
expect(page.get_by_role('button', name='ثبت تأیید من', exact=True)).to_have_count(0)
|
|
if not linked:
|
|
expect(page.get_by_text('واریز مستقل', exact=True)).to_be_visible()
|
|
assert page.evaluate('document.documentElement.scrollWidth <= document.documentElement.clientWidth + 1')
|