Files
customerTicket/tests/e2e/test_payment_daily_summary_e2e.py

62 lines
3.8 KiB
Python

import uuid
import pytest
from django.core.files.uploadedfile import SimpleUploadedFile
from django.utils import timezone
from playwright.sync_api import expect
from apps.payments import services
from apps.payments.models import MAX_AMOUNT
from tests.e2e.pages.auth import AuthenticationPage
from tests.e2e.pages.staff_payments import StaffPaymentsPage
from tests.e2e.test_payments_e2e import PASSWORD, PNG, payment_case
pytestmark = [pytest.mark.e2e, pytest.mark.django_db(transaction=True)]
def test_daily_summary_mobile_desktop_and_filtered_empty_results(live_server, browser_page, payment_case, tmp_path):
customer, account, reviewers = payment_case
services.issue_notice(reviewers[0], {'customer': customer, 'account': account,
'amount': 100000, 'subject': 'اعلامیه آزمایشی', 'description': '', 'deposit_id': ''})
receipt = services.submit_receipt(customer, customer, {
'paid_amount': MAX_AMOUNT, 'paid_date': timezone.localdate(),
'destination_account': account, 'depositor_name': 'مشتری آزمایشی',
'submission_key': uuid.uuid4(),
'receipt_image': SimpleUploadedFile('receipt.png', PNG, content_type='image/png'),
})
services.decide_receipt(reviewers[0], receipt.public_id, 1, 'APPROVE')
services.decide_receipt(reviewers[1], receipt.public_id, 1, 'APPROVE')
with browser_page() as page:
AuthenticationPage(page, live_server.url).login_staff(reviewers[0], PASSWORD)
workspace = StaffPaymentsPage(page, live_server.url)
workspace.open_desk()
summary = workspace.daily_summary
expect(summary).to_be_visible()
expect(summary.locator('[data-summary=submitted]')).to_contain_text('1 فیش')
expect(summary.locator('[data-summary=approved]')).to_contain_text('1 فیش')
expect(summary.locator('[data-summary=rejected]')).to_contain_text('0 فیش')
expect(summary.locator('[data-summary=pending]')).to_contain_text('0 فیش')
expect(summary.locator('[data-summary=notices]')).to_contain_text('1 اعلامیه')
amount = f'{MAX_AMOUNT:,}'
expect(summary.locator('[data-summary=approved]')).to_contain_text(amount)
for width, height in [(320, 568), (360, 640), (390, 844), (768, 1024), (1440, 900)]:
page.set_viewport_size({'width': width, 'height': height})
expect(summary).to_be_visible()
assert page.evaluate('document.documentElement.scrollWidth <= document.documentElement.clientWidth + 1')
assert summary.evaluate('(el) => el.scrollWidth <= el.clientWidth + 1')
page.screenshot(path=tmp_path / f'payment-summary-{width}.png', full_page=True)
page.set_viewport_size({'width': 320, 'height': 568})
page.evaluate("document.documentElement.style.fontSize = '200%'")
assert summary.evaluate('(el) => el.scrollWidth <= el.clientWidth + 1')
expect(summary.locator('[data-summary=approved]')).to_contain_text(amount)
workspace.open_summary_definitions()
definitions = summary.locator('.pay-day-definitions')
for title in ['ارسالی امروز:', 'تأیید امروز:', 'رد امروز:', 'در انتظار بررسی:', 'اعلامیه امروز:', 'قواعد مشترک:']:
expect(definitions.get_by_text(title, exact=True)).to_be_visible()
expect(definitions).not_to_contain_text('امروز بر اساس ساعت تهران است')
page.evaluate("document.documentElement.style.fontSize = ''")
workspace.search('no-such-customer')
expect(page.get_by_text('موردی پیدا نشد', exact=True)).to_be_visible()
expect(summary.locator('[data-summary=approved]')).to_contain_text('1 فیش')
expect(summary.locator('[data-summary=approved]')).to_contain_text(amount)