Debian Codegraph @

tests/online-accounts-ui/tst_qmlplugin/tst_AuthorizationPage.qml.in

raw
1 import QtQuick 2.9
2 import QtTest 1.0
3 import SSO.OnlineAccounts 0.1
4 import Lomiri.Test @LOMIRI_TEST_VERSION@
5
6 Item {
7 id: root
8 width: 400
9 height: 400
10
11 AccountServiceModel {
12 id: accountsModel
13 includeDisabled: true
14 provider: "cool"
15 service: "coolmail"
16 }
17
18 SignalSpy {
19 id: spyDenied
20 signalName: "denied"
21 }
22
23 SignalSpy {
24 id: spyCreateAccount
25 signalName: "createAccount"
26 }
27
28 SignalSpy {
29 id: spyAllowed
30 signalName: "allowed"
31 }
32
33 SignalSpy {
34 id: spyAccount
35 signalName: "synced"
36 }
37
38 Component {
39 id: accountComponent
40 Account {}
41 }
42
43 Component {
44 id: pageComponent
45 AuthorizationPage {
46 model: accountsModel
47 }
48 }
49
50 LomiriTestCase {
51 name: "AuthorizationPage"
52 when: windowShown
53
54 function createAccount(displayName) {
55 spyAccount.clear()
56 var accountHandle = Manager.createAccount("cool")
57 var account = accountComponent.createObject(null, {
58 "objectHandle": accountHandle
59 })
60 account.updateDisplayName(displayName)
61 account.updateEnabled(false)
62 spyAccount.target = account
63 account.sync()
64 if (spyAccount.count === 0) {
65 spyAccount.wait()
66 }
67 compare(spyAccount.count, 1)
68 account.destroy(1000)
69 }
70
71 function tapButton(button) {
72 mouseClick(button, button.width / 2, button.height / 2, Qt.LeftButton, 0, 0)
73 }
74
75 function createPage(params) {
76 var page = pageComponent.createObject(root, params)
77 spyAllowed.clear()
78 spyAllowed.target = page
79 spyDenied.clear()
80 spyDenied.target = page
81 spyCreateAccount.clear()
82 spyCreateAccount.target = page
83 return page
84 }
85
86 function test_1_one_account() {
87 createAccount("My account")
88 var page = createPage({
89 "application": {
90 "displayName": "My app",
91 "displayId": "com.lomiri/MyApp",
92 },
93 "provider": { "displayName": "My provider" }
94 })
95 verify(page != null)
96
97 var label = findChild(page, "appLabel")
98 verify(label != null)
99 compare(label.text, "My app")
100
101 label = findChild(page, "pkgLabel")
102 verify(label != null)
103 compare(label.text, "com.lomiri/MyApp")
104
105 label = findChild(page, "msgLabel")
106 verify(label != null)
107 compare(label.text, "wants to access your My provider account")
108
109 var accountLabel = findChild(page, "accountLabel")
110 verify(accountLabel != null)
111 compare(accountLabel.visible, true)
112 compare(accountLabel.text, "My account")
113
114 // Check that the selector is *not* visible
115 var accountSelector = findChild(page, "accountSelector")
116 verify(accountSelector != null)
117 compare(accountSelector.visible, false)
118
119 // Test the buttons
120 var allowButton = findChild(page, "allowButton")
121 verify(allowButton != null)
122 compare(allowButton.visible, true)
123 tapButton(allowButton)
124 compare(spyAllowed.count, 1)
125 compare(spyAllowed.signalArguments[0][0], accountsModel.get(0, "accountId"))
126 compare(spyDenied.count, 0)
127 compare(spyCreateAccount.count, 0)
128
129 var denyButton = findChild(page, "denyButton")
130 verify(denyButton != null)
131 compare(denyButton.visible, true)
132 tapButton(denyButton)
133 compare(spyAllowed.count, 1)
134 compare(spyDenied.count, 1)
135 compare(spyCreateAccount.count,0)
136
137 page.destroy()
138 }
139
140 function test_2_add_another_data() {
141 return [
142 { tag: "with button", canAdd: true },
143 { tag: "without button", canAdd: false }
144 ]
145 }
146
147 function test_2_add_another(data) {
148 var page = createPage({
149 "application": { "displayName": "My app" },
150 "provider": { "displayName": "My provider" },
151 "canAddAnotherAccount": data.canAdd
152 })
153 verify(page != null)
154
155 var addAnotherButton = findChild(page, "addAnotherButton")
156 verify(addAnotherButton != null)
157 compare(addAnotherButton.visible, data.canAdd)
158 if (addAnotherButton.visible) {
159 tapButton(addAnotherButton)
160 compare(spyAllowed.count, 0)
161 compare(spyDenied.count, 0)
162 compare(spyCreateAccount.count, 1)
163 }
164
165 page.destroy()
166 }
167
168 function test_3_many_accounts_data() {
169 return [
170 { tag: "first account", index: 0 },
171 { tag: "second account", index: 1 }
172 ]
173 }
174
175 function test_3_many_accounts(data) {
176 createAccount("Your account")
177 var page = createPage({
178 "application": { "displayName": "My app" },
179 "provider": { "displayName": "My provider" }
180 })
181 verify(page != null)
182
183 var accountLabel = findChild(page, "accountLabel")
184 verify(accountLabel != null)
185 compare(accountLabel.visible, false)
186
187 var accountSelector = findChild(page, "accountSelector")
188 verify(accountSelector != null)
189 compare(accountSelector.visible, true)
190 accountSelector.selectedIndex = data.index
191
192 var allowButton = findChild(page, "allowButton")
193 verify(allowButton != null)
194 compare(allowButton.visible, true)
195 tapButton(allowButton)
196 compare(spyAllowed.count, 1)
197 compare(spyAllowed.signalArguments[0][0],
198 accountsModel.get(data.index, "accountId"))
199 compare(spyDenied.count, 0)
200 compare(spyCreateAccount.count, 0)
201
202 page.destroy()
203 }
204 }
205 }