Pin-unpin messages in chats

Signed-off-by: Serhy <sergii@status.im>
This commit is contained in:
Serhy 2021-07-20 11:34:10 +03:00
parent 56d29866da
commit fe0a67dc65
No known key found for this signature in database
GPG Key ID: 5D7C4B9E2B6F500B
4 changed files with 153 additions and 3 deletions

View File

@ -87,7 +87,7 @@
[quo/list-item
{:title (i18n/label :t/pinned-messages)
:size :small
:accessibility-label :profile-nickname-item
:accessibility-label :pinned-messages-item
:accessory :text
:accessory-text pin-count
:disabled (zero? pin-count)

View File

@ -441,6 +441,112 @@ class TestMessagesOneToOneChatMultiple(MultipleDeviceTestCase):
self.errors.verify_no_errors()
@marks.testrail_id(695847)
@marks.medium
def test_can_pin_messages_in_ono_to_one_and_group_chats(self):
self.create_drivers(2)
device_1, device_2 = SignInView(self.drivers[0]), SignInView(self.drivers[1])
home_1, home_2 = device_1.create_user(), device_2.create_user()
public_key_1, username_1 = home_1.get_public_key_and_username(return_username=True)
public_key_2, username_2 = home_2.get_public_key_and_username(return_username=True)
home_1.home_button.click()
chat_1 = home_1.add_contact(public_key_2)
home_1.just_fyi("Check that Device1 can pin own message in 1-1 chat")
message_1,message_2,message_3,message_4 = "Message1","Message2","Message3","Message4",
chat_1.send_message(message_1)
chat_1.send_message(message_2)
chat_1.pin_message(message_1)
if not chat_1.chat_element_by_text(message_1).pinned_by_label.is_element_present():
self.drivers[0].fail("Message is not pinned!")
home_1.just_fyi("Check that Device2 can pin Device1 message in 1-1 chat and two pinned "
"messages are in Device1 profile")
home_2.home_button.click()
chat_2 = home_2.get_chat(username_1).click()
chat_2.pin_message(message_2)
chat_2.chat_options.click()
chat_2.view_profile_button.click()
if not chat_2.pinned_messages_button.count == "2":
self.drivers[0].fail("Pinned message count is not 2 as expected!")
home_1.just_fyi("Check pinned message are visible in Pinned panel for both users")
chat_1.chat_options.click()
chat_1.view_profile_button.click()
chat_1.pinned_messages_button.click()
if not (chat_1.chat_element_by_text(message_1).pinned_by_label.is_element_present() and
chat_1.chat_element_by_text(message_2).pinned_by_label.is_element_present() and
chat_1.chat_element_by_text(message_1).is_element_present() and
chat_1.chat_element_by_text(message_2).is_element_present()):
self.drivers[0].fail("Something missed on Pinned messaged on Device 1!")
chat_2.pinned_messages_button.click()
if not (chat_1.chat_element_by_text(message_1).pinned_by_label.is_element_present() and
chat_2.chat_element_by_text(message_2).pinned_by_label.is_element_present() and
chat_2.chat_element_by_text(message_1).is_element_present() and
chat_2.chat_element_by_text(message_2).is_element_present()):
self.drivers[0].fail("Something missed on Pinned messaged on Device 2!")
chat_1.close_button.click()
home_1.just_fyi("Check that Device1 can not pin more than 3 messages and 'Unpin' dialog appears"
"messages are in Device1 profile")
chat_1.send_message(message_3)
chat_1.send_message(message_4)
chat_1.pin_message(message_3)
chat_1.pin_message(message_4)
if not chat_1.unpin_message_popup.is_element_present():
self.drivers[0].fail("No 'Unpin' dialog appears when pining 4th message")
home_1.just_fyi("Unpin one message so that another could be pinned")
chat_1.unpin_message_popup.message_text(message_1).click()
chat_1.unpin_message_popup.click_unpin_message_button()
if chat_1.unpin_message_popup.is_element_present():
self.drivers[0].fail("Unpin message pop up keep staying after Unpin button pressed")
if chat_1.chat_element_by_text(message_1).pinned_by_label.is_element_present():
self.drivers[0].fail("Message is not unpinned!")
if not chat_1.chat_element_by_text(message_4).pinned_by_label.is_element_present():
self.drivers[0].fail("Message is not pinned!")
home_1.just_fyi("Unpin another message and check it's unpinned for another user")
chat_2.close_button.click()
chat_2.pin_message(message_4, action="unpin")
chat_1.chat_element_by_text(message_4).pinned_by_label.wait_for_invisibility_of_element()
if chat_1.chat_element_by_text(message_4).pinned_by_label.is_element_present():
self.drivers[0].fail("Message_4 is not unpinned!")
home_1.just_fyi("Create group chat and pin message there. It's pinned for both members.")
chat_2.home_button.click()
chat_1.home_button.click()
group_chat_name = "GroupChat"
group_chat_1 = home_1.create_group_chat(user_names_to_add=[username_2], group_chat_name=group_chat_name)
home_2.get_chat(group_chat_name).click()
group_chat_2 = home_2.get_chat_view()
group_chat_2.join_chat_button.click()
group_chat_1.send_message(message_1)
group_chat_1.pin_message(message_1)
if not (group_chat_1.chat_element_by_text(message_1).pinned_by_label.is_element_present() and
group_chat_2.chat_element_by_text(message_1).pinned_by_label.is_element_present()):
self.errors.append("Message is not pinned in group chat!")
home_1.just_fyi("Check that non admin user can not unpin messages")
group_chat_2.chat_element_by_text(message_1).long_press_element()
if group_chat_2.element_by_translation_id("unpin").is_element_present():
self.errors.append("Unpin option is available for non-admin user")
home_1.just_fyi("Grant another user with admin rights and check he can unpin message now")
group_chat_1.chat_options.click()
group_info_view = group_chat_1.group_info.click()
options = group_info_view.get_username_options(username_2).click()
options.make_admin_button.click()
group_chat_2.click_system_back_button()
group_chat_2.pin_message(message_1, action="unpin")
if (group_chat_1.chat_element_by_text(message_1).pinned_by_label.is_element_present() and
group_chat_2.chat_element_by_text(message_1).pinned_by_label.is_element_present()):
self.errors.append("Message failed be unpinned by user who granted admin permissions!")
self.errors.verify_no_errors()
@marks.testrail_id(5373)
@marks.high
def test_send_and_open_links_with_previews(self):

View File

@ -226,6 +226,13 @@ class ChatElementByText(Text):
return 0
return int(EmojisNumber(self.driver, self.locator).text)
@property
def pinned_by_label(self):
class PinnedByLabelText(Text):
def __init__(self, driver, parent_locator: str):
super().__init__(driver, prefix=parent_locator,
xpath="/../..//android.view.ViewGroup[@content-desc='pinned-by']")
return PinnedByLabelText(self.driver, self.locator)
class UsernameOptions(Button):
def __init__(self, driver, username):
@ -336,7 +343,7 @@ class CommunityView(HomeView):
class PreviewMessage(ChatElementByText):
def __init__(self, driver, text:str):
super().__init__(driver, text=text)
self.locator+="/android.view.ViewGroup/android.view.ViewGroup"
self.locator += "/android.view.ViewGroup/android.view.ViewGroup"
@staticmethod
def return_element_or_empty(obj):
@ -486,6 +493,36 @@ class IncomingTransaction(TransactionMessage):
return AcceptAndShareAddress(self.driver, self.locator)
class PinnedMessagesOnProfileButton(Button):
def __init__(self, driver):
super().__init__(driver, xpath="//*[@content-desc='pinned-messages-item']")
@property
def count(self):
class PinnedMessageCounter(Text):
def __init__(self, driver, parent_locator: str):
super().__init__(driver, prefix=parent_locator, xpath="/android.widget.TextView[2]")
return PinnedMessageCounter(self.driver, self.locator).text
class UnpinMessagePopUp(BaseElement):
def __init__(self, driver):
#self.message_text = message_text
super().__init__(driver, translation_id="pin-limit-reached", suffix='/..')
def click_unpin_message_button(self):
class UnpinMessageButton(Button):
def __init__(self, driver, parent_locator: str):
super().__init__(driver, prefix=parent_locator, xpath="//android.widget.TextView[starts-with(@text,'Unpin')]")
return UnpinMessageButton(self.driver, self.locator).click()
def message_text(self, text):
element = Text(self.driver, prefix=self.locator,
xpath="//android.widget.TextView[contains(@text,'%s')]" % text)
return element
class ChatView(BaseView):
def __init__(self, driver):
super().__init__(driver)
@ -523,6 +560,7 @@ class ChatView(BaseView):
# General chat view
self.history_start_icon = Button(self.driver, accessibility_id="history-chat")
self.unpin_message_popup = UnpinMessagePopUp(self.driver)
#Stickers
self.show_stickers_button = Button(self.driver, accessibility_id="show-stickers-icon")
@ -589,6 +627,7 @@ class ChatView(BaseView):
self.profile_nickname = Text(self.driver,
xpath="//*[@content-desc='profile-nickname-item']/android.widget.TextView[2]")
self.profile_nickname_button = Button(self.driver, accessibility_id="profile-nickname-item")
self.pinned_messages_button = PinnedMessagesOnProfileButton(self.driver)
self.nickname_input_field = EditBox(self.driver, accessibility_id="nickname-input")
self.remove_from_contacts = Button(self.driver, accessibility_id="Remove from contacts-item-button")
@ -723,6 +762,11 @@ class ChatView(BaseView):
self.chat_message_input.send_keys(message)
self.send_message_button.click()
def pin_message(self, message, action="pin"):
self.driver.info("**Looking for message '%s' pin**" % message)
self.element_by_text_part(message).long_press_element()
self.element_by_translation_id(action).click()
def edit_message_in_chat(self, message_to_edit, message_to_update):
self.driver.info("**Looking for message '%s' to edit it**" % message_to_edit)
self.element_by_text_part(message_to_edit).long_press_element()

View File

@ -4,6 +4,7 @@ from views.base_element import Button, Text, BaseElement, SilentButton
from views.base_view import BaseView
from tests import test_dapp_url
class ChatButton(Button):
def __init__(self, driver, **kwargs):
super().__init__(driver, **kwargs)
@ -12,7 +13,6 @@ class ChatButton(Button):
from views.chat_view import ChatView
return ChatView(self.driver)
class ChatElement(SilentButton):
def __init__(self, driver, username_part, community=False):
self.username = username_part