Skip to content

Commit 60812ce

Browse files
committed
Add inbox screen and fix test_create_address xpaths
1 parent 22aec01 commit 60812ce

5 files changed

Lines changed: 120 additions & 21 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# pylint: disable=unused-import, too-many-public-methods, unused-variable, too-many-ancestors
2+
# pylint: disable=no-name-in-module, too-few-public-methods, import-error, unused-argument, too-many-arguments
3+
# pylint: disable=attribute-defined-outside-init, global-variable-not-assigned, too-many-instance-attributes
4+
5+
"""
6+
Kivy UI for inbox screen
7+
"""
8+
from kivy.clock import Clock
9+
from kivy.properties import (
10+
ListProperty,
11+
StringProperty
12+
)
13+
from kivy.app import App
14+
from kivy.uix.screenmanager import Screen
15+
16+
from pybitmessage.bitmessagekivy.baseclass.common import kivy_state_variables, load_image_path
17+
18+
19+
class Inbox(Screen):
20+
"""Inbox Screen class for kivy Ui"""
21+
22+
queryreturn = ListProperty()
23+
has_refreshed = True
24+
account = StringProperty()
25+
no_search_res_found = "No search result found"
26+
label_str = "Yet no message for this account!"
27+
28+
def __init__(self, *args, **kwargs):
29+
"""Initialize kivy variables"""
30+
super(Inbox, self).__init__(*args, **kwargs)
31+
self.kivy_running_app = App.get_running_app()
32+
self.kivy_state = kivy_state_variables()
33+
self.image_dir = load_image_path()
34+
Clock.schedule_once(self.init_ui, 0)
35+
36+
def set_defaultAddress(self):
37+
"""Set default address"""
38+
if self.kivy_state.selected_address == "":
39+
if self.kivy_running_app.identity_list:
40+
self.kivy_state.selected_address = self.kivy_running_app.identity_list[0]
41+
42+
def init_ui(self, dt=0):
43+
"""loadMessagelist() call at specific interval"""
44+
45+
def refresh_callback(self, *args):
46+
"""Load inbox messages while wating-loader spins & called in inbox.kv"""
47+
48+
def refresh_on_scroll_down(interval):
49+
"""Reset fields and load data on scrolling upside down"""
50+
self.kivy_state.searching_text = ""
51+
self.children[2].children[1].ids.search_field.text = ""
52+
self.ids.ml.clear_widgets()
53+
self.loadMessagelist(self.kivy_state.selected_address)
54+
self.has_refreshed = True
55+
self.ids.refresh_layout.refresh_done()
56+
self.tick = 0
57+
58+
Clock.schedule_once(refresh_on_scroll_down, 1)

src/bitmessagekivy/baseclass/maildetail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def delete_mail(self):
154154
self.parent.screens[2].ids.ml.clear_widgets()
155155
self.parent.screens[2].loadSent(self.kivy_state.selected_address)
156156
elif self.kivy_state.detail_page_type == 'inbox':
157-
App.get_running_app().root.ids.sc1.ids.inbox_search.ids.search_field.text = ''
157+
App.get_running_app().root.ids.id_inbox.ids.inbox_search.ids.search_field.text = ''
158158
trash(self.kivy_state.mail_id)
159159
msg_count_objs.inbox_cnt.ids.badge_txt.text = str(
160160
int(self.kivy_state.inbox_count) - 1)

