Merge lp:~elopio/ubuntu-ui-toolkit/toogles_emulator into lp:ubuntu-ui-toolkit

Proposed by Leo Arias
Status: Merged
Approved by: Francis Ginther
Approved revision: 750
Merged at revision: 756
Proposed branch: lp:~elopio/ubuntu-ui-toolkit/toogles_emulator
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 106 lines (+91/-0)
2 files modified
tests/autopilot/ubuntuuitoolkit/emulators.py (+16/-0)
tests/autopilot/ubuntuuitoolkit/tests/test_emulators.py (+75/-0)
To merge this branch: bzr merge lp:~elopio/ubuntu-ui-toolkit/toogles_emulator
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
I Ahmad (community) Approve
Nicholas Skaggs (community) Approve
Ubuntu SDK team Pending
Review via email: mp+186922@code.launchpad.net

Commit message

Added the autopilot emulator for toggles.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Looks good, and you test all 4 possible scenarios for checking and unchecking :-)

review: Approve
Revision history for this message
I Ahmad (iahmad) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/ubuntuuitoolkit/emulators.py'
2--- tests/autopilot/ubuntuuitoolkit/emulators.py 2013-09-03 17:30:42 +0000
3+++ tests/autopilot/ubuntuuitoolkit/emulators.py 2013-09-21 20:06:42 +0000
4@@ -283,3 +283,19 @@
5 for button in buttons:
6 if button.text == text:
7 return button
8+
9+
10+class CheckBox(UbuntuUIToolkitEmulatorBase):
11+ """CheckBox Autopilot emulator."""
12+
13+ def check(self):
14+ """Check a CheckBox, if its not already checked."""
15+ if not self.checked:
16+ self.pointing_device.click_object(self)
17+ self.checked.wait_for(True)
18+
19+ def uncheck(self):
20+ """Uncheck a CheckBox, if its not already unchecked."""
21+ if self.checked:
22+ self.pointing_device.click_object(self)
23+ self.checked.wait_for(False)
24
25=== modified file 'tests/autopilot/ubuntuuitoolkit/tests/test_emulators.py'
26--- tests/autopilot/ubuntuuitoolkit/tests/test_emulators.py 2013-09-17 20:56:19 +0000
27+++ tests/autopilot/ubuntuuitoolkit/tests/test_emulators.py 2013-09-21 20:06:42 +0000
28@@ -380,3 +380,78 @@
29 AssertionError, popover.click_button_by_text, 'Action one')
30 self.assertEqual(
31 error.message, 'The popover is not open.')
32+
33+
34+TEST_QML_WITH_CHECKBOX = ("""
35+import QtQuick 2.0
36+import Ubuntu.Components 0.1
37+
38+MainView {
39+ width: units.gu(48)
40+ height: units.gu(60)
41+
42+ Item {
43+ CheckBox {
44+ checked: false
45+ objectName: "test_checkbox"
46+ }
47+ }
48+}
49+""")
50+
51+
52+TEST_QML_WITH_SWITCH = ("""
53+import QtQuick 2.0
54+import Ubuntu.Components 0.1
55+
56+MainView {
57+ width: units.gu(48)
58+ height: units.gu(60)
59+
60+ Item {
61+ Switch {
62+ checked: false
63+ objectName: "test_switch"
64+ }
65+ }
66+}
67+""")
68+
69+
70+class ToggleTestCase(tests.QMLStringAppTestCase):
71+
72+ scenarios = [
73+ ('checkbox', dict(
74+ test_qml=TEST_QML_WITH_CHECKBOX, objectName='test_checkbox')),
75+ ('switch', dict(
76+ test_qml=TEST_QML_WITH_SWITCH, objectName='test_switch'))
77+ ]
78+
79+ def setUp(self):
80+ super(ToggleTestCase, self).setUp()
81+ self.toggle = self.main_view.select_single(
82+ emulators.CheckBox, objectName=self.objectName)
83+
84+ def test_toggle_emulator(self):
85+ self.assertIsInstance(self.toggle, emulators.CheckBox)
86+
87+ def test_check_toggle(self):
88+ self.assertFalse(self.toggle.checked)
89+ self.toggle.check()
90+ self.assertTrue(self.toggle.checked)
91+
92+ def test_check_toggle_already_checked(self):
93+ self.toggle.check()
94+ with mock.patch.object(input.Pointer, 'click_object') as mock_click:
95+ self.toggle.check()
96+ self.assertFalse(mock_click.called)
97+
98+ def test_uncheck_toggle(self):
99+ self.toggle.check()
100+ self.toggle.uncheck()
101+ self.assertFalse(self.toggle.checked)
102+
103+ def test_uncheck_toggle_already_unchecked(self):
104+ with mock.patch.object(input.Pointer, 'click_object') as mock_click:
105+ self.toggle.uncheck()
106+ self.assertFalse(mock_click.called)

Subscribers

People subscribed via source and target branches

to status/vote changes: