Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add admin-dashboard message counter test #855

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions testsuite/tests/ui/mail_and_messages/test_message_counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Test of message counters in dashboard main-section tabs"""

import pytest

from testsuite.ui.views.admin.audience.messages import MessagesView
from testsuite.ui.views.admin.foundation import DashboardView
from testsuite.ui.views.devel.messages import ComposeView


def assert_dashboard_counters(navigator, message_count, unread_count):
"""
Asserts counters in the messages tab in admin dashboard
"""
admin_dashboard_view = navigator.navigate(DashboardView)
assert admin_dashboard_view.msg_count == message_count
assert admin_dashboard_view.unread_msg_count == unread_count


def send_message_from_devel(navigator, subject, body):
"""
Sends the message from the developer portal
"""
devel_compose_view = navigator.navigate(ComposeView)
devel_compose_view.send_message(subject, body)


# pylint: disable=too-many-arguments
@pytest.mark.usefixtures("login", "application", "service")
def test_message_counter(custom_devel_login, custom_admin_login, account, navigator):
"""
Test:
- Take a note of number of messages (msg_count) and unread messages (unread_count) in messages tab in
admin dashboard
- Send two e-mails from developer to admin
- Assert that messages tab in admin dashboard shows msg_count + 2 messages and unread_count + 2 unread messages
- Read two new messages
- Assert that messages tab in admin dashboard msg_count + 2 messages and unread_count + 2 unread messages
- Delete two new messages
- Assert that messages tab in admin dashboard shows msg_count messages and unread_count unread messages
"""
admin_dashboard_view = navigator.navigate(DashboardView)
start_msg_count = admin_dashboard_view.msg_count
start_unread_msg_count = admin_dashboard_view.unread_msg_count

custom_devel_login(account)
send_message_from_devel(navigator, "subject1", "body1")
send_message_from_devel(navigator, "subject2", "body2")

custom_admin_login(account)
assert_dashboard_counters(navigator, start_msg_count + 2, start_unread_msg_count + 2)

admin_messages_view = navigator.navigate(MessagesView)
link = admin_messages_view.get_unread_msg_link(Subject="subject1", From=account.entity_name)
link.click()
admin_messages_view = navigator.navigate(MessagesView)
link = admin_messages_view.get_unread_msg_link(Subject="subject2", From=account.entity_name)
link.click()

assert_dashboard_counters(navigator, start_msg_count + 2, start_unread_msg_count + 0)

admin_messages_view = navigator.navigate(MessagesView)
admin_messages_view.delete_message(Subject="subject1", From=account.entity_name)
admin_messages_view.delete_message(Subject="subject2", From=account.entity_name)

assert_dashboard_counters(navigator, start_msg_count + 0, start_unread_msg_count + 0)
54 changes: 53 additions & 1 deletion testsuite/ui/views/admin/audience/messages.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
"""View representations of Messages pages"""

import re

from widgetastic.widget import GenericLocatorWidget, View, Text
from widgetastic_patternfly import TextInput
from widgetastic_patternfly4 import Button, PatternflyTable

from widgetastic_patternfly4 import Button, PatternflyTable, Dropdown
from widgetastic_patternfly4.ouia import Dropdown as OUIADropdown

from testsuite.ui.navigation import step
from testsuite.ui.views.admin.audience import BaseAudienceView
Expand All @@ -16,6 +20,54 @@ class MessagesView(BaseAudienceView):
table = PatternflyTable("//table[@aria-label='Messages table']")
compose_msg_link = GenericLocatorWidget("//*[contains(@href,'/p/admin/messages/outbox/new')]")
empty_inbox = Text("//div[text()='Your inbox is empty, there are no new messages.']")
select_dropdown = OUIADropdown(component_id="OUIA-Generated-Dropdown-1")
# This dropdown does not have page unique component id
actions_dropdown = Dropdown(
None, locator="//div[@id='pf-random-id-0']//div[@data-ouia-component-id='OUIA-Generated-Dropdown-2']"
)
delete_dialog_button = Button(locator='//div[@id="colorbox"]//button[contains(text(), "Delete")]')

def delete_all(self):
"""
Deletes all massages from the inbox
"""
if self.empty_inbox.is_displayed:
return
items = self.select_dropdown.items
select_all_item = [s for s in items if re.match("Select all.*", s)][0]
self.select_dropdown.item_select(select_all_item) # item_select does not have better selector than exact text
self.actions_dropdown.open()
self.actions_dropdown.item_select("Delete")
self.delete_dialog_button.wait_displayed(timeout="1s")
self.delete_dialog_button.click()

def delete_message(self, **kwargs):
"""
Deletes first message with which matches given text values in columns
e.g. delete_message(Subject='subject1, From='user1') will delete message with subject subject1 from
user user1 if such message exists and is not already deleted.
"""
row = self.table.row(**kwargs)
if row.From.text != "(deleted)":
row[4].click()

def get_unread_msg_link(self, **kwargs):
"""Returns link to the first unread message, None if such message does not exist
**kwargs: Allows filter rows by values in the columns.
Keys are names of the columns, values are text values in the specified column.
"""
return self.table.row(_row__attr=("class", "unread"), **kwargs).Subject.browser.element("./a")

def get_first_unread_msg_link_gen(self):
"""
Returns generator, that returns link to the first unread message until, such message exists.
"""
while True:
link = self.get_unread_msg_link()
if link:
yield link
else:
break

def prerequisite(self):
return BaseAudienceView
Expand Down
13 changes: 13 additions & 0 deletions testsuite/ui/views/admin/foundation.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,22 @@ class DashboardView(BaseAdminView):
billing_link = Text('//a[@href="/finance"]')
develop_portal_link = Text('//a[@href="/p/admin/cms"]')
message_link = Text('//a[@href="/p/admin/messages"]')
unread_messages_count = Text("//li[a[@href='/p/admin/messages']]/span[@class='u-notice']")
explore_all_products = Text('//a[@href="/apiconfig/services"]')
explore_all_backends = Text('//a[@href="/p/admin/backend_apis"]')

@property
def msg_count(self):
"""Return number of messages in the inbox"""
return int(self.message_link.text.split()[0])

@property
def unread_msg_count(self):
"""Returns number of unread messages"""
if not self.unread_messages_count.is_displayed:
return 0
return int(self.unread_messages_count.text)

@View.nested
# pylint: disable=invalid-name
class backends(View):
Expand Down
Loading