from django.urls import reverse from playwright.sync_api import expect from tests.e2e.pages.base import BasePage class MagicLinkConfirmationPage(BasePage): def open(self, token): self.goto(reverse("accounts:magic", args=[token])) expect(self.page.get_by_role("heading", name="این لینک مربوط به حساب دیگری است")).to_be_visible() @property def continue_button(self): return self.page.get_by_role("button", name="خروج از حساب و مشاهده تیکت", exact=True) @property def cancel_link(self): return self.page.get_by_role("link", name="انصراف از مشاهده این تیکت/پیام", exact=True) def continue_to_ticket(self, ticket): self.continue_button.click() expect(self.page).to_have_url(self.url(reverse("tickets:detail", args=[ticket.public_id]))) expect(self.page.get_by_role("heading", name=ticket.subject, exact=True)).to_be_visible() expect(self.page.get_by_text("فقط به همین تیکت دسترسی دارید", exact=False)).to_be_visible() def cancel(self): self.cancel_link.click() expect(self.page).to_have_url(self.url(reverse("payments:home"))) def expect_readable_layout(self): expect(self.continue_button).to_be_visible() expect(self.cancel_link).to_be_visible() metrics = self.page.evaluate("""() => ({ width: document.documentElement.clientWidth, scrollWidth: document.documentElement.scrollWidth, textSize: parseFloat(getComputedStyle(document.querySelector('#confirmation-description')).fontSize), background: getComputedStyle(document.querySelector('.magic-confirmation-primary')).backgroundColor, color: getComputedStyle(document.querySelector('.magic-confirmation-primary')).color, })""") assert metrics["scrollWidth"] <= metrics["width"] assert metrics["textSize"] >= 16 assert metrics["background"] == "rgb(8, 55, 107)" and metrics["color"] == "rgb(255, 255, 255)" for control in (self.continue_button, self.cancel_link): assert control.bounding_box()["height"] >= 44