Merge lp:~boiko/ubuntu-calculator-app/add_tests_for_new_formula into lp:~f-riccardo87/ubuntu-calculator-app/new-formula-structure

Proposed by Gustavo Pichorim Boiko
Status: Merged
Approved by: Riccardo Ferrazzo
Approved revision: 49
Merged at revision: 48
Proposed branch: lp:~boiko/ubuntu-calculator-app/add_tests_for_new_formula
Merge into: lp:~f-riccardo87/ubuntu-calculator-app/new-formula-structure
Diff against target: 197 lines (+113/-25)
5 files modified
Simple/CalcLabel.qml (+7/-0)
Simple/Screen.qml (+1/-0)
tests/autopilot/ubuntu_calculator_app/emulators/simple_page.py (+12/-0)
tests/autopilot/ubuntu_calculator_app/tests/__init__.py (+12/-12)
tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py (+81/-13)
To merge this branch: bzr merge lp:~boiko/ubuntu-calculator-app/add_tests_for_new_formula
Reviewer Review Type Date Requested Status
Riccardo Ferrazzo Approve
Review via email: mp+158227@code.launchpad.net

Commit message

Add tests for the bugs fixed by the new formula structure.

Description of the change

Add tests for the bugs fixed by the new formula structure.

To post a comment you must log in.
49. By Gustavo Pichorim Boiko

Add the bugnumber reference in the testcase.

Revision history for this message
Riccardo Ferrazzo (f-riccardo87) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Simple/CalcLabel.qml'
2--- Simple/CalcLabel.qml 2013-03-19 17:52:36 +0000
3+++ Simple/CalcLabel.qml 2013-04-10 21:46:22 +0000
4@@ -14,6 +14,7 @@
5 property string labelText: ""
6 property int numbersHeight: units.gu(4)
7 property string numbersColor: '#757373'
8+ property bool isLast: false
9
10 Row{
11 id: row
12@@ -39,6 +40,12 @@
13 }
14 Label {
15 id: formulaLabel
16+
17+ // this property is used by autopilot tests to find the correct item
18+ // FIXME: implement it in a better way
19+ property bool isLast: root.isLast
20+
21+ objectName: "formulaLabel"
22 width: units.gu(25)
23 color: numbersColor
24 anchors.bottom: parent.bottom
25
26=== modified file 'Simple/Screen.qml'
27--- Simple/Screen.qml 2013-03-20 16:28:57 +0000
28+++ Simple/Screen.qml 2013-04-10 21:46:22 +0000
29@@ -77,6 +77,7 @@
30 operation: _operation
31 numbersColor: (isLastItem && index === repeater.model.count-1) ? "#dd4814" : "#757373"
32 numbersHeight: (isLastItem && index === repeater.model.count-1) ? units.gu(7) : units.gu(4)
33+ isLast: (isLastItem && index === repeater.model.count-1)
34
35 onLabelTextChanged: {
36 root.labelTextUpdated(index, labelText)
37
38=== renamed file 'tests/autopilot/ubuntu_calculator_app/emulators/main_buttons.py' => 'tests/autopilot/ubuntu_calculator_app/emulators/simple_page.py'
39--- tests/autopilot/ubuntu_calculator_app/emulators/main_buttons.py 2013-03-22 12:15:46 +0000
40+++ tests/autopilot/ubuntu_calculator_app/emulators/simple_page.py 2013-04-10 21:46:22 +0000
41@@ -4,3 +4,15 @@
42 # This program is free software: you can redistribute it and/or modify it
43 # under the terms of the GNU General Public License version 3, as published
44 # by the Free Software Foundation.
45+
46+class SimplePage(object):
47+ """An emulator class that makes it easy to interact with the call panel."""
48+ def __init__(self, app):
49+ self.app = app
50+
51+ def get_button(self, text):
52+ return self.app.select_single('KeyboardButton', text=text)
53+
54+ def get_formula_label(self):
55+ # FIXME: find a better way to find the latest formula label
56+ return self.app.select_single('Label', objectName='formulaLabel', isLast=True)
57
58=== modified file 'tests/autopilot/ubuntu_calculator_app/tests/__init__.py'
59--- tests/autopilot/ubuntu_calculator_app/tests/__init__.py 2013-03-22 12:15:46 +0000
60+++ tests/autopilot/ubuntu_calculator_app/tests/__init__.py 2013-04-10 21:46:22 +0000
61@@ -17,22 +17,22 @@
62
63 class CalculatorTestCase(AutopilotTestCase, QtIntrospectionTestMixin):
64
65- """A common testcase class that provides useful methods for calculator app."""
66-
67- def setUp(self):
68- super(CalculatorTestCase, self).setUp()
69-
70- if os.path.realpath(__file__).startswith("/usr/"):
71+ """A common testcase class that provides useful methods for calculator app."""
72+
73+ def setUp(self):
74+ super(CalculatorTestCase, self).setUp()
75+
76+ if os.path.realpath(__file__).startswith("/usr/"):
77 self.launch_test_installed()
78 else:
79 self.launch_test_local()
80
81 def launch_test_local(self):
82- self.app = self.launch_test_application(
83- "qmlscene", "../../ubuntu-calculator-app.qml"
84- )
85+ self.app = self.launch_test_application(
86+ "qmlscene", "../../ubuntu-calculator-app.qml"
87+ )
88
89 def launch_test_installed(self):
90- self.app = self.launch_test_application(
91- "ubuntu-calculator-app"
92- )
93+ self.app = self.launch_test_application(
94+ "ubuntu-calculator-app"
95+ )
96
97=== renamed file 'tests/autopilot/ubuntu_calculator_app/tests/test_main_buttons.py' => 'tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py'
98--- tests/autopilot/ubuntu_calculator_app/tests/test_main_buttons.py 2013-03-22 14:17:43 +0000
99+++ tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py 2013-04-10 21:46:22 +0000
100@@ -14,16 +14,84 @@
101 from autopilot.matchers import Eventually
102
103 from ubuntu_calculator_app.tests import CalculatorTestCase
104-
105-
106-class TestMainButtons(CalculatorTestCase):
107-
108- def setUp(self):
109- super(TestMainButtons, self).setUp()
110-
111- def test_this(self):
112- buttons = self.app.select_many("KeyboardButton")
113-
114- for keys in buttons:
115- self.pointing_device.move_to_object(keys)
116- self.pointing_device.click()
117+from ubuntu_calculator_app.emulators.simple_page import SimplePage
118+
119+class TestSimplePage(CalculatorTestCase):
120+
121+ def setUp(self):
122+ super(TestSimplePage, self).setUp()
123+
124+ def test_this(self):
125+ buttons = self.app.select_many("KeyboardButton")
126+
127+ for keys in buttons:
128+ self.pointing_device.move_to_object(keys)
129+ self.pointing_device.click()
130+
131+ def test_operation_after_clear(self):
132+ """ Test that after clearing one calculation, the next is still correct (bug #1164973) """
133+ oneButton = self.simple_page.get_button("1")
134+ plusButton = self.simple_page.get_button("+")
135+ equalsButton = self.simple_page.get_button("=")
136+ clearButton = self.simple_page.get_button("C")
137+
138+ # type 1+1=
139+ self.pointing_device.move_to_object(oneButton)
140+ self.pointing_device.click()
141+ self.pointing_device.move_to_object(plusButton)
142+ self.pointing_device.click()
143+ self.pointing_device.move_to_object(oneButton)
144+ self.pointing_device.click()
145+ self.pointing_device.move_to_object(equalsButton)
146+ self.pointing_device.click()
147+
148+ # make sure the result is already there
149+ self.assertThat(self.simple_page.get_formula_label().text, Eventually(Equals("2")))
150+
151+ # now clear the input by pressing "C" three times
152+ self.pointing_device.move_to_object(clearButton)
153+ self.pointing_device.click()
154+ self.pointing_device.click()
155+ self.pointing_device.click()
156+
157+ # and do the operation again to make sure the result is correct
158+ self.pointing_device.move_to_object(oneButton)
159+ self.pointing_device.click()
160+ self.pointing_device.move_to_object(plusButton)
161+ self.pointing_device.click()
162+ self.pointing_device.move_to_object(oneButton)
163+ self.pointing_device.click()
164+ self.pointing_device.move_to_object(equalsButton)
165+ self.pointing_device.click()
166+
167+ # make sure the result is correct
168+ self.assertThat(self.simple_page.get_formula_label().text, Eventually(Equals("2")))
169+
170+ def test_equals_dont_change_numbers(self):
171+ """ Test that typing a number and pressing "=" won't change the number (bug #1165894) """
172+ oneButton = self.simple_page.get_button("1")
173+ twoButton = self.simple_page.get_button("2")
174+ threeButton = self.simple_page.get_button("3")
175+ equalsButton = self.simple_page.get_button("=")
176+
177+ # type the initial number
178+ self.pointing_device.move_to_object(oneButton)
179+ self.pointing_device.click()
180+ self.pointing_device.move_to_object(twoButton)
181+ self.pointing_device.click()
182+ self.pointing_device.move_to_object(threeButton)
183+ self.pointing_device.click()
184+
185+ # check that the label is displaying correctly
186+ self.assertThat(self.simple_page.get_formula_label().text, Eventually(Equals("123")))
187+
188+ # click the "=" button
189+ self.pointing_device.move_to_object(equalsButton)
190+ self.pointing_device.click()
191+
192+ # check that the label is still displaying correctly
193+ self.assertThat(self.simple_page.get_formula_label().text, Eventually(Equals("123")))
194+
195+ @property
196+ def simple_page(self):
197+ return SimplePage(self.app)

Subscribers

People subscribed via source and target branches