Merge lp:~nskaggs/sudoku-app/add-emulator-autopilot into lp:sudoku-app

Proposed by Nicholas Skaggs
Status: Merged
Approved by: Dinko Osmankovic
Approved revision: 75
Merged at revision: 74
Proposed branch: lp:~nskaggs/sudoku-app/add-emulator-autopilot
Merge into: lp:sudoku-app
Diff against target: 247 lines (+120/-30)
5 files modified
components/SudokuBlocksGrid.qml (+1/-0)
sudoku-app.qml (+4/-0)
tests/autopilot/sudoku_app/emulators/main_window.py (+17/-0)
tests/autopilot/sudoku_app/emulators/ubuntusdk.py (+35/-29)
tests/autopilot/sudoku_app/tests/test_sudoku.py (+63/-1)
To merge this branch: bzr merge lp:~nskaggs/sudoku-app/add-emulator-autopilot
Reviewer Review Type Date Requested Status
Dinko Osmankovic Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+174282@code.launchpad.net

Commit message

This change adds tests for number inputs and the high score tab

Description of the change

This change adds tests for number inputs and the high score tab

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
75. By Nicholas Skaggs

fix testcase for input numbers

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Dinko Osmankovic (dinko-metalac) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'components/SudokuBlocksGrid.qml'
2--- components/SudokuBlocksGrid.qml 2013-07-10 09:02:21 +0000
3+++ components/SudokuBlocksGrid.qml 2013-07-11 22:05:30 +0000
4@@ -292,6 +292,7 @@
5
6 Dialog {
7 id: dialogue
8+ objectName: "picknumberscreen"
9 //title: "Number Picker"
10 text: i18n.tr("Please pick a number")
11
12
13=== modified file 'sudoku-app.qml'
14--- sudoku-app.qml 2013-07-10 11:38:57 +0000
15+++ sudoku-app.qml 2013-07-11 22:05:30 +0000
16@@ -304,6 +304,7 @@
17
18 SudokuBlocksGrid {
19 id: sudokuBlocksGrid;
20+ objectName: "blockgrid"
21 }
22
23 }
24@@ -320,6 +321,7 @@
25 page: Page {
26 tools: ToolbarItems {
27 ToolbarButton {
28+ objectName: "allusersbutton"
29 action: Action {
30 text: "All\nusers"
31 iconSource: Qt.resolvedUrl("icons/all-users.svg")
32@@ -341,6 +343,7 @@
33 }
34 }
35 ToolbarButton {
36+ objectName: "currentuserbutton"
37 action: Action {
38 text: "Current\nuser"
39 iconSource: Qt.resolvedUrl("icons/single-user.svg")
40@@ -387,6 +390,7 @@
41 anchors.fill: parent
42 header: ListItem.Header {
43 id: highscoresHeader
44+ objectName: "highscoreslabel"
45 text: highscoresHeaderText
46 }
47 delegate: ListItem.SingleValue {
48
49=== modified file 'tests/autopilot/sudoku_app/emulators/main_window.py'
50--- tests/autopilot/sudoku_app/emulators/main_window.py 2013-07-11 16:46:16 +0000
51+++ tests/autopilot/sudoku_app/emulators/main_window.py 2013-07-11 22:05:30 +0000
52@@ -15,3 +15,20 @@
53 """
54 def __init__(self, app):
55 self.app = app
56+
57+ def get_blank_inputs(self):
58+ #generate a list of blank input fields from the game board
59+ #SudokuBlocksGrid->..->SudokuButton->QQuickTest->enabled == true
60+ inputs = self.app.select_single("SudokuBlocksGrid")
61+ blankInputsList = inputs.select_many("QQuickText", enabled=True)
62+ return blankInputsList
63+
64+ def get_dialog_button(self, name):
65+ numberdialog = self.get_number_dialog()
66+
67+ #SudokuDialogButton->QQuickText text =
68+ button = numberdialog.select_single("QQuickText",text=name)
69+ return button
70+
71+ def get_number_dialog(self):
72+ return self.app.select_single("Dialog", objectName="picknumberscreen")
73
74=== modified file 'tests/autopilot/sudoku_app/emulators/ubuntusdk.py'
75--- tests/autopilot/sudoku_app/emulators/ubuntusdk.py 2013-07-11 16:46:16 +0000
76+++ tests/autopilot/sudoku_app/emulators/ubuntusdk.py 2013-07-11 22:05:30 +0000
77@@ -38,6 +38,10 @@
78 """Get more than one object"""
79 return self.app.select_many(typeName, objectName=name)
80
81+ def get_tabs(self):
82+ """Return all tabs"""
83+ return self.app.select_single("Tabs")
84+
85 def switch_to_tab(self, tab):
86 """Switch to the specified tab number"""
87 tabs = self.get_tabs()
88@@ -46,11 +50,37 @@
89 #perform operations until tab == currentTab
90 while tab != currentTab:
91 if tab > currentTab:
92+ self._next_tab()
93+ if tab < currentTab:
94 self._previous_tab()
95- if tab < currentTab:
96- self._next_tab()
97 currentTab = tabs.selectedTabIndex
98
99+ def _previous_tab(self):
100+ """Switch to the previous tab"""
101+ qmlView = self.get_qml_view()
102+
103+ startX = int(qmlView.x + qmlView.width * 0.10)
104+ stopX = int(qmlView.x + qmlView.width * 0.35)
105+ lineY = int(qmlView.y + qmlView.height * 0.05)
106+
107+ self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
108+ self.autopilot.pointing_device.move(startX, lineY)
109+ self.autopilot.pointing_device.click()
110+ self.autopilot.pointing_device.click()
111+
112+ def _next_tab(self):
113+ """Switch to the next tab"""
114+ qmlView = self.get_qml_view()
115+
116+ startX = int(qmlView.x + qmlView.width * 0.35)
117+ stopX = int(qmlView.x + qmlView.width * 0.10)
118+ lineY = int(qmlView.y + qmlView.height * 0.05)
119+
120+ self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
121+ self.autopilot.pointing_device.move(startX, lineY)
122+ self.autopilot.pointing_device.click()
123+ self.autopilot.pointing_device.click()
124+
125 def toggle_toolbar(self):
126 """Toggle the toolbar between revealed and hidden"""
127 #check and see if the toolbar is open or not
128@@ -69,6 +99,9 @@
129 if not toolbar.opened:
130 self.open_toolbar()
131 buttonList = toolbar.select_many("ActionItem")
132+ #old version is ToolbarButton
133+ if not buttonList:
134+ buttonList = toolbar.select_many("ToolbarButton")
135 for button in buttonList:
136 if button.objectName == buttonObject:
137 return button
138@@ -122,30 +155,3 @@
139 if item.text == value:
140 self.autopilot.pointing_device.click_object(item)
141 return item
142-
143- def get_tabs(self):
144- """Return all tabs"""
145- return self.get_object("Tabs", "rootTabs")
146-
147- def _previous_tab(self):
148- """Switch to the previous tab"""
149- qmlView = self.get_qml_view()
150-
151- startX = int(qmlView.x + qmlView.width * 0.35)
152- stopX = int(qmlView.x + qmlView.width * 0.50)
153- lineY = int(qmlView.y + qmlView.height * 0.05)
154-
155- self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
156- self.autopilot.pointing_device.click()
157- self.autopilot.pointing_device.click()
158-
159- def _next_tab(self):
160- """Switch to the next tab"""
161- qmlView = self.get_qml_view()
162-
163- startX = int(qmlView.x + qmlView.width * 0.50)
164- stopX = int(qmlView.x + qmlView.width * 0.35)
165- lineY = int(qmlView.y + qmlView.height * 0.05)
166-
167- self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
168- self.autopilot.pointing_device.click()
169
170=== modified file 'tests/autopilot/sudoku_app/tests/test_sudoku.py'
171--- tests/autopilot/sudoku_app/tests/test_sudoku.py 2013-07-11 16:58:38 +0000
172+++ tests/autopilot/sudoku_app/tests/test_sudoku.py 2013-07-11 22:05:30 +0000
173@@ -10,7 +10,7 @@
174 from __future__ import absolute_import
175
176 from autopilot.matchers import Eventually
177-from testtools.matchers import Equals
178+from testtools.matchers import Equals, Contains, NotEquals
179
180 from sudoku_app.tests import SudokuTestCase
181
182@@ -24,3 +24,65 @@
183
184 def tearDown(self):
185 super(TestMainWindow, self).tearDown()
186+
187+ def test_enter_and_clear_number(self):
188+ #find the first button that has a blank value
189+ gridButtons = self.main_window.get_blank_inputs()
190+ gridButton = gridButtons[0]
191+
192+ #create a value function to check later using id
193+ buttonValue = lambda: self.app.select_single("QQuickText",id=gridButton.id).text
194+
195+ #double check that it's blank
196+ self.assertThat(buttonValue, Eventually(Equals("")))
197+
198+ #click the button
199+ self.pointing_device.click_object(gridButton)
200+
201+ #assert that we can see the input screen
202+ inputScreen = lambda: self.main_window.get_number_dialog()
203+ self.assertThat(inputScreen, Eventually(NotEquals(None)))
204+
205+ #set a value, choose 4
206+ dialogButton = self.main_window.get_dialog_button("4")
207+ self.assertThat(dialogButton, NotEquals(None))
208+ self.pointing_device.click_object(dialogButton)
209+
210+ #check the value to ensure it worked
211+ self.assertThat(buttonValue, Eventually(Equals("4")))
212+
213+ #click the button
214+ self.pointing_device.click_object(gridButton)
215+
216+ #assert that we can see the input screen
217+ inputScreen = lambda: self.main_window.get_number_dialog()
218+ self.assertThat(inputScreen, Eventually(NotEquals(None)))
219+
220+ #set a value, choose clear
221+ dialogButton = self.main_window.get_dialog_button("Clear")
222+ self.assertThat(dialogButton, NotEquals(None))
223+ self.pointing_device.click_object(dialogButton)
224+
225+ #check the value to ensure it worked
226+ self.assertThat(buttonValue, Eventually(Equals("")))
227+
228+ def test_best_scores_tab(self):
229+ #switch to best scores tab
230+ self.ubuntusdk.switch_to_tab(1)
231+
232+ #make sure we are in the right place
233+ tabName = lambda: self.ubuntusdk.get_object("Tab","highscoresTab")
234+ self.assertThat(tabName, Eventually(NotEquals(None)))
235+
236+ #click current user button
237+ self.ubuntusdk.click_toolbar_button("currentuserbutton")
238+
239+ #check label
240+ label = lambda: self.ubuntusdk.get_object("Header","highscoreslabel").text
241+ self.assertThat(label, Eventually(NotEquals("<b>Best scores for all players</b>")))
242+
243+ #click all users button
244+ self.ubuntusdk.click_toolbar_button("allusersbutton")
245+
246+ #check label again
247+ self.assertThat(label, Eventually(Equals("<b>Best scores for all players</b>")))

Subscribers

People subscribed via source and target branches