src/bitmessagekivy/main.kv

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,13 @@
104104
text: app.tr._('Accounts')
105105
height:"35dp"
106106
NavigationItem:
107+
text: 'dropdown_nav_item'
107108
height: dp(48)
108109
IdentitySpinner:
109110
id: identity_dropdown
110111
pos_hint:{"x":0,"y":0}
112+
name: "identity_dropdown"
113+
text: 'Select Address'
111114
option_cls: Factory.get("MySpinnerOption")
112115
font_size: '12.5sp'
113116
color: color_font
@@ -119,7 +122,7 @@
119122
text: app.tr._('Inbox')
120123
icon: 'email-open'
121124
divider: None
122-
on_release: app.root.ids.scr_mngr.current = 'inbox'
125+
on_release: app.set_screen('inbox')
123126
on_release: root.parent.set_state()
124127
on_press: app.load_screen(self)
125128
NavigationItem:
@@ -224,6 +227,8 @@ MDNavigationLayout:
224227
id:id_networkstat
225228
Setting:
226229
id:id_settings
230+
Inbox:
231+
id:id_inbox
227232

228233
MDNavigationDrawer:
229234
id: nav_drawer

src/bitmessagekivy/screens_data.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2+
"Inbox": {
3+
"kv_string": "inbox",
4+
"name_screen": "inbox",
5+
"Import": "from pybitmessage.bitmessagekivy.baseclass.inbox import Inbox"
6+
},
27
"Login": {
38
"kv_string": "login",
49
"Import": "from pybitmessage.bitmessagekivy.baseclass.login import *"

src/bitmessagekivy/tests/test_create_random_address.py

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
Test for creating new identity
33
"""
44

5+
from time import sleep
56
from random import choice
67
from string import ascii_lowercase
78
from .telenium_process import TeleniumTestProcess
8-
from .common import skip_screen_checks
99
from .common import ordered
1010

1111

1212
class CreateRandomAddress(TeleniumTestProcess):
1313
"""This is for testing randrom address creation"""
14-
1514
@staticmethod
1615
def populate_test_data():
1716
pass
@@ -23,38 +22,43 @@ def test_landing_screen(self):
2322
"""Click on Proceed Button to Proceed to Next Screen."""
2423
# Checking current Screen(Login screen)
2524
self.assert_wait_no_except('//ScreenManager[@current]', timeout=15, value='login')
26-
# Click on "Proceed Next" Button to "generate random label for address" screen
27-
# Some widgets cannot renders suddenly and become not functional so we used loop with a timeout.
28-
self.assertExists("//Screen[0]//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]", timeout=5)
25+
self.assertExists(
26+
'''//Login//Screen[@name=\"check_screen\"]'''
27+
'''//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]''', timeout=5
28+
)
2929
# Clicking on Proceed Next Button to redirect to "random" screen
30-
self.cli.wait_click('//Screen[0]//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=5)
30+
self.cli.wait_click(
31+
'''//Login//Screen[@name=\"check_screen\"]'''
32+
'''//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]''', timeout=5
33+
)
3134
self.assertExists("//ScreenManager[@current=\"random\"]", timeout=5)
3235

3336
@ordered
3437
def test_generate_random_address_label(self):
3538
"""Creating New Adress For New User."""
3639
# Checking the Button is rendered
3740
self.assertExists(
38-
'//RandomBoxlayout/BoxLayout[0]/AnchorLayout[1]/MDTextField[@hint_text=\"Label\"]', timeout=2)
41+
'//Random//RandomBoxlayout//MDTextField[@hint_text=\"Label\"]', timeout=1)
3942
# Click on Label Text Field to give address Label
4043
self.cli.wait_click(
41-
'//RandomBoxlayout/BoxLayout[0]/AnchorLayout[1]/MDTextField[@hint_text=\"Label\"]', timeout=2)
44+
'//Random//RandomBoxlayout//MDTextField[@hint_text=\"Label\"]', timeout=2)
4245
# Enter a Label Randomly
4346
random_label = ""
4447
for _ in range(10):
4548
random_label += choice(ascii_lowercase)
46-
self.cli.setattr('//RandomBoxlayout//AnchorLayout[1]/MDTextField[0]', "text", random_label)
49+
self.cli.setattr('//Random//MDTextField[0]', "text", random_label)
4750
self.cli.sleep(0.1)
4851
# Checking the Button is rendered
49-
self.assertExists('//RandomBoxlayout//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=3)
52+
self.assertExists(
53+
'//Random//RandomBoxlayout//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=3)
5054
# Click on Proceed Next button to generate random Address
51-
self.cli.wait_click('//RandomBoxlayout//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=3)
55+
self.cli.wait_click(
56+
'//Random//RandomBoxlayout//MDFillRoundFlatIconButton[@text=\"Proceed Next\"]', timeout=3)
5257
# Checking "My Address" Screen after creating a address
5358
self.assertExists("//ScreenManager[@current=\"myaddress\"]", timeout=5)
5459
# Checking the new address is created
55-
self.assertExists('//MDList[0]/CustomTwoLineAvatarIconListItem', timeout=10)
60+
self.assertExists('//MyAddress//MDList[0]/CustomTwoLineAvatarIconListItem', timeout=10)
5661

57-
@skip_screen_checks
5862
@ordered
5963
def test_set_default_address(self):
6064
"""Select First Address From Drawer-Box"""
@@ -63,13 +67,40 @@ def test_set_default_address(self):
6367
# This is for opening side navbar
6468
self.open_side_navbar()
6569
# Click to open Address Dropdown
66-
self.cli.wait_click('//NavigationItem[0]/CustomSpinner[0]', timeout=5)
67-
# Checking the dropdown option is exist
68-
self.assertExists('//MySpinnerOption[0]', timeout=5)
69-
is_open = self.cli.getattr('//NavigationItem[0]/CustomSpinner[@is_open]', 'is_open')
70+
self.assertExists('//NavigationItem[0][@text=\"dropdown_nav_item\"]', timeout=2)
71+
self.assertExists(
72+
'//NavigationItem[0][@text=\"dropdown_nav_item\"]'
73+
'/IdentitySpinner[@name=\"identity_dropdown\"]', timeout=1
74+
)
75+
is_open = self.cli.getattr(
76+
'//NavigationItem[0][@text=\"dropdown_nav_item\"]'
77+
'/IdentitySpinner[@name=\"identity_dropdown\"][@is_open]', "is_open")
78+
self.assertEqual(is_open, False)
79+
self.cli.wait(
80+
'//NavigationItem[0][@text=\"dropdown_nav_item\"]'
81+
'/IdentitySpinner[@name=\"identity_dropdown\"][@state=\"normal\"]', timeout=2
82+
)
83+
self.cli.wait_click(
84+
'//NavigationItem[0][@text=\"dropdown_nav_item\"]'
85+
'/IdentitySpinner[@name=\"identity_dropdown\"]', timeout=1
86+
)
87+
if self.cli.wait(
88+
'//NavigationItem[0][@text=\"dropdown_nav_item\"]'
89+
'/IdentitySpinner[@name=\"identity_dropdown\"][@state=\"normal\"]', timeout=2):
90+
sleep(0.2)
7091
# Check the state of dropdown.
92+
is_open = self.cli.getattr(
93+
'//NavigationItem[0][@text=\"dropdown_nav_item\"]'
94+
'/IdentitySpinner[@name=\"identity_dropdown\"][@is_open]', 'is_open'
95+
)
7196
self.assertEqual(is_open, True)
97+
# List of addresses
98+
addresses_in_dropdown = self.cli.getattr(
99+
'//NavigationItem[0][@text=\"dropdown_nav_item\"]/IdentitySpinner[@values]', 'values'
100+
)
101+
# Checking the dropdown options are exists
102+
self.assertGreaterEqual(len(self.cli.getattr(
103+
'//MySpinnerOption[@text]', 'text')), len(addresses_in_dropdown)
104+
)
72105
# Selection of an address to set as a default address.
73106
self.cli.wait_click('//MySpinnerOption[0]', timeout=5)
74-
# Checking current screen
75-
self.assertExists("//ScreenManager[@current=\"inbox\"]", timeout=5)

0 commit comments

Comments
 (0)