|
| 1 | +"""Test of message counters in dashboard main-section tabs""" |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from packaging.version import Version # noqa # pylint: disable=unused-import |
| 6 | +from testsuite import TESTED_VERSION # noqa # pylint: disable=unused-import |
| 7 | +from testsuite.ui.views.admin.audience.messages import MessagesView |
| 8 | +from testsuite.ui.views.admin.foundation import DashboardView |
| 9 | +from testsuite.ui.views.devel.messages import ComposeView |
| 10 | + |
| 11 | + |
| 12 | +def assert_dashboard_counters(navigator, message_count, unread_count): |
| 13 | + """ |
| 14 | + Asserts counters in the messages tab in admin dashboard |
| 15 | + """ |
| 16 | + admin_dashboard_view = navigator.navigate(DashboardView) |
| 17 | + assert admin_dashboard_view.msg_count == message_count |
| 18 | + assert admin_dashboard_view.unread_msg_count == unread_count |
| 19 | + |
| 20 | + |
| 21 | +def send_message_from_devel(navigator, subject, body): |
| 22 | + """ |
| 23 | + Sends the message from the developer portal |
| 24 | + """ |
| 25 | + devel_compose_view = navigator.navigate(ComposeView) |
| 26 | + devel_compose_view.send_message(subject, body) |
| 27 | + |
| 28 | + |
| 29 | +# pylint: disable=too-many-arguments |
| 30 | +@pytest.mark.skipif("TESTED_VERSION < Version('2.15')") |
| 31 | +@pytest.mark.usefixtures("login", "application", "service") |
| 32 | +def test_message_counter(custom_devel_login, custom_admin_login, account, navigator): |
| 33 | + """ |
| 34 | + Test: |
| 35 | + - Take a note of number of messages (msg_count) and unread messages (unread_count) in messages tab in |
| 36 | + admin dashboard |
| 37 | + - Send two e-mails from developer to admin |
| 38 | + - Assert that messages tab in admin dashboard shows msg_count + 2 messages and unread_count + 2 unread messages |
| 39 | + - Read two new messages |
| 40 | + - Assert that messages tab in admin dashboard msg_count + 2 messages and unread_count + 2 unread messages |
| 41 | + - Delete two new messages |
| 42 | + - Assert that messages tab in admin dashboard shows msg_count messages and unread_count unread messages |
| 43 | + """ |
| 44 | + admin_dashboard_view = navigator.navigate(DashboardView) |
| 45 | + start_msg_count = admin_dashboard_view.msg_count |
| 46 | + start_unread_msg_count = admin_dashboard_view.unread_msg_count |
| 47 | + |
| 48 | + custom_devel_login(account) |
| 49 | + send_message_from_devel(navigator, "subject1", "body1") |
| 50 | + send_message_from_devel(navigator, "subject2", "body2") |
| 51 | + |
| 52 | + custom_admin_login(account) |
| 53 | + assert_dashboard_counters(navigator, start_msg_count + 2, start_unread_msg_count + 2) |
| 54 | + |
| 55 | + admin_messages_view = navigator.navigate(MessagesView) |
| 56 | + link = admin_messages_view.get_unread_msg_link(Subject="subject1", From=account.entity_name) |
| 57 | + link.click() |
| 58 | + admin_messages_view = navigator.navigate(MessagesView) |
| 59 | + link = admin_messages_view.get_unread_msg_link(Subject="subject2", From=account.entity_name) |
| 60 | + link.click() |
| 61 | + |
| 62 | + assert_dashboard_counters(navigator, start_msg_count + 2, start_unread_msg_count + 0) |
| 63 | + |
| 64 | + admin_messages_view = navigator.navigate(MessagesView) |
| 65 | + admin_messages_view.delete_message(Subject="subject1", From=account.entity_name) |
| 66 | + admin_messages_view.delete_message(Subject="subject2", From=account.entity_name) |
| 67 | + |
| 68 | + assert_dashboard_counters(navigator, start_msg_count + 0, start_unread_msg_count + 0) |
0 commit comments