Skip to content

Commit 166ea04

Browse files
mastastnymdujava
authored andcommitted
Add admin-dashboard message counter test
1 parent cd81aae commit 166ea04

File tree

3 files changed

+134
-1
lines changed

3 files changed

+134
-1
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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)

testsuite/ui/views/admin/audience/messages.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"""View representations of Messages pages"""
22

3+
import re
4+
35
from widgetastic.widget import GenericLocatorWidget, View, Text
46
from widgetastic_patternfly import TextInput
5-
from widgetastic_patternfly4 import Button, PatternflyTable
7+
8+
from widgetastic_patternfly4 import Button, PatternflyTable, Dropdown
9+
from widgetastic_patternfly4.ouia import Dropdown as OUIADropdown
610

711
from testsuite.ui.navigation import step
812
from testsuite.ui.views.admin.audience import BaseAudienceView
@@ -16,6 +20,54 @@ class MessagesView(BaseAudienceView):
1620
table = PatternflyTable("//table[@aria-label='Messages table']")
1721
compose_msg_link = GenericLocatorWidget("//*[contains(@href,'/p/admin/messages/outbox/new')]")
1822
empty_inbox = Text("//div[text()='Your inbox is empty, there are no new messages.']")
23+
select_dropdown = OUIADropdown(component_id="OUIA-Generated-Dropdown-1")
24+
# This dropdown does not have page unique component id
25+
actions_dropdown = Dropdown(
26+
None, locator="//div[@id='pf-random-id-0']//div[@data-ouia-component-id='OUIA-Generated-Dropdown-2']"
27+
)
28+
delete_dialog_button = Button(locator='//div[@id="colorbox"]//button[contains(text(), "Delete")]')
29+
30+
def delete_all(self):
31+
"""
32+
Deletes all massages from the inbox
33+
"""
34+
if self.empty_inbox.is_displayed:
35+
return
36+
items = self.select_dropdown.items
37+
select_all_item = [s for s in items if re.match("Select all.*", s)][0]
38+
self.select_dropdown.item_select(select_all_item) # item_select does not have better selector than exact text
39+
self.actions_dropdown.open()
40+
self.actions_dropdown.item_select("Delete")
41+
self.delete_dialog_button.wait_displayed(timeout="1s")
42+
self.delete_dialog_button.click()
43+
44+
def delete_message(self, **kwargs):
45+
"""
46+
Deletes first message with which matches given text values in columns
47+
e.g. delete_message(Subject='subject1, From='user1') will delete message with subject subject1 from
48+
user user1 if such message exists and is not already deleted.
49+
"""
50+
row = self.table.row(**kwargs)
51+
if row.From.text != "(deleted)":
52+
row[4].click()
53+
54+
def get_unread_msg_link(self, **kwargs):
55+
"""Returns link to the first unread message, None if such message does not exist
56+
**kwargs: Allows filter rows by values in the columns.
57+
Keys are names of the columns, values are text values in the specified column.
58+
"""
59+
return self.table.row(_row__attr=("class", "unread"), **kwargs).Subject.browser.element("./a")
60+
61+
def get_first_unread_msg_link_gen(self):
62+
"""
63+
Returns generator, that returns link to the first unread message until, such message exists.
64+
"""
65+
while True:
66+
link = self.get_unread_msg_link()
67+
if link:
68+
yield link
69+
else:
70+
break
1971

2072
def prerequisite(self):
2173
return BaseAudienceView

testsuite/ui/views/admin/foundation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,22 @@ class DashboardView(BaseAdminView):
7878
billing_link = Text('//a[@href="/finance"]')
7979
develop_portal_link = Text('//a[@href="/p/admin/cms"]')
8080
message_link = Text('//a[@href="/p/admin/messages"]')
81+
unread_messages_count = Text("//li[a[@href='/p/admin/messages']]/span[@class='u-notice']")
8182
explore_all_products = Text('//a[@href="/apiconfig/services"]')
8283
explore_all_backends = Text('//a[@href="/p/admin/backend_apis"]')
8384

85+
@property
86+
def msg_count(self):
87+
"""Return number of messages in the inbox"""
88+
return int(self.message_link.text.split()[0])
89+
90+
@property
91+
def unread_msg_count(self):
92+
"""Returns number of unread messages"""
93+
if not self.unread_messages_count.is_displayed:
94+
return 0
95+
return int(self.unread_messages_count.text)
96+
8497
@View.nested
8598
# pylint: disable=invalid-name
8699
class backends(View):

0 commit comments

Comments
 (0)