fix payment UI UX

This commit is contained in:
javad committed 2026-10-07 14:06:14 +03:30
1 parent bb3ddd1610
commit 90931a5a64
6 files changed
+104 -10

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
from playwright.sync_api import expect
from .payments import PaymentsPage
class PaymentFeedbackPage(PaymentsPage):
def check_amount(self, raw, expected):
self.page.locator('#id_amount').fill(raw)
expect(self.page.locator('#amount-words')).to_have_text(expected)
def request_share(self):
self.page.locator('[data-share-link] button').click()
def expect_pending_share(self):
button = self.page.locator('[data-share-link] button')
expect(button).to_be_disabled()
expect(button).to_have_attribute('aria-busy', 'true')
expect(button).to_have_text('در حال آماده‌سازی لینک…')
def expect_failed_share(self):
button = self.page.locator('[data-share-link] button')
expect(button).to_be_enabled()
expect(button).not_to_have_attribute('aria-busy', 'true')
expect(button).to_have_text('کپی لینک کوتاه این صفحه برای ارسال به دیگران')
expect(self.page.locator('.pay-share-feedback')).to_contain_text('دریافت لینک ممکن نشد')
+6 -3
View File
@@ -12,9 +12,10 @@ class PaymentLinkPage(PaymentsPage):
self.page.context.grant_permissions(['clipboard-read', 'clipboard-write'])
def copied_text(self, button_name):
self.page.get_by_role('button', name=button_name, exact=True).click()
button = self.page.locator('[data-share-link] button') if button_name == 'کپی لینک کوتاه این صفحه برای ارسال به دیگران' else self.page.get_by_role('button', name=button_name, exact=True)
button.click()
if button_name == 'کپی لینک کوتاه این صفحه برای ارسال به دیگران':
expect(self.page.locator('.pay-share-feedback')).to_contain_text('لینک آماده است')
expect(self.page.locator('.pay-share-feedback')).to_contain_text('لینک آماده است' if self.manual_copy else 'لینک کوتاه کپی شد')
if self.manual_copy:
dialog = self.page.get_by_role('dialog')
expect(dialog).to_be_visible()
@@ -26,7 +27,9 @@ class PaymentLinkPage(PaymentsPage):
def copy_short_link(self):
value = self.copied_text('کپی لینک کوتاه این صفحه برای ارسال به دیگران')
expect(self.page.locator('.pay-share-feedback')).to_contain_text('لینک آماده است')
expect(self.page.locator('[data-share-link] button')).to_be_enabled()
expect(self.page.locator('[data-share-link] button')).not_to_have_attribute('aria-busy', 'true')
expect(self.page.locator('[data-share-link] button')).to_have_text('کپی لینک کوتاه این صفحه برای ارسال به دیگران' if self.manual_copy else 'لینک کپی شد؛ کپی دوباره')
return value
def open_link(self, path):
+55
View File
@@ -0,0 +1,55 @@
import pytest
from django.urls import reverse
from playwright.sync_api import expect
from apps.payments import services
from tests.e2e.pages.auth import AuthenticationPage
from tests.e2e.pages.payment_feedback import PaymentFeedbackPage
from tests.e2e.pages.payment_link import PaymentLinkPage
from tests.e2e.test_payments_e2e import payment_case, PASSWORD
pytestmark = [pytest.mark.e2e, pytest.mark.django_db(transaction=True)]
@pytest.mark.parametrize('width', [320, 1440])
def test_notice_toman_words_are_exact_for_small_large_and_localized_rial_inputs(live_server, browser_page, payment_case, width):
customer, account, reviewers = payment_case
samples = [('0', 'صفر'), ('1', 'یک دهم'), ('10', 'یک'), ('19', 'یک و نه دهم'), ('20', 'دو'),
('101', 'ده و یک دهم'), ('1001', 'صد و یک دهم'), ('1000000', 'صد هزار'),
('۱۲٬۳۴۵', 'هزار و دویست و سی و چهار و پنج دهم'), ('١٢٣٤٥', 'هزار و دویست و سی و چهار و پنج دهم'),
('1234567890', 'صد و بیست و سه میلیون و چهارصد و پنجاه و شش هزار و هفتصد و هشتاد و نه'),
('9007199254740991', 'نهصد تریلیون و هفتصد و نوزده میلیارد و نهصد و بیست و پنج میلیون و چهارصد و هفتاد و چهار هزار و نود و نه و یک دهم')]
with browser_page() as page:
page.set_viewport_size({'width': width, 'height': 900})
AuthenticationPage(page, live_server.url).login_staff(reviewers[0], PASSWORD)
view = PaymentFeedbackPage(page, live_server.url)
view.goto(reverse('staff_payments:notice_new'))
for raw, words in samples:
view.check_amount(raw, 'معادل: ' + words + ' تومان')
for invalid in ['', '12.5', '-100', '12abc', '9007199254740992']:
view.check_amount(invalid, '')
assert page.evaluate('document.documentElement.scrollWidth <= document.documentElement.clientWidth + 1')
def test_share_pending_failure_retry_and_repeated_success_restore_button(live_server, browser_page, payment_case):
customer, account, reviewers = payment_case
notice = services.issue_notice(reviewers[0], {'customer': customer, 'account': account,
'subject': 'آزمون وضعیت کپی لینک', 'amount': 10000})
endpoint = live_server.url + reverse('payments:notice_share_link', args=[notice.public_id])
pending = []
with browser_page() as page:
view = PaymentLinkPage(page, live_server.url)
view.prepare_copy()
AuthenticationPage(page, live_server.url).login_customer(customer, PASSWORD)
view.goto(reverse('payments:notice_detail', args=[notice.public_id]))
page.route(endpoint, lambda route: pending.append(route))
feedback = PaymentFeedbackPage(page, live_server.url)
feedback.request_share()
feedback.expect_pending_share()
expect(page.locator('.pay-share-feedback')).to_have_text('در حال آماده‌سازی لینک…')
assert len(pending) == 1
pending[0].fulfill(status=503, content_type='application/json', body='{}')
feedback.expect_failed_share()
page.unroute(endpoint)
first = view.copy_short_link()
assert view.copy_short_link() == first