chore: remove hardcoded values

This commit is contained in:
Anastasiya Semenkevich 2024-03-27 13:39:30 +03:00 committed by Anastasiya
parent f46152d07d
commit 40ef7b0f51
4 changed files with 132 additions and 84 deletions

View File

@ -15,3 +15,4 @@ class LeaveGroupPopup(BasePopup):
def confirm_leaving(self): def confirm_leaving(self):
self._leave_button.click() self._leave_button.click()
self.wait_until_hidden() self.wait_until_hidden()

View File

@ -46,7 +46,8 @@ leave_group_StatusMenuItem = {"checkable": False, "container": mainWindow_Overla
mainWindow_inputScrollView_StatusScrollView = {"container": statusDesktop_mainWindow, "id": "inputScrollView", "type": "StatusScrollView", "unnamed": 1, "visible": True} mainWindow_inputScrollView_StatusScrollView = {"container": statusDesktop_mainWindow, "id": "inputScrollView", "type": "StatusScrollView", "unnamed": 1, "visible": True}
inputScrollView_Message_PlaceholderText = {"container": mainWindow_inputScrollView_StatusScrollView, "text": "Message", "type": "PlaceholderText", "unnamed": 1, "visible": True} inputScrollView_Message_PlaceholderText = {"container": mainWindow_inputScrollView_StatusScrollView, "text": "Message", "type": "PlaceholderText", "unnamed": 1, "visible": True}
mainWindow_scrollView_StatusScrollView = {"container": statusDesktop_mainWindow, "id": "scrollView", "type": "StatusScrollView", "unnamed": 1, "visible": True} mainWindow_scrollView_StatusScrollView = {"container": statusDesktop_mainWindow, "id": "scrollView", "type": "StatusScrollView", "unnamed": 1, "visible": True}
scrollView_StatusChatListItem = {"container": mainWindow_scrollView_StatusScrollView, "type": "StatusChatListItem", "visible": True} mainWindow_ScrollView = {"container": statusDesktop_mainWindow, "type": "StatusScrollView", "unnamed": 1, "visible": True}
scrollView_StatusChatListItem = {"container": mainWindow_ScrollView, "type": "StatusChatListItem", "visible": True}
tiny_pin_icon_StatusIcon = {"container": chatLogView_chatMessageViewDelegate_MessageView, "objectName": "tiny/pin-icon", "type": "StatusIcon"} tiny_pin_icon_StatusIcon = {"container": chatLogView_chatMessageViewDelegate_MessageView, "objectName": "tiny/pin-icon", "type": "StatusIcon"}
add_remove_from_group_StatusMenuItem = {"checkable": False, "container": mainWindow_Overlay, "enabled": True, "type": "StatusMenuItem", "unnamed": 1, "visible": True} add_remove_from_group_StatusMenuItem = {"checkable": False, "container": mainWindow_Overlay, "enabled": True, "type": "StatusMenuItem", "unnamed": 1, "visible": True}
mainWindow_inputScrollView_StatusScrollView = {"container": statusDesktop_mainWindow, "id": "inputScrollView", "type": "StatusScrollView", "unnamed": 1, "visible": True} mainWindow_inputScrollView_StatusScrollView = {"container": statusDesktop_mainWindow, "id": "inputScrollView", "type": "StatusScrollView", "unnamed": 1, "visible": True}

View File

@ -31,18 +31,30 @@ class LeftPanel(QObject):
self._start_chat_button = Button(messaging_names.mainWindow_startChatButton_StatusIconTabButton) self._start_chat_button = Button(messaging_names.mainWindow_startChatButton_StatusIconTabButton)
self._search_text_edit = TextEdit(messaging_names.mainWindow_search_edit_TextEdit) self._search_text_edit = TextEdit(messaging_names.mainWindow_search_edit_TextEdit)
self._scroll = Scroll(messaging_names.scrollView_Flickable) self._scroll = Scroll(messaging_names.scrollView_Flickable)
self._contacts_list = List(messaging_names.chatList_ListView) self._chats_list = List(messaging_names.chatList_ListView)
self._contact_item = QObject(messaging_names.scrollView_StatusChatListItem) self._chat_list_item = QObject(messaging_names.scrollView_StatusChatListItem)
@property @property
@allure.step('Get contacts') @allure.step('Get contacts')
def contacts(self) -> typing.List[str]: def chats(self) -> typing.List[str]:
return self._contacts_list.get_values('objectName') return self._chats_list.get_values('objectName')
@allure.step('Open chat') @allure.step('Open chat')
def open_chat(self, contact: str): def get_chats_list(self):
assert driver.waitFor(lambda: contact in self.contacts), f'Contact: {contact} not found in {self.contacts}' chats_list = []
self._contacts_list.select(contact, 'objectName') for obj in driver.findAllObjects(self._chat_list_item.real_name):
chats_list.append(str(obj.name))
if len(chats_list) == 0:
raise LookupError(
'Chats list is empty')
else:
return chats_list
@allure.step('Click chat item')
def click_chat_by_name(self, chat_name: str):
self._chat_list_item.real_name['objectName'] = chat_name
self._chat_list_item.click()
return ChatView() return ChatView()
@allure.step('Click start chat button') @allure.step('Click start chat button')
@ -52,8 +64,8 @@ class LeftPanel(QObject):
@allure.step('Open context menu group chat') @allure.step('Open context menu group chat')
def _open_context_menu_for_chat(self, chat_name: str) -> ContextMenu: def _open_context_menu_for_chat(self, chat_name: str) -> ContextMenu:
self._contact_item.real_name['objectName'] = chat_name self._chat_list_item.real_name['objectName'] = chat_name
self._contact_item.right_click() self._chat_list_item.right_click()
return ContextMenu().wait_until_appears() return ContextMenu().wait_until_appears()
@allure.step('Open leave popup') @allure.step('Open leave popup')

View File

@ -1,3 +1,7 @@
import random
import string
import time
import allure import allure
import pytest import pytest
from allure_commons._allure import step from allure_commons._allure import step
@ -22,6 +26,9 @@ pytestmark = marks
(configs.testpath.TEST_USER_DATA / 'group_chat_user_1', configs.testpath.TEST_USER_DATA / 'group_chat_user_2', (configs.testpath.TEST_USER_DATA / 'group_chat_user_1', configs.testpath.TEST_USER_DATA / 'group_chat_user_2',
configs.testpath.TEST_USER_DATA / 'group_chat_user_3') configs.testpath.TEST_USER_DATA / 'group_chat_user_3')
]) ])
@pytest.mark.skip
# TODO: https://github.com/status-im/status-desktop/issues/14191
# TODO: https://github.com/status-im/status-desktop/issues/14193
def test_group_chat(multiple_instances, user_data_one, user_data_two, user_data_three): def test_group_chat(multiple_instances, user_data_one, user_data_two, user_data_three):
user_one: UserAccount = constants.group_chat_user_1 user_one: UserAccount = constants.group_chat_user_1
user_two: UserAccount = constants.group_chat_user_2 user_two: UserAccount = constants.group_chat_user_2
@ -30,105 +37,132 @@ def test_group_chat(multiple_instances, user_data_one, user_data_two, user_data_
main_window = MainWindow() main_window = MainWindow()
messages_screen = MessagesScreen() messages_screen = MessagesScreen()
with multiple_instances(user_data_one) as aut_one, multiple_instances(user_data_two) as aut_two, multiple_instances(user_data_three) as aut_three: with multiple_instances(user_data_one) as aut_one, multiple_instances(user_data_two) as aut_two, multiple_instances(
with step(f'Launch multiple instances with authorized users {user_one.name} and {user_two.name}'): user_data_three) as aut_three:
with step(f'Launch multiple instances with authorized users {user_one.name}, {user_two.name}, {user_three}'):
for aut, account in zip([aut_one, aut_two, aut_three], [user_one, user_two, user_three]): for aut, account in zip([aut_one, aut_two, aut_three], [user_one, user_two, user_three]):
aut.attach() aut.attach()
main_window.wait_until_appears(configs.timeouts.APP_LOAD_TIMEOUT_MSEC).prepare() main_window.wait_until_appears(configs.timeouts.APP_LOAD_TIMEOUT_MSEC).prepare()
main_window.authorize_user(account) main_window.authorize_user(account)
main_window.hide() main_window.hide()
with step(f'User {user_one.name}, start chat and add {user_two.name}'): with step(f'User {user_one.name}, start chat and add {members}'):
aut_one.attach() aut_one.attach()
main_window.prepare() main_window.prepare()
main_window.left_panel.open_messages_screen() main_window.left_panel.open_messages_screen()
messages_screen.left_panel.start_chat().create_chat(members) messages_screen.left_panel.start_chat().create_chat(members)
with step('Verify group chat info'): with step('Verify group chat info'):
with step('Verify group chat name'): with step('Verify group chat name'):
group_chat_name = user_two.name + '&' + user_three.name group_chat_name = user_two.name + '&' + user_three.name
assert messages_screen.group_chat.group_name == group_chat_name, f'Group chat name is not correct' assert messages_screen.group_chat.group_name == group_chat_name, f'Group chat name is not correct'
with step('Welcome group message is correct'): with step('Welcome group message is correct'):
actual_welcome_message = messages_screen.group_chat.group_welcome_message actual_welcome_message = messages_screen.group_chat.group_welcome_message
assert actual_welcome_message.startswith(Messaging.WELCOME_GROUP_MESSAGE.value) assert actual_welcome_message.startswith(Messaging.WELCOME_GROUP_MESSAGE.value)
assert actual_welcome_message.endswith(' group!') assert actual_welcome_message.endswith(' group!')
assert group_chat_name in actual_welcome_message assert group_chat_name in actual_welcome_message
with step('Verify there are three members in group members list'): with step('Verify there are three members in group members list'):
assert user_one.name in messages_screen.right_panel.members
assert user_two.name in messages_screen.right_panel.members
assert user_three.name in messages_screen.right_panel.members
assert len(messages_screen.right_panel.members) == 3
with step('Open edit group name and image form and change name'):
group_chat_new_name = ''.join(random.choices(string.ascii_letters +
string.digits, k=24))
edit_group_popup = messages_screen.group_chat.open_edit_group_name_form()
edit_group_popup.change_group_name(group_chat_new_name)
edit_group_popup.save_changes()
with step('Verify group chat name is changed'):
assert messages_screen.group_chat.group_name == group_chat_new_name
with step('Send message to group chat and verify it was sent'):
chat_message = ''.join(random.choices(string.ascii_letters +
string.digits, k=40))
messages_screen.group_chat.send_message_to_group_chat(chat_message)
message_objects = messages_screen.chat.messages('0')
message_items = [message.text for message in message_objects]
for message_item in message_items:
assert chat_message in message_item
with step(f'Remove {user_three.name} from group'):
messages_screen.group_chat.remove_member_from_chat(user_three.name)
with step('Verify members in a group members list'):
assert driver.waitFor(lambda: user_one.name in messages_screen.right_panel.members,
configs.timeouts.UI_LOAD_TIMEOUT_MSEC)
assert user_two.name in messages_screen.right_panel.members
assert user_three.name not in messages_screen.right_panel.members
assert len(messages_screen.right_panel.members) == 2
main_window.hide()
with step(f'Check group members and message for {user_two.name}'):
aut_two.attach()
main_window.prepare()
assert group_chat_new_name in messages_screen.left_panel.get_chats_list(), \
f'{group_chat_new_name} is not present in chats list for {aut_two}'
messages_screen.left_panel.click_chat_by_name(group_chat_new_name)
with step('Verify members in a group members list'):
assert user_one.name in messages_screen.right_panel.members assert user_one.name in messages_screen.right_panel.members
assert user_two.name in messages_screen.right_panel.members assert user_two.name in messages_screen.right_panel.members
assert user_three.name in messages_screen.right_panel.members assert user_three.name not in messages_screen.right_panel.members
assert len(messages_screen.right_panel.members) == 3 assert len(messages_screen.right_panel.members) == 2
with step('Open edit group name and image form and change name'): with step('Send message to group chat after user removal and verify it'):
new_name = 'New_name' chat_message_2 = ''.join(random.choices(string.ascii_letters +
edit_group_popup = messages_screen.group_chat.open_edit_group_name_form() string.digits, k=40))
edit_group_popup.change_group_name(new_name) messages_screen.group_chat.send_message_to_group_chat(chat_message_2)
edit_group_popup.save_changes() message_objects = messages_screen.chat.messages('1')
message_items = [message.text for message in message_objects]
for message_item in message_items:
assert chat_message_2 in message_item
with step('Verify group chat name is changed'): with step('Leave group'):
assert messages_screen.group_chat.group_name == new_name messages_screen.left_panel.open_leave_group_popup(group_chat_new_name).confirm_leaving()
with step('Send message to group chat and verify it was sent'): with step('Check that group name is not displayed on left panel'):
messages_screen.group_chat.send_message_to_group_chat('Hi') assert group_chat_new_name not in messages_screen.left_panel.get_chats_list()
message_objects = messages_screen.chat.messages('0')
message_items = [message.text for message in message_objects]
for message_item in message_items:
assert 'Hi' in message_item
with step(f'Remove {user_three.name} from group'):
messages_screen.group_chat.remove_member_from_chat(user_three.name)
with step('Verify there are two members in group members list'):
assert driver.waitFor(lambda: user_one.name in messages_screen.right_panel.members, configs.timeouts.UI_LOAD_TIMEOUT_MSEC)
assert user_two.name in messages_screen.right_panel.members
assert len(messages_screen.right_panel.members) == 2
main_window.hide() main_window.hide()
with step(f'Restart app for {user_two.name} and open group chat'): with step(f'Check group members and message for {user_three.name}'):
aut_two.restart() aut_three.attach()
main_window.authorize_user(user_two) main_window.prepare()
messages_screen.left_panel.open_chat(new_name)
with step('Verify there are three members in group members list'): with step(f'Check that {user_three.name} is not a member of a group'):
assert user_one.name in messages_screen.right_panel.members assert group_chat_new_name in messages_screen.left_panel.get_chats_list(), \
assert user_two.name in messages_screen.right_panel.members f'{group_chat_new_name} is not present in chats list for {aut_three}'
assert len(messages_screen.right_panel.members) == 2 messages_screen.left_panel.click_chat_by_name(group_chat_new_name)
gray_message_text = messages_screen.group_chat.gray_text_from_message_area
assert gray_message_text == Messaging.YOU_NEED_TO_BE_A_MEMBER.value
assert not messages_screen.group_chat.is_message_area_enabled
with step('Send message to group chat and verify it was sent'): with step('Verify members in a group members list'):
messages_screen.group_chat.send_message_to_group_chat('Hi') assert user_one.name in messages_screen.right_panel.members
message_objects = messages_screen.chat.messages('1') assert user_two.name in messages_screen.right_panel.members is False
message_items = [message.text for message in message_objects] assert user_three.name in messages_screen.right_panel.members is False
for message_item in message_items: assert len(messages_screen.right_panel.members) == 2 # it has to be 2 since user3 is kicked and not
assert 'Hi' in message_item # receiving any updates from that moment
with step('Leave group'): with step('Leave group'):
messages_screen.left_panel.open_leave_group_popup(new_name).confirm_leaving() messages_screen.group_chat.leave_group().confirm_leaving()
with step('Check that group name is not displayed on left panel'): with step('Check that group name is not displayed on left panel'):
assert new_name not in messages_screen.left_panel.contacts assert group_chat_new_name not in messages_screen.left_panel.get_chats_list()
main_window.hide() main_window.hide()
with step(f'Restart app for {user_three.name} and verify that user is not the member of chat'): with step(f'Get back to {aut_one} and check members list'):
aut_three.restart() aut_one.attach()
main_window.authorize_user(user_three) main_window.prepare()
assert group_chat_new_name in messages_screen.left_panel.get_chats_list(), \
with step('Check that {user_three.name} is not a member of a group'): f'{group_chat_new_name} is not present in chats list for {aut_one}'
messages_screen.left_panel.open_chat(new_name) messages_screen.left_panel.click_chat_by_name(group_chat_new_name)
gray_message_text = messages_screen.group_chat.gray_text_from_message_area
assert gray_message_text == Messaging.YOU_NEED_TO_BE_A_MEMBER.value
assert not messages_screen.group_chat.is_message_area_enabled
with step(f'Restart app for {user_one.name} and open group chat'):
aut_one.restart()
main_window.authorize_user(user_one)
messages_screen.left_panel.open_chat(new_name)
with step('Verify there is one member in group members list'):
assert user_one.name in messages_screen.right_panel.members assert user_one.name in messages_screen.right_panel.members
assert len(messages_screen.right_panel.members) == 1 assert len(messages_screen.right_panel.members) == 1
with step('Leave group'): with step('Leave group'):
messages_screen.group_chat.leave_group().confirm_leaving() messages_screen.group_chat.leave_group().confirm_leaving()
with step('Check that group name is not displayed on left panel'): with step('Check that group name is not displayed on left panel'):
assert new_name not in messages_screen.left_panel.contacts assert group_chat_new_name in messages_screen.left_panel.get_chats_list() is False