2023-10-13 15:55:44 +00:00
|
|
|
import time
|
|
|
|
import typing
|
|
|
|
|
|
|
|
import allure
|
|
|
|
|
|
|
|
import configs.timeouts
|
|
|
|
import driver
|
|
|
|
from driver.objects_access import walk_children
|
2023-11-28 12:26:05 +00:00
|
|
|
from gui.components.settings.respond_to_id_request_popup import RespondToIDRequestPopup
|
2023-10-13 15:55:44 +00:00
|
|
|
from gui.components.settings.send_contact_request_popup import SendContactRequest
|
2023-11-28 12:26:05 +00:00
|
|
|
from gui.components.settings.verify_identity_popup import VerifyIdentityPopup
|
2023-10-13 15:55:44 +00:00
|
|
|
|
|
|
|
from gui.elements.button import Button
|
|
|
|
from gui.elements.list import List
|
|
|
|
from gui.screens.messages import MessagesScreen
|
|
|
|
from scripts.tools.image import Image
|
2023-10-16 07:27:46 +00:00
|
|
|
from gui.screens.settings import *
|
2023-10-13 15:55:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MessagingSettingsView(QObject):
|
|
|
|
|
|
|
|
def __init__(self):
|
2024-02-13 09:04:24 +00:00
|
|
|
super().__init__(names.mainWindow_MessagingView)
|
|
|
|
self._contacts_button = Button(names.contactsListItem_btn_StatusContactRequestsIndicatorListItem)
|
2023-10-13 15:55:44 +00:00
|
|
|
|
|
|
|
@allure.step('Open contacts settings')
|
|
|
|
def open_contacts_settings(self) -> 'ContactsSettingsView':
|
|
|
|
self._contacts_button.click()
|
|
|
|
return ContactsSettingsView().wait_until_appears()
|
|
|
|
|
|
|
|
|
2023-11-27 10:44:42 +00:00
|
|
|
class ContactItem:
|
2023-10-13 15:55:44 +00:00
|
|
|
|
|
|
|
def __init__(self, obj):
|
|
|
|
self.object = obj
|
|
|
|
self.icon: typing.Optional[Image] = None
|
|
|
|
self.contact: typing.Optional[Image] = None
|
|
|
|
self._accept_button: typing.Optional[Button] = None
|
|
|
|
self._reject_button: typing.Optional[Button] = None
|
|
|
|
self._open_canvas_button: typing.Optional[Button] = None
|
|
|
|
self.init_ui()
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return self.contact
|
|
|
|
|
|
|
|
def init_ui(self):
|
|
|
|
for child in walk_children(self.object):
|
|
|
|
if str(getattr(child, 'id', '')) == 'iconOrImage':
|
|
|
|
self.icon = Image(driver.objectMap.realName(child))
|
|
|
|
elif str(getattr(child, 'id', '')) == 'menuButton':
|
2024-02-13 09:04:24 +00:00
|
|
|
self._open_canvas_button = Button(real_name=driver.objectMap.realName(child))
|
2023-10-13 15:55:44 +00:00
|
|
|
elif str(getattr(child, 'objectName', '')) == 'checkmark-circle-icon':
|
2024-02-13 09:04:24 +00:00
|
|
|
self._accept_button = Button(real_name=driver.objectMap.realName(child))
|
2023-10-13 15:55:44 +00:00
|
|
|
elif str(getattr(child, 'objectName', '')) == 'close-circle-icon':
|
2024-02-13 09:04:24 +00:00
|
|
|
self._reject_button = Button(real_name=driver.objectMap.realName(child))
|
2023-10-13 15:55:44 +00:00
|
|
|
elif str(getattr(child, 'id', '')) == 'statusListItemTitle':
|
|
|
|
self.contact = str(child.text)
|
2023-11-27 10:44:42 +00:00
|
|
|
elif str(getattr(child, 'objectName', '')) == 'chat-icon':
|
2024-02-13 09:04:24 +00:00
|
|
|
self._chat_button = Button(real_name=driver.objectMap.realName(child))
|
2023-10-13 15:55:44 +00:00
|
|
|
|
2023-11-28 12:26:05 +00:00
|
|
|
@allure.step('Accept request')
|
2023-10-13 15:55:44 +00:00
|
|
|
def accept(self) -> MessagesScreen:
|
|
|
|
assert self._accept_button is not None, 'Button not found'
|
|
|
|
self._accept_button.click()
|
|
|
|
return MessagesScreen().wait_until_appears()
|
|
|
|
|
2023-11-28 12:26:05 +00:00
|
|
|
@allure.step('Reject request')
|
2023-11-27 10:44:42 +00:00
|
|
|
def reject(self):
|
|
|
|
assert self._reject_button is not None, 'Button not found'
|
|
|
|
self._reject_button.click()
|
|
|
|
|
2023-11-28 12:26:05 +00:00
|
|
|
@allure.step('Open more options popup')
|
|
|
|
def open_more_options_popup(self, timeout_msec: int = configs.timeouts.UI_LOAD_TIMEOUT_MSEC, attempt: int = 2):
|
|
|
|
try:
|
|
|
|
self._open_canvas_button.click()
|
|
|
|
driver.waitFor(lambda: ContactsSettingsView()._view_profile_item.is_visible, timeout_msec)
|
|
|
|
return self
|
|
|
|
except:
|
|
|
|
if attempt:
|
|
|
|
self._open_canvas_button.click(attempt - 1)
|
|
|
|
return self
|
|
|
|
else:
|
2023-12-19 13:12:24 +00:00
|
|
|
raise LookupError(f"Popup didn't appear")
|
2023-11-28 12:26:05 +00:00
|
|
|
|
2023-10-13 15:55:44 +00:00
|
|
|
|
|
|
|
class ContactsSettingsView(QObject):
|
|
|
|
|
|
|
|
def __init__(self):
|
2024-02-13 09:04:24 +00:00
|
|
|
super().__init__(names.mainWindow_ContactsView)
|
|
|
|
self._contact_request_button = Button(names.mainWindow_Send_contact_request_to_chat_key_StatusButton)
|
|
|
|
self._pending_request_tab = Button(names.contactsTabBar_Pending_Requests_StatusTabButton)
|
|
|
|
self._contacts_tab = Button(names.contactsTabBar_Contacts_StatusTabButton)
|
|
|
|
self._contacts_items_list = List(names.settingsContentBaseScrollView_ContactListPanel)
|
|
|
|
self._pending_request_sent_panel = QObject(names.settingsContentBaseScrollView_sentRequests_ContactsListPanel)
|
2023-11-27 10:44:42 +00:00
|
|
|
self._pending_request_received_panel = QObject(
|
2024-02-13 09:04:24 +00:00
|
|
|
names.settingsContentBaseScrollView_receivedRequests_ContactsListPanel)
|
|
|
|
self._contacts_panel = QObject(names.settingsContentBaseScrollView_mutualContacts_ContactsListPanel)
|
|
|
|
self._invite_friends_button = QObject(names.settingsContentBaseScrollView_Invite_friends_StatusButton)
|
|
|
|
self._no_friends_item = QObject(names.settingsContentBaseScrollView_NoFriendsRectangle)
|
2023-11-28 12:26:05 +00:00
|
|
|
# more options on contact
|
2024-02-13 09:04:24 +00:00
|
|
|
self._verify_identity_item = QObject(names.verify_Identity_StatusMenuItem)
|
|
|
|
self._respond_to_id_request_item = QObject(names.respond_to_ID_Request_StatusMenuItem)
|
|
|
|
self._view_profile_item = QObject(names.view_Profile_StatusMenuItem)
|
|
|
|
self._respond_to_id_request_button = Button(names.settingsContentBaseScrollView_Respond_to_ID_Request_StatusFlatButton)
|
2023-11-27 10:44:42 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@allure.step('Get contact items')
|
|
|
|
def contact_items(self) -> typing.List[ContactItem]:
|
|
|
|
return [ContactItem(item) for item in self._contacts_items_list.items]
|
|
|
|
|
|
|
|
@property
|
|
|
|
@allure.step('Get title of list with sent pending requests')
|
|
|
|
def pending_request_sent_list_title(self) -> str:
|
|
|
|
return self._pending_request_sent_panel.object.title
|
|
|
|
|
|
|
|
@property
|
|
|
|
@allure.step('Get title of list with received pending requests')
|
|
|
|
def pending_request_received_list_title(self) -> str:
|
|
|
|
return self._pending_request_received_panel.object.title
|
|
|
|
|
|
|
|
@property
|
|
|
|
@allure.step('Get title of list with contacts')
|
|
|
|
def contacts_list_title(self) -> str:
|
|
|
|
return self._contacts_panel.object.title
|
|
|
|
|
|
|
|
@property
|
|
|
|
@allure.step('Get title of no friends item')
|
|
|
|
def no_friends_item_text(self) -> str:
|
|
|
|
return self._no_friends_item.object.text
|
2023-10-13 15:55:44 +00:00
|
|
|
|
|
|
|
@property
|
2023-11-27 10:44:42 +00:00
|
|
|
@allure.step('Get state of invite friends button')
|
|
|
|
def is_invite_friends_button_visible(self) -> bool:
|
|
|
|
return self._invite_friends_button.is_visible
|
|
|
|
|
|
|
|
@allure.step('Open pending requests tab')
|
|
|
|
def open_pending_requests(self):
|
2023-10-13 15:55:44 +00:00
|
|
|
self._pending_request_tab.click()
|
2023-11-28 12:26:05 +00:00
|
|
|
return self
|
2023-11-27 10:44:42 +00:00
|
|
|
|
|
|
|
@allure.step('Open contacts tab')
|
|
|
|
def open_contacts(self):
|
|
|
|
self._contacts_tab.click()
|
2023-11-28 12:26:05 +00:00
|
|
|
return self
|
2023-10-13 15:55:44 +00:00
|
|
|
|
|
|
|
@allure.step('Open contacts request form')
|
|
|
|
def open_contact_request_form(self) -> SendContactRequest:
|
|
|
|
self._contact_request_button.click()
|
|
|
|
return SendContactRequest().wait_until_appears()
|
|
|
|
|
|
|
|
@allure.step('Open contacts request form')
|
|
|
|
def send_contacts_request(self):
|
|
|
|
LeftPanel().open_messaging_settings().open_contacts_settings().open_contact_request_form()
|
|
|
|
|
|
|
|
@allure.step('Accept contact request')
|
2023-11-27 10:44:42 +00:00
|
|
|
def find_contact_in_list(
|
|
|
|
self, contact: str, timeout_sec: int = configs.timeouts.MESSAGING_TIMEOUT_SEC):
|
2023-10-13 15:55:44 +00:00
|
|
|
started_at = time.monotonic()
|
|
|
|
request = None
|
|
|
|
while request is None:
|
2023-11-27 10:44:42 +00:00
|
|
|
requests = self.contact_items
|
2023-10-13 15:55:44 +00:00
|
|
|
for _request in requests:
|
|
|
|
if _request.contact == contact:
|
|
|
|
request = _request
|
|
|
|
assert time.monotonic() - started_at < timeout_sec, f'Contact: {contact} not found in {requests}'
|
2023-11-27 10:44:42 +00:00
|
|
|
return request
|
|
|
|
|
|
|
|
@allure.step('Accept contact request')
|
|
|
|
def accept_contact_request(self, contact: str,
|
|
|
|
timeout_sec: int = configs.timeouts.MESSAGING_TIMEOUT_SEC) -> MessagesScreen:
|
2023-11-28 12:26:05 +00:00
|
|
|
self.open_pending_requests()
|
2023-11-27 10:44:42 +00:00
|
|
|
request = self.find_contact_in_list(contact, timeout_sec)
|
2023-10-13 15:55:44 +00:00
|
|
|
return request.accept()
|
2023-11-27 10:44:42 +00:00
|
|
|
|
|
|
|
@allure.step('Reject contact request')
|
|
|
|
def reject_contact_request(
|
|
|
|
self, contact: str, timeout_sec: int = configs.timeouts.MESSAGING_TIMEOUT_SEC):
|
2023-11-28 12:26:05 +00:00
|
|
|
self.open_pending_requests()
|
2023-11-27 10:44:42 +00:00
|
|
|
request = self.find_contact_in_list(contact, timeout_sec)
|
|
|
|
request.reject()
|
2023-11-28 12:26:05 +00:00
|
|
|
|
|
|
|
@allure.step('Open verify identity popup')
|
|
|
|
def open_more_options_popup(
|
|
|
|
self, contact: str, timeout_sec: int = configs.timeouts.MESSAGING_TIMEOUT_SEC, attempts: int = 2):
|
|
|
|
request = self.find_contact_in_list(contact, timeout_sec)
|
|
|
|
request.open_more_options_popup()
|
|
|
|
return self
|
|
|
|
|
|
|
|
def verify_identity(self):
|
|
|
|
self._verify_identity_item.click()
|
|
|
|
return VerifyIdentityPopup().wait_until_appears()
|
|
|
|
|
|
|
|
def is_respond_to_id_request_visible(self) -> bool:
|
|
|
|
return self._respond_to_id_request_item.is_visible
|
|
|
|
|
|
|
|
def respond_to_id_request(self):
|
|
|
|
self._respond_to_id_request_item.click()
|
|
|
|
return RespondToIDRequestPopup().wait_until_appears()
|