Merge lp:~mikemc/ubuntuone-credentials/add-qml-unit-tests into lp:ubuntuone-credentials

Proposed by Mike McCracken
Status: Merged
Approved by: Mike McCracken
Approved revision: 72
Merged at revision: 72
Proposed branch: lp:~mikemc/ubuntuone-credentials/add-qml-unit-tests
Merge into: lp:ubuntuone-credentials
Diff against target: 241 lines (+198/-1)
3 files modified
online-accounts-provider/NewAccount.qml (+3/-1)
online-accounts-provider/tests/unit/tst_newaccount.qml (+161/-0)
online-accounts-provider/tests/unit/utils.js (+34/-0)
To merge this branch: bzr merge lp:~mikemc/ubuntuone-credentials/add-qml-unit-tests
Reviewer Review Type Date Requested Status
Leo Arias (community) code review Approve
PS Jenkins bot continuous-integration Approve
dobey (community) Approve
Review via email: mp+189426@code.launchpad.net

Commit message

- Add initial suite of QML unit tests for online-accounts-provider.

Description of the change

- Add initial suite of QML unit tests for online-accounts-provider.

Mostly just covers input validation at this point.

To run, from the top of this branch, do:
mkdir build
cd build
cmake .. # this will not configure it correctly for install, but is fine for the tests
make online-accounts-provider-qmlunit-tests

# Don't relax. The tests are fast!

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: Approve (continuous-integration)
Revision history for this message
dobey (dobey) wrote :

I think the qml and javascript files need to have the appropriate copyright comment headers.

review: Needs Fixing
69. By Mike McCracken

merge with trunk

70. By Mike McCracken

add copyright headers to source files

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
71. By Mike McCracken

remove unused empty functions

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
72. By Mike McCracken

standardize on camelCase, sort of

Revision history for this message
Leo Arias (elopio) wrote :

Thank you!

