2
* Copyright 2016 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by Jonas G. Drange <jonas.drange@canonical.com>
19
import Qt.labs.folderlistmodel 2.1
22
import Ubuntu.Components 1.3
23
import Ubuntu.Components.Popups 1.3
24
import Ubuntu.Settings.Components 0.1
25
import Ubuntu.Test 0.1
52
property var instance: null
53
property var fsModel: null
56
fsModel = fsModelComp.createObject(testRoot);
60
PopupUtils.close(instance);
61
tryCompareFunction(function () {
62
return !!findChild(testRoot, "filePicker");
70
function test_breadCrumb_data() {
73
folder: "file:///home/user/",
74
parentFolder: "file:///home",
76
targetText: i18n.dtr("ubuntu-settings-components", "%1 (%2 files)")
77
.arg(i18n.tr("Device") + "/home/user")
82
parentFolder: "file:///",
84
targetText: i18n.dtr("ubuntu-settings-components", "%1 (%2 files)")
85
.arg(i18n.tr("Device"))
89
folder: "file:///bar/baz",
90
parentFolder: "file:///bar",
92
targetText: i18n.dtr("ubuntu-settings-components", "%1 (%2 file)")
93
.arg(i18n.tr("Device") + "/bar/baz")
99
function test_breadCrumb(data) {
100
fsModel.folder = data.folder;
101
fsModel.parentFolder = data.parentFolder;
102
fsModel.count = data.count;
103
instance = PopupUtils.open(filePickerComp, null, { "fsModel": fsModel });
104
waitForRendering(instance);
106
var crumbs = findChild(instance, "filePickerBreadcrumb");
107
compare(crumbs.text, data.targetText)
110
function test_backButtonEnabled_data() {
112
{ folder: "file:///", parentFolder: "file:///", targetEnabled: false },
113
{ folder: "file:///bar", parentFolder: "file:///", targetEnabled: true },
114
{ folder: "file:///bar/baz", parentFolder: "file:///bar", targetEnabled: true },
118
function test_backButtonEnabled(data) {
119
fsModel.folder = data.folder;
120
fsModel.parentFolder = data.parentFolder;
121
instance = PopupUtils.open(filePickerComp, null, { "fsModel": fsModel });
122
waitForRendering(instance);
124
var button = findChild(instance, "filePickerBackButton");
125
compare(button.enabled, data.targetEnabled);
128
function test_backButtonAction_data() {
130
{ folder: "file:///", parentFolder: "file:///" },
131
{ folder: "file:///bar", parentFolder: "file:///" },
132
{ folder: "file:///bar/baz", parentFolder: "file:///bar" }
136
function test_backButtonAction(data) {
137
fsModel.folder = data.folder;
138
fsModel.parentFolder = data.parentFolder;
139
instance = PopupUtils.open(filePickerComp, null, { "fsModel": fsModel });
140
waitForRendering(instance);
142
var button = findChild(instance, "filePickerBackButton");
143
mouseClick(button, button.width / 2, button.height / 2);
144
compare(fsModel.folder, fsModel.parentFolder);
147
function test_renderFiles_data() {
149
{ files: [ ["fileA.txt", "/home/user/fileA.txt", "", 5000, "txt", false, true] ] },
151
["fileA.txt", "/home/user/fileA.txt", "", 5000, "txt", false, true],
152
["fileB.txt", "/fileB.txt", "", 5000, "txt", false, true],
153
["somedir", "/somedir", "somedir", 4001, "", true, false]
158
function test_renderFiles(data) {
159
for (var i = 0; i < data.files.length; i++) {
160
fsModel.mockAddFile.apply(fsModel, data.files[i]);
162
instance = PopupUtils.open(filePickerComp, null, { "fsModel": fsModel });
163
waitForRendering(instance);
165
// Make sure each file was rendered.
166
for (var i = 0; i < data.files.length; i++) {
167
verify(findChild(instance, "filePickerFileItem_" + i));
171
function test_accept_data() {
173
["fileA.txt", "file:///home/user/fileA.txt", "", 5000, "txt", false, true],
174
["fileB.txt", "file:///fileB.txt", "", 5000, "txt", false, true]
177
{ "files": files, accept: 0, targetAcceptPath: "file:///home/user/fileA.txt" },
178
{ "files": files, accept: 1, targetAcceptPath: "file:///fileB.txt" },
182
function test_accept(data) {
183
for (var i = 0; i < data.files.length; i++) {
184
fsModel.mockAddFile.apply(fsModel, data.files[i]);
186
instance = PopupUtils.open(filePickerComp, null, { "fsModel": fsModel });
187
waitForRendering(instance);
189
var item = findChild(instance, "filePickerFileItem_" + data.accept);
190
mouseClick(item, item.width / 2, item.height / 2);
192
spy.target = instance;
193
spy.signalName = "accept";
195
var btn = findChild(instance, "filePickerAccept");
196
mouseClick(btn, btn.width / 2, btn.height / 2);
198
compare(spy.count, 1);
199
compare(spy.signalArguments[0][0], data.targetAcceptPath);
202
function test_reject() {
203
instance = PopupUtils.open(filePickerComp, null, { "fsModel": fsModel });
204
waitForRendering(instance);
206
spy.target = instance;
207
spy.signalName = "reject";
209
var btn = findChild(instance, "filePickerCancel");
210
mouseClick(btn, btn.width / 2, btn.height / 2);
212
compare(spy.count, 1);