| 1 |
import QtQuick 2.9 |
| 2 |
import QtTest 1.0 |
| 3 |
import Lomiri.Test @LOMIRI_TEST_VERSION@ |
| 4 |
|
| 5 |
Item { |
| 6 |
id: root |
| 7 |
width: 400 |
| 8 |
height: 400 |
| 9 |
|
| 10 |
QtObject { |
| 11 |
id: request |
| 12 |
property string title |
| 13 |
property string message |
| 14 |
property string loginText |
| 15 |
|
| 16 |
property bool queryUserName: false |
| 17 |
property string userNameText |
| 18 |
property string userName |
| 19 |
|
| 20 |
property bool queryPassword: false |
| 21 |
property string passwordText |
| 22 |
property string password |
| 23 |
|
| 24 |
property string forgotPasswordText |
| 25 |
property url forgotPasswordUrl |
| 26 |
|
| 27 |
property string registerText |
| 28 |
property url registerUrl |
| 29 |
|
| 30 |
signal accept() |
| 31 |
signal cancel() |
| 32 |
} |
| 33 |
|
| 34 |
SignalSpy { |
| 35 |
id: spyAccept |
| 36 |
target: request |
| 37 |
signalName: "accept" |
| 38 |
} |
| 39 |
|
| 40 |
SignalSpy { |
| 41 |
id: spyCancel |
| 42 |
target: request |
| 43 |
signalName: "cancel" |
| 44 |
} |
| 45 |
|
| 46 |
Component { |
| 47 |
id: pageComponent |
| 48 |
SignOnUiDialog {} |
| 49 |
} |
| 50 |
|
| 51 |
LomiriTestCase { |
| 52 |
name: "SignOnUiDialog" |
| 53 |
when: windowShown |
| 54 |
|
| 55 |
function tapButton(button) { |
| 56 |
mouseClick(button, button.width / 2, button.height / 2, Qt.LeftButton, 0, 0) |
| 57 |
} |
| 58 |
|
| 59 |
function createPage() { |
| 60 |
var page = pageComponent.createObject(root) |
| 61 |
spyCancel.clear() |
| 62 |
spyAccept.clear() |
| 63 |
return page |
| 64 |
} |
| 65 |
|
| 66 |
function test_request_data() { |
| 67 |
return [ |
| 68 |
{ |
| 69 |
tag: "only password", |
| 70 |
request: { |
| 71 |
queryPassword: true, |
| 72 |
queryUserName: false, |
| 73 |
passwordText: "What's your password?", |
| 74 |
password: "prefilled pw" |
| 75 |
} |
| 76 |
}, |
| 77 |
{ |
| 78 |
tag: "only username", |
| 79 |
request: { |
| 80 |
queryPassword: false, |
| 81 |
queryUserName: true, |
| 82 |
userNameText: "What's your name?", |
| 83 |
userName: "Tommy" |
| 84 |
} |
| 85 |
}, |
| 86 |
{ |
| 87 |
tag: "username and password", |
| 88 |
request: { |
| 89 |
queryPassword: true, |
| 90 |
passwordText: "What's your password?", |
| 91 |
password: "prefilled pw", |
| 92 |
queryUserName: true, |
| 93 |
userNameText: "What's your name?", |
| 94 |
userName: "Tommy" |
| 95 |
} |
| 96 |
}, |
| 97 |
{ |
| 98 |
tag: "forgot password", |
| 99 |
request: { |
| 100 |
queryPassword: true, |
| 101 |
passwordText: "What's your password?", |
| 102 |
password: "prefilled pw", |
| 103 |
forgotPasswordUrl: "http://localhost/remember", |
| 104 |
forgotPasswordText: "Reset your password" |
| 105 |
} |
| 106 |
} |
| 107 |
] |
| 108 |
} |
| 109 |
|
| 110 |
function test_request(data) { |
| 111 |
for (var p in data.request) { |
| 112 |
request[p] = data.request[p] |
| 113 |
} |
| 114 |
|
| 115 |
var page = createPage() |
| 116 |
verify(page != null) |
| 117 |
|
| 118 |
var passwordLabel = findChild(page, "passwordLabel") |
| 119 |
verify(passwordLabel != null) |
| 120 |
compare(passwordLabel.visible, request.queryPassword) |
| 121 |
|
| 122 |
var passwordField = findChild(page, "passwordField") |
| 123 |
verify(passwordField != null) |
| 124 |
compare(passwordField.visible, request.queryPassword) |
| 125 |
|
| 126 |
if (request.queryPassword) { |
| 127 |
compare(passwordLabel.text, request.passwordText) |
| 128 |
compare(passwordField.text, request.password) |
| 129 |
} |
| 130 |
|
| 131 |
var userNameLabel = findChild(page, "userNameLabel") |
| 132 |
verify(userNameLabel != null) |
| 133 |
compare(userNameLabel.visible, request.queryUserName) |
| 134 |
|
| 135 |
var userNameField = findChild(page, "userNameField") |
| 136 |
verify(userNameField != null) |
| 137 |
compare(userNameField.visible, request.queryUserName) |
| 138 |
|
| 139 |
if (request.queryUserName) { |
| 140 |
compare(userNameLabel.text, request.userNameText) |
| 141 |
compare(userNameField.text, request.userName) |
| 142 |
} |
| 143 |
|
| 144 |
var forgotPasswordLabel = findChild(page, "forgotPasswordLabel") |
| 145 |
verify(forgotPasswordLabel != null) |
| 146 |
compare(forgotPasswordLabel.visible, |
| 147 |
request.forgotPasswordUrl.toString() != "") |
| 148 |
|
| 149 |
page.destroy() |
| 150 |
} |
| 151 |
|
| 152 |
function test_buttons_data() { |
| 153 |
return [ |
| 154 |
{ |
| 155 |
tag: "cancel", |
| 156 |
buttonName: "cancelButton", |
| 157 |
expectedCancelCount: 1, |
| 158 |
expectedAcceptCount: 0 |
| 159 |
}, |
| 160 |
{ |
| 161 |
tag: "accept", |
| 162 |
buttonName: "acceptButton", |
| 163 |
expectedCancelCount: 0, |
| 164 |
expectedAcceptCount: 1 |
| 165 |
} |
| 166 |
] |
| 167 |
} |
| 168 |
|
| 169 |
function test_buttons(data) { |
| 170 |
request.queryPassword = true |
| 171 |
request.passwordText = "Enter your password" |
| 172 |
|
| 173 |
var page = createPage() |
| 174 |
verify(page != null) |
| 175 |
|
| 176 |
var button = findChild(page, data.buttonName) |
| 177 |
verify(button != null) |
| 178 |
verify(button.visible) |
| 179 |
|
| 180 |
tapButton(button) |
| 181 |
compare(spyAccept.count, data.expectedAcceptCount) |
| 182 |
compare(spyCancel.count, data.expectedCancelCount) |
| 183 |
|
| 184 |
page.destroy() |
| 185 |
} |
| 186 |
} |
| 187 |
} |