review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'online-accounts-provider/NewAccount.qml'
2--- online-accounts-provider/NewAccount.qml 2013-10-09 13:10:58 +0000
3+++ online-accounts-provider/NewAccount.qml 2013-10-11 20:07:00 +0000
4@@ -111,6 +111,7 @@
5
6 LoginForm {
7 id: loginForm
8+ objectName: "loginForm"
9 visible: true
10
11 anchors.left: parent.left
12@@ -120,6 +121,7 @@
13
14 RegisterForm {
15 id: registerForm
16+ objectName: "registerForm"
17 visible: false
18
19 anchors.left: parent.left
20@@ -150,6 +152,7 @@
21
22 function resetUI() {
23 errorLabel.visible = false;
24+ errorLabel.text = "";
25 emailTextField.text = "";
26 loginForm.resetUI()
27 registerForm.resetUI();
28@@ -253,7 +256,6 @@
29 }
30
31 function validateInput() {
32- console.debug("in validateInput, emailTextField.text = " + emailTextField.text);
33 formValid = emailTextField.acceptableInput;
34 if(!formValid) {
35 showError("Please enter a valid email address.");
36
37=== added directory 'online-accounts-provider/tests/unit'
38=== added file 'online-accounts-provider/tests/unit/tst_newaccount.qml'
39--- online-accounts-provider/tests/unit/tst_newaccount.qml 1970-01-01 00:00:00 +0000
40+++ online-accounts-provider/tests/unit/tst_newaccount.qml 2013-10-11 20:07:00 +0000
41@@ -0,0 +1,161 @@
42+/*
43+ * Copyright (C) 2013 Canonical Ltd.
44+ *
45+ *
46+ * This program is free software: you can redistribute it and/or modify it
47+ * under the terms of the GNU General Public License version 3, as published
48+ * by the Free Software Foundation.
49+ *
50+ * This program is distributed in the hope that it will be useful, but
51+ * WITHOUT ANY WARRANTY; without even the implied warranties of
52+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
53+ * PURPOSE. See the GNU General Public License for more details.
54+ *
55+ * You should have received a copy of the GNU General Public License along
56+ * with this program. If not, see <http://www.gnu.org/licenses/>.
57+ */
58+
59+import QtQuick 2.0
60+import QtTest 1.0
61+import Ubuntu.Test 0.1
62+import Ubuntu.Components 0.1
63+import "utils.js" as Utils
64+import "../../"
65+
66+Item {
67+ // The objects
68+ NewAccount {
69+ id: newAccount
70+ anchors.fill: parent
71+ }
72+
73+ Rectangle {
74+ /* fake to isolate NewAccount from Main */
75+ id: loadingOverlay
76+ }
77+
78+
79+ TestCase {
80+ name: "NewAccountTests"
81+ id: testCase
82+
83+ property var loginForm
84+ property var registerForm
85+ property var errorLabel
86+ property var emailTextField
87+
88+ function init() {
89+ newAccount.resetUI();
90+ }
91+
92+ function initTestCase() {
93+ loginForm = Utils.findChild(newAccount, "loginForm")
94+ registerForm = Utils.findChild(newAccount, "registerForm")
95+ errorLabel = Utils.findChild(newAccount, "errorLabel")
96+ emailTextField = Utils.findChild(newAccount, "emailTextField")
97+ }
98+
99+ function test_resetUI() {
100+
101+ compare(newAccount.currentVisible, loginForm);
102+ compare(loginForm.visible, true);
103+ compare(errorLabel.visible, false);
104+ compare(emailTextField.text, "");
105+ compare(newAccount.state, "login");
106+
107+ var loginForm_pwd = Utils.findChild(loginForm, "loginFormPasswordTextField");
108+ compare(loginForm_pwd.text, "");
109+
110+ compare(loginForm.twoFactorVisible, false);
111+ }
112+
113+ function test_toggleNewUser() {
114+
115+ compare(loginForm.visible, true);
116+ compare(registerForm.visible, false);
117+ compare(newAccount.state, "login");
118+
119+ newAccount.toggleNewUser();
120+
121+ compare(loginForm.visible, false);
122+ compare(registerForm.visible, true);
123+ compare(newAccount.state, "register");
124+
125+ }
126+
127+ function test_showTwoFactorUI() {
128+ compare(loginForm.twoFactorVisible, false);
129+ compare(newAccount.state, "login");
130+ newAccount.showTwoFactorUI();
131+ compare(newAccount.state, "twofactor");
132+ compare(loginForm.twoFactorVisible, true);
133+ }
134+
135+ function test_loginValidateInput_data() {
136+ var invalidEmail = "invalid email";
137+ var validEmail = "valid@email.com";
138+ var validPassword = "123456789";
139+ var validTwoFactorCode = "123456";
140+ return [
141+ { shouldShowError: true, tag: "empty input no 2fa", showTwoFactor: false, email: "", password: "", twoFactorCode: ""},
142+ { shouldShowError: true, tag: "empty input, with 2fa visible", showTwoFactor: true, email: "", password: "", twoFactorCode: ""},
143+ { shouldShowError: true, tag: "invalid email", showTwoFactor: false, email: invalidEmail, password: validPassword, twoFactorCode: ""},
144+ { shouldShowError: true, tag: "invalid email with 2fa", showTwoFactor: true, email: invalidEmail, password: validPassword, twoFactorCode: validTwoFactorCode},
145+ { shouldShowError: true, tag: "short pwd", showTwoFactor: false, email: validEmail, password: "123", twoFactorCode: ""},
146+ { shouldShowError: true, tag: "short pwd with 2fa", showTwoFactor: true, email: validEmail, password: "123", twoFactorCode: validTwoFactorCode},
147+
148+ { shouldShowError: false, tag: "OK no 2fa", showTwoFactor: false, email: validEmail, password: validPassword, twoFactorCode: ""},
149+ { shouldShowError: false, tag: "OK with 2fa", showTwoFactor: true, email: validEmail, password: validPassword, twoFactorCode: validTwoFactorCode},
150+ ]
151+ }
152+
153+ function test_loginValidateInput(data) {
154+ newAccount.resetUI();
155+ emailTextField.text = data.email;
156+ var passwordTextField = Utils.findChild(loginForm, "loginFormPasswordTextField");
157+ passwordTextField.text = data.password;
158+ if(data.showTwoFactor) {
159+ newAccount.showTwoFactorUI();
160+ var twoFactorTextField = Utils.findChild(loginForm, "twoFactorTextField");
161+ twoFactorTextField.text = data.twoFactorCode;
162+ }
163+
164+ newAccount.validateInput();
165+ compare(errorLabel.visible, data.shouldShowError);
166+ }
167+
168+ function test_registerValidateInput_data() {
169+ var invalidEmail = "invalid email";
170+ var validEmail = "valid@email.com";
171+ var invalidName = "";
172+ var validName = "Vlad Name";
173+ var validPassword = "123456789";
174+ return [
175+ { shouldShowError: true, tag: "invalid email", email: "invalid", name: validName, password: validPassword, confirmPassword: validPassword, termsChecked: true},
176+ { shouldShowError: true, tag: "empty name", email: validEmail, name: "", password: validPassword, confirmPassword: validPassword, termsChecked: true},
177+ { shouldShowError: true, tag: "short pwd", email: validEmail, name: validName, password: "123", confirmPassword: "123", termsChecked: true},
178+ { shouldShowError: true, tag: "pwd mismatch", email: validEmail, name: validName, password: validPassword, confirmPassword: "123456789-mismatch", termsChecked: true},
179+ { shouldShowError: true, tag: "termsnotchecked", email: validEmail, name: validName, password: validPassword, confirmPassword: "123456789-mismatch", termsChecked: false},
180+ { shouldShowError: false, tag: "everything OK", email: validEmail, name: validName, password: validPassword, confirmPassword: validPassword, termsChecked: true},
181+ ]
182+ }
183+
184+ function test_registerValidateInput(data) {
185+ newAccount.resetUI();
186+ newAccount.toggleNewUser();
187+ emailTextField.text = data.email;
188+ var nameTextField = Utils.findChild(registerForm, "nameTextField");
189+ nameTextField.text = data.name;
190+ var passwordTextField = Utils.findChild(registerForm, "passwordTextField");
191+ passwordTextField.text = data.password;
192+ var registerForm_confirm_pwd = Utils.findChild(registerForm, "confirmPasswordTextField");
193+ registerForm_confirm_pwd.text = data.confirmPassword;
194+ var termsCheckbox = Utils.findChild(registerForm, "termsAndConditionsCheckBox");
195+ termsCheckbox.checked = data.termsChecked;
196+
197+ newAccount.validateInput()
198+
199+ compare(errorLabel.visible, data.shouldShowError);
200+ }
201+ }
202+}
203
204=== added file 'online-accounts-provider/tests/unit/utils.js'
205--- online-accounts-provider/tests/unit/utils.js 1970-01-01 00:00:00 +0000
206+++ online-accounts-provider/tests/unit/utils.js 2013-10-11 20:07:00 +0000
207@@ -0,0 +1,34 @@
208+/*
209+ * Copyright (C) 2013 Canonical Ltd.
210+ *
211+ *
212+ * This program is free software: you can redistribute it and/or modify it
213+ * under the terms of the GNU General Public License version 3, as published
214+ * by the Free Software Foundation.
215+ *
216+ * This program is distributed in the hope that it will be useful, but
217+ * WITHOUT ANY WARRANTY; without even the implied warranties of
218+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
219+ * PURPOSE. See the GNU General Public License for more details.
220+ *
221+ * You should have received a copy of the GNU General Public License along
222+ * with this program. If not, see <http://www.gnu.org/licenses/>.
223+ */
224+
225+.pragma library
226+
227+// Find an object with the given name in the children tree of "obj"
228+function findChild(obj,objectName) {
229+ var childs = new Array(0);
230+ childs.push(obj)
231+ while (childs.length > 0) {
232+ if (childs[0].objectName == objectName) {
233+ return childs[0]
234+ }
235+ for (var i in childs[0].children) {
236+ childs.push(childs[0].children[i])
237+ }
238+ childs.splice(0, 1);
239+ }
240+ return undefined;
241+}

Subscribers

People subscribed via source and target branches

to all changes: