From 60812ce892b447b7a9212b6a3ccf552dac72f8f8 Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Mon, 3 Oct 2022 13:32:25 +0530 Subject: [PATCH] Add inbox screen and fix test_create_address xpaths --- src/bitmessagekivy/baseclass/inbox.py | 58 ++++++++++++++++ src/bitmessagekivy/baseclass/maildetail.py | 2 +- src/bitmessagekivy/main.kv | 7 +- src/bitmessagekivy/screens_data.json | 5 ++ .../tests/test_create_random_address.py | 69 ++++++++++++++----- 5 files changed, 120 insertions(+), 21 deletions(-) create mode 100644 src/bitmessagekivy/baseclass/inbox.py diff --git a/src/bitmessagekivy/baseclass/inbox.py b/src/bitmessagekivy/baseclass/inbox.py new file mode 100644 index 00000000..b2bd022c --- /dev/null +++ b/src/bitmessagekivy/baseclass/inbox.py @@ -0,0 +1,58 @@ +# pylint: disable=unused-import, too-many-public-methods, unused-variable, too-many-ancestors +# pylint: disable=no-name-in-module, too-few-public-methods, import-error, unused-argument, too-many-arguments +# pylint: disable=attribute-defined-outside-init, global-variable-not-assigned, too-many-instance-attributes + +""" +Kivy UI for inbox screen +""" +from kivy.clock import Clock +from kivy.properties import ( + ListProperty, + StringProperty +) +from kivy.app import App +from kivy.uix.screenmanager import Screen + +from pybitmessage.bitmessagekivy.baseclass.common import kivy_state_variables, load_image_path + + +class Inbox(Screen): + """Inbox Screen class for kivy Ui""" + + queryreturn = ListProperty() + has_refreshed = True + account = StringProperty() + no_search_res_found = "No search result found" + label_str = "Yet no message for this account!" + + def __init__(self, *args, **kwargs): + """Initialize kivy variables""" + super(Inbox, self).__init__(*args, **kwargs) + self.kivy_running_app = App.get_running_app() + self.kivy_state = kivy_state_variables() + self.image_dir = load_image_path() + Clock.schedule_once(self.init_ui, 0) + + def set_defaultAddress(self): + """Set default address""" + if self.kivy_state.selected_address == "": + if self.kivy_running_app.identity_list: + self.kivy_state.selected_address = self.kivy_running_app.identity_list[0] + + def init_ui(self, dt=0): + """loadMessagelist() call at specific interval""" + + def refresh_callback(self, *args): + """Load inbox messages while wating-loader spins & called in inbox.kv""" + + def refresh_on_scroll_down(interval): + """Reset fields and load data on scrolling upside down""" + self.kivy_state.searching_text = "" + self.children[2].children[1].ids.search_field.text = "" + self.ids.ml.clear_widgets() + self.loadMessagelist(self.kivy_state.selected_address) + self.has_refreshed = True + self.ids.refresh_layout.refresh_done() + self.tick = 0 + + Clock.schedule_once(refresh_on_scroll_down, 1) diff --git a/src/bitmessagekivy/baseclass/maildetail.py b/src/bitmessagekivy/baseclass/maildetail.py index e2a886c8..633ed844 100644 --- a/src/bitmessagekivy/baseclass/maildetail.py +++ b/src/bitmessagekivy/baseclass/maildetail.py @@ -154,7 +154,7 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes self.parent.screens[2].ids.ml.clear_widgets() self.parent.screens[2].loadSent(self.kivy_state.selected_address) elif self.kivy_state.detail_page_type == 'inbox': - App.get_running_app().root.ids.sc1.ids.inbox_search.ids.search_field.text = '' + App.get_running_app().root.ids.id_inbox.ids.inbox_search.ids.search_field.text = '' trash(self.kivy_state.mail_id) msg_count_objs.inbox_cnt.ids.badge_txt.text = str( int(self.kivy_state.inbox_count) - 1) diff --git a/src/bitmessagekivy/main.kv b/src/bitmessagekivy/main.kv index 45b367f0..d2d3d10d 100644 --- a/src/bitmessagekivy/main.kv +++ b/src/bitmessagekivy/main.kv @@ -104,10 +104,13 @@ text: app.tr._('Accounts') height:"35dp" NavigationItem: + text: 'dropdown_nav_item' height: dp(48) IdentitySpinner: id: identity_dropdown pos_hint:{"x":0,"y":0} + name: "identity_dropdown" + text: 'Select Address' option_cls: Factory.get("MySpinnerOption") font_size: '12.5sp' color: color_font @@ -119,7 +122,7 @@ text: app.tr._('Inbox') icon: 'email-open' divider: None - on_release: app.root.ids.scr_mngr.current = 'inbox' + on_release: app.set_screen('inbox') on_release: root.parent.set_state() on_press: app.load_screen(self) NavigationItem: @@ -224,6 +227,8 @@ MDNavigationLayout: id:id_networkstat Setting: id:id_settings + Inbox: + id:id_inbox MDNavigationDrawer: id: nav_drawer diff --git a/src/bitmessagekivy/screens_data.json b/src/bitmessagekivy/screens_data.json index 8f7d78ec..492907fc 100644 --- a/src/bitmessagekivy/screens_data.json +++ b/src/bitmessagekivy/screens_data.json @@ -1,4 +1,9 @@ { + "Inbox": { + "kv_string": "inbox", + "name_screen": "inbox", + "Import": "from pybitmessage.bitmessagekivy.baseclass.inbox import Inbox" + }, "Login": { "kv_string": "login", "Import": "from pybitmessage.bitmessagekivy.baseclass.login import *" diff --git a/src/bitmessagekivy/tests/test_create_random_address.py b/src/bitmessagekivy/tests/test_create_random_address.py index 8f6155a5..cd062c45 100644 --- a/src/bitmessagekivy/tests/test_create_random_address.py +++ b/src/bitmessagekivy/tests/test_create_random_address.py @@ -2,16 +2,15 @@ Test for creating new identity """ +from time import sleep from random import choice from string import ascii_lowercase from .telenium_process import TeleniumTestProcess -from .common import skip_screen_checks from .common import ordered class CreateRandomAddress(TeleniumTestProcess): """This is for testing randrom address creation""" - @staticmethod def populate_test_data(): pass @@ -23,11 +22,15 @@ class CreateRandomAddress(TeleniumTestProcess): """Click on Proceed Button to Proceed to Next Screen.""" # Checking current Screen(Login screen) self.assert_wait_no_except('//ScreenManager[@current]', timeout=15, value='login') - # Click on "Proceed Next" Button to "generate random label for address" screen - # Some widgets cannot renders suddenly and become not functional so we used loop with a timeout. - self.assertExists("//Screen[0]//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]", timeout=5) + self.assertExists( + '''//Login//Screen[@name=\"check_screen\"]''' + '''//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]''', timeout=5 + ) # Clicking on Proceed Next Button to redirect to "random" screen - self.cli.wait_click('//Screen[0]//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=5) + self.cli.wait_click( + '''//Login//Screen[@name=\"check_screen\"]''' + '''//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]''', timeout=5 + ) self.assertExists("//ScreenManager[@current=\"random\"]", timeout=5) @ordered @@ -35,26 +38,27 @@ class CreateRandomAddress(TeleniumTestProcess): """Creating New Adress For New User.""" # Checking the Button is rendered self.assertExists( - '//RandomBoxlayout/BoxLayout[0]/AnchorLayout[1]/MDTextField[@hint_text=\"Label\"]', timeout=2) + '//Random//RandomBoxlayout//MDTextField[@hint_text=\"Label\"]', timeout=1) # Click on Label Text Field to give address Label self.cli.wait_click( - '//RandomBoxlayout/BoxLayout[0]/AnchorLayout[1]/MDTextField[@hint_text=\"Label\"]', timeout=2) + '//Random//RandomBoxlayout//MDTextField[@hint_text=\"Label\"]', timeout=2) # Enter a Label Randomly random_label = "" for _ in range(10): random_label += choice(ascii_lowercase) - self.cli.setattr('//RandomBoxlayout//AnchorLayout[1]/MDTextField[0]', "text", random_label) + self.cli.setattr('//Random//MDTextField[0]', "text", random_label) self.cli.sleep(0.1) # Checking the Button is rendered - self.assertExists('//RandomBoxlayout//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=3) + self.assertExists( + '//Random//RandomBoxlayout//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=3) # Click on Proceed Next button to generate random Address - self.cli.wait_click('//RandomBoxlayout//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=3) + self.cli.wait_click( + '//Random//RandomBoxlayout//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=3) # Checking "My Address" Screen after creating a address self.assertExists("//ScreenManager[@current=\"myaddress\"]", timeout=5) # Checking the new address is created - self.assertExists('//MDList[0]/CustomTwoLineAvatarIconListItem', timeout=10) + self.assertExists('//MyAddress//MDList[0]/CustomTwoLineAvatarIconListItem', timeout=10) - @skip_screen_checks @ordered def test_set_default_address(self): """Select First Address From Drawer-Box""" @@ -63,13 +67,40 @@ class CreateRandomAddress(TeleniumTestProcess): # This is for opening side navbar self.open_side_navbar() # Click to open Address Dropdown - self.cli.wait_click('//NavigationItem[0]/CustomSpinner[0]', timeout=5) - # Checking the dropdown option is exist - self.assertExists('//MySpinnerOption[0]', timeout=5) - is_open = self.cli.getattr('//NavigationItem[0]/CustomSpinner[@is_open]', 'is_open') + self.assertExists('//NavigationItem[0][@text=\"dropdown_nav_item\"]', timeout=2) + self.assertExists( + '//NavigationItem[0][@text=\"dropdown_nav_item\"]' + '/IdentitySpinner[@name=\"identity_dropdown\"]', timeout=1 + ) + is_open = self.cli.getattr( + '//NavigationItem[0][@text=\"dropdown_nav_item\"]' + '/IdentitySpinner[@name=\"identity_dropdown\"][@is_open]', "is_open") + self.assertEqual(is_open, False) + self.cli.wait( + '//NavigationItem[0][@text=\"dropdown_nav_item\"]' + '/IdentitySpinner[@name=\"identity_dropdown\"][@state=\"normal\"]', timeout=2 + ) + self.cli.wait_click( + '//NavigationItem[0][@text=\"dropdown_nav_item\"]' + '/IdentitySpinner[@name=\"identity_dropdown\"]', timeout=1 + ) + if self.cli.wait( + '//NavigationItem[0][@text=\"dropdown_nav_item\"]' + '/IdentitySpinner[@name=\"identity_dropdown\"][@state=\"normal\"]', timeout=2): + sleep(0.2) # Check the state of dropdown. + is_open = self.cli.getattr( + '//NavigationItem[0][@text=\"dropdown_nav_item\"]' + '/IdentitySpinner[@name=\"identity_dropdown\"][@is_open]', 'is_open' + ) self.assertEqual(is_open, True) + # List of addresses + addresses_in_dropdown = self.cli.getattr( + '//NavigationItem[0][@text=\"dropdown_nav_item\"]/IdentitySpinner[@values]', 'values' + ) + # Checking the dropdown options are exists + self.assertGreaterEqual(len(self.cli.getattr( + '//MySpinnerOption[@text]', 'text')), len(addresses_in_dropdown) + ) # Selection of an address to set as a default address. self.cli.wait_click('//MySpinnerOption[0]', timeout=5) - # Checking current screen - self.assertExists("//ScreenManager[@current=\"inbox\"]", timeout=5)