fix focus on ticket new, sitebranding, customer edit error
This commit is contained in:
1 parent
d72381f0ac
commit
6b841dc5fa
11 files changed
+139
-10
No files matched your search
@@ -12,6 +12,8 @@ class CustomerNewTicketPage(BasePage):
|
||||
|
||||
def open(self):
|
||||
self.goto("/tickets/new/")
|
||||
if not self.unit.is_visible():
|
||||
self.page.locator("details.ticket-manual-routing summary").click()
|
||||
expect(self.unit).to_be_visible()
|
||||
|
||||
def select_unit(self, unit_id: int, expected_category: str):
|
||||
|
||||
@@ -170,6 +170,10 @@ def test_e2e_customer_wizard_validation_preview_edit_and_floating_submit(
|
||||
with browser_page() as page:
|
||||
page.set_viewport_size({"width": 390, "height": 640})
|
||||
form = open_form(page, live_server, customer)
|
||||
wizard = page.locator('[data-ticket-wizard]')
|
||||
expect(wizard).to_be_focused()
|
||||
expect(wizard).to_be_in_viewport()
|
||||
assert wizard.bounding_box()["y"] < page.viewport_size["height"] / 3
|
||||
expect(page.locator('[data-wizard-step="1"]')).to_be_visible()
|
||||
expect(page.locator('[data-wizard-step="2"]')).to_be_hidden()
|
||||
expect(page.locator('[data-ticket-search-results]')).to_be_hidden()
|
||||
@@ -186,7 +190,7 @@ def test_e2e_customer_wizard_validation_preview_edit_and_floating_submit(
|
||||
form.select_search_result("عمومی فروش", "عمومی فروش")
|
||||
expect(page.locator('[data-ticket-subject]')).to_have_value("")
|
||||
page.locator('[data-wizard-step="1"] [data-wizard-next]').click()
|
||||
assert page.evaluate("document.activeElement === document.querySelector('[data-ticket-subject]')")
|
||||
expect(page.locator('[data-ticket-subject]')).to_be_focused()
|
||||
expect(page.locator('.ticket-subject-field')).to_have_class(re.compile(r"is-guided-field"))
|
||||
page.locator('[data-ticket-subject]').fill(subject)
|
||||
expect(page.locator('[data-ticket-subject]')).to_have_value(subject)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import pytest
|
||||
from django.urls import reverse
|
||||
|
||||
from apps.accounts.models import User
|
||||
from apps.accounts.models import TicketMagicLink, User
|
||||
from apps.core.models import PageTitle, SiteBranding
|
||||
from apps.customers.models import ContactGroup
|
||||
from apps.notifications.models import SMSTemplate
|
||||
from apps.staff.models import OrganizationalUnit
|
||||
from apps.tickets.models import GroupDispatch, TicketCategory
|
||||
from apps.tickets.services import create_ticket
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@@ -66,6 +67,32 @@ def test_customer_new_renders_developer_credit_once_directly_below_wizard(client
|
||||
assert '<footer class="site-footer">' not in content
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_magic_ticket_renders_database_developer_credit_once_inside_workspace(client):
|
||||
branding = SiteBranding.load()
|
||||
branding.developer_credit_text = "برنامه نویسی و توسعه: محمد جواد فصاحت | 09202202129"
|
||||
branding.save()
|
||||
customer = User.objects.create_user(
|
||||
username="magic-credit-customer", mobile="09120000414", account_type=User.AccountType.CUSTOMER
|
||||
)
|
||||
category = TicketCategory.objects.create(title="پیگیری لینک امضا", slug="magic-credit-category")
|
||||
ticket = create_ticket(customer=customer, category=category, subject="نمایش امضا", body="شرح")
|
||||
token = TicketMagicLink.issue(ticket)
|
||||
destination = client.get(reverse("accounts:magic", args=[token])).url
|
||||
|
||||
content = client.get(destination).content.decode()
|
||||
assert content.count(branding.developer_credit_text) == 1
|
||||
assert '<footer class="ticket-detail-credit">' in content
|
||||
assert content.index('class="workspace-grid customer-grid"') < content.index('<footer class="ticket-detail-credit">')
|
||||
assert '<footer class="site-footer">' not in content
|
||||
|
||||
branding.developer_credit_html = '<strong data-developer-signature>امضای HTML سفارشی</strong>'
|
||||
branding.use_developer_credit_html = True
|
||||
branding.save()
|
||||
html_content = client.get(destination).content.decode()
|
||||
assert '<strong data-developer-signature>امضای HTML سفارشی</strong>' in html_content
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_staff_sidebar_brand_is_database_backed(client):
|
||||
user = User.objects.create_superuser(username="brand-admin", password="safe-password", account_type=User.AccountType.STAFF)
|
||||
|
||||
@@ -405,6 +405,70 @@ def test_staff_can_visually_add_and_remove_contact_group_memberships(client):
|
||||
assert set(contact.customer_profile.groups.values_list("pk", flat=True)) == {second.pk}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_staff_can_classify_and_edit_ticket_customer_without_an_existing_group(client):
|
||||
unit = OrganizationalUnit.objects.create(name="واحد مشتری خودکار", slug="ungrouped-customer-editor")
|
||||
unit.permissions.add(*Permission.objects.filter(
|
||||
content_type__app_label="customers",
|
||||
codename__in=("view_customerprofile", "change_customerprofile"),
|
||||
))
|
||||
staff = make_staff("ungrouped-customer-agent", unit)
|
||||
contact = make_contact("ungrouped-ticket-customer", "09120000515")
|
||||
category = TicketCategory.objects.create(unit=unit, title="درخواست مشتری خودکار", slug="ungrouped-customer-ticket")
|
||||
create_ticket(customer=contact, created_by=staff, unit=unit, category=category, subject="نیازمند دستهبندی", body="شرح")
|
||||
group = ContactGroup.objects.create(name="گروه انتخابشده", unit=unit)
|
||||
client.force_login(staff)
|
||||
url = reverse("staff_tickets:contact_edit", args=[contact.public_id])
|
||||
|
||||
page = client.get(url)
|
||||
assert page.status_code == 200
|
||||
assert f'value="{group.pk}"' in page.content.decode()
|
||||
|
||||
missing_group = client.post(url, {
|
||||
"mobile": contact.local_mobile,
|
||||
"first_name": "مشتری",
|
||||
"last_name": "خودکار",
|
||||
"organization_name": "",
|
||||
"stakeholder_type": CustomerProfile.StakeholderType.CUSTOMER,
|
||||
"groups": [],
|
||||
"province": "",
|
||||
"city": "",
|
||||
})
|
||||
assert missing_group.status_code == 200
|
||||
assert missing_group.context["form"]["groups"].errors
|
||||
|
||||
saved = client.post(url, {
|
||||
"mobile": contact.local_mobile,
|
||||
"first_name": "مشتری",
|
||||
"last_name": "دستهبندیشده",
|
||||
"organization_name": "",
|
||||
"stakeholder_type": CustomerProfile.StakeholderType.CUSTOMER,
|
||||
"groups": [group.pk],
|
||||
"province": "",
|
||||
"city": "",
|
||||
})
|
||||
assert saved.status_code == 302
|
||||
assert contact.customer_profile.groups.filter(pk=group.pk).exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_staff_cannot_edit_ungrouped_customer_from_an_unrelated_ticket_unit(client):
|
||||
ticket_unit = OrganizationalUnit.objects.create(name="واحد مالک مشتری", slug="ungrouped-owner-unit")
|
||||
unrelated_unit = OrganizationalUnit.objects.create(name="واحد نامرتبط مشتری", slug="ungrouped-unrelated-unit")
|
||||
unrelated_unit.permissions.add(*Permission.objects.filter(
|
||||
content_type__app_label="customers",
|
||||
codename__in=("view_customerprofile", "change_customerprofile"),
|
||||
))
|
||||
owner = make_staff("ungrouped-owner-agent", ticket_unit)
|
||||
outsider = make_staff("ungrouped-outsider-agent", unrelated_unit)
|
||||
contact = make_contact("private-ungrouped-customer", "09120000516")
|
||||
category = TicketCategory.objects.create(unit=ticket_unit, title="درخواست محرمانه", slug="private-ungrouped-ticket")
|
||||
create_ticket(customer=contact, created_by=owner, unit=ticket_unit, category=category, subject="محرمانه", body="شرح")
|
||||
client.force_login(outsider)
|
||||
|
||||
assert client.get(reverse("staff_tickets:contact_edit", args=[contact.public_id])).status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_staff_ticket_create_supports_multiple_previewable_attachments(client, monkeypatch, settings, tmp_path):
|
||||
settings.MEDIA_ROOT = tmp_path
|
||||
|
||||
Reference in new issue
Block a user