Add inbox screen and fix test_create_address xpaths

This commit is contained in:
shekhar-cis 2022-10-03 13:32:25 +05:30
parent 22aec0159b
commit 60812ce892
Signed by untrusted user: shekhar-cis
GPG Key ID: F4F00AB04E83F9A7
5 changed files with 120 additions and 21 deletions

View File

@ -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)

View File

@ -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].ids.ml.clear_widgets()
self.parent.screens[2].loadSent(self.kivy_state.selected_address) self.parent.screens[2].loadSent(self.kivy_state.selected_address)
elif self.kivy_state.detail_page_type == 'inbox': 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) trash(self.kivy_state.mail_id)
msg_count_objs.inbox_cnt.ids.badge_txt.text = str( msg_count_objs.inbox_cnt.ids.badge_txt.text = str(
int(self.kivy_state.inbox_count) - 1) int(self.kivy_state.inbox_count) - 1)

View File

@ -104,10 +104,13 @@
text: app.tr._('Accounts') text: app.tr._('Accounts')
height:"35dp" height:"35dp"
NavigationItem: NavigationItem:
text: 'dropdown_nav_item'
height: dp(48) height: dp(48)
IdentitySpinner: IdentitySpinner:
id: identity_dropdown id: identity_dropdown
pos_hint:{"x":0,"y":0} pos_hint:{"x":0,"y":0}
name: "identity_dropdown"
text: 'Select Address'
option_cls: Factory.get("MySpinnerOption") option_cls: Factory.get("MySpinnerOption")
font_size: '12.5sp' font_size: '12.5sp'
color: color_font color: color_font
@ -119,7 +122,7 @@
text: app.tr._('Inbox') text: app.tr._('Inbox')
icon: 'email-open' icon: 'email-open'
divider: None divider: None
on_release: app.root.ids.scr_mngr.current = 'inbox' on_release: app.set_screen('inbox')
on_release: root.parent.set_state() on_release: root.parent.set_state()
on_press: app.load_screen(self) on_press: app.load_screen(self)
NavigationItem: NavigationItem:
@ -224,6 +227,8 @@ MDNavigationLayout:
id:id_networkstat id:id_networkstat
Setting: Setting:
id:id_settings id:id_settings
Inbox:
id:id_inbox
MDNavigationDrawer: MDNavigationDrawer:
id: nav_drawer id: nav_drawer

View File

@ -1,4 +1,9 @@
{ {
"Inbox": {
"kv_string": "inbox",
"name_screen": "inbox",
"Import": "from pybitmessage.bitmessagekivy.baseclass.inbox import Inbox"
},
"Login": { "Login": {
"kv_string": "login", "kv_string": "login",
"Import": "from pybitmessage.bitmessagekivy.baseclass.login import *" "Import": "from pybitmessage.bitmessagekivy.baseclass.login import *"

View File

@ -2,16 +2,15 @@
Test for creating new identity Test for creating new identity
""" """
from time import sleep
from random import choice from random import choice
from string import ascii_lowercase from string import ascii_lowercase
from .telenium_process import TeleniumTestProcess from .telenium_process import TeleniumTestProcess
from .common import skip_screen_checks
from .common import ordered from .common import ordered
class CreateRandomAddress(TeleniumTestProcess): class CreateRandomAddress(TeleniumTestProcess):
"""This is for testing randrom address creation""" """This is for testing randrom address creation"""
@staticmethod @staticmethod
def populate_test_data(): def populate_test_data():
pass pass
@ -23,11 +22,15 @@ class CreateRandomAddress(TeleniumTestProcess):
"""Click on Proceed Button to Proceed to Next Screen.""" """Click on Proceed Button to Proceed to Next Screen."""
# Checking current Screen(Login screen) # Checking current Screen(Login screen)
self.assert_wait_no_except('//ScreenManager[@current]', timeout=15, value='login') self.assert_wait_no_except('//ScreenManager[@current]', timeout=15, value='login')
# Click on "Proceed Next" Button to "generate random label for address" screen self.assertExists(
# Some widgets cannot renders suddenly and become not functional so we used loop with a timeout. '''//Login//Screen[@name=\"check_screen\"]'''
self.assertExists("//Screen[0]//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]", timeout=5) '''//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]''', timeout=5
)
# Clicking on Proceed Next Button to redirect to "random" screen # 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) self.assertExists("//ScreenManager[@current=\"random\"]", timeout=5)
@ordered @ordered
@ -35,26 +38,27 @@ class CreateRandomAddress(TeleniumTestProcess):
"""Creating New Adress For New User.""" """Creating New Adress For New User."""
# Checking the Button is rendered # Checking the Button is rendered
self.assertExists( 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 # Click on Label Text Field to give address Label
self.cli.wait_click( 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 # Enter a Label Randomly
random_label = "" random_label = ""
for _ in range(10): for _ in range(10):
random_label += choice(ascii_lowercase) 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) self.cli.sleep(0.1)
# Checking the Button is rendered # 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 # 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 # Checking "My Address" Screen after creating a address
self.assertExists("//ScreenManager[@current=\"myaddress\"]", timeout=5) self.assertExists("//ScreenManager[@current=\"myaddress\"]", timeout=5)
# Checking the new address is created # 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 @ordered
def test_set_default_address(self): def test_set_default_address(self):
"""Select First Address From Drawer-Box""" """Select First Address From Drawer-Box"""
@ -63,13 +67,40 @@ class CreateRandomAddress(TeleniumTestProcess):
# This is for opening side navbar # This is for opening side navbar
self.open_side_navbar() self.open_side_navbar()
# Click to open Address Dropdown # Click to open Address Dropdown
self.cli.wait_click('//NavigationItem[0]/CustomSpinner[0]', timeout=5) self.assertExists('//NavigationItem[0][@text=\"dropdown_nav_item\"]', timeout=2)
# Checking the dropdown option is exist self.assertExists(
self.assertExists('//MySpinnerOption[0]', timeout=5) '//NavigationItem[0][@text=\"dropdown_nav_item\"]'
is_open = self.cli.getattr('//NavigationItem[0]/CustomSpinner[@is_open]', 'is_open') '/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. # 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) 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. # Selection of an address to set as a default address.
self.cli.wait_click('//MySpinnerOption[0]', timeout=5) self.cli.wait_click('//MySpinnerOption[0]', timeout=5)
# Checking current screen
self.assertExists("//ScreenManager[@current=\"inbox\"]", timeout=5)