| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
import time |
| 4 |
|
| 5 |
import dialoglib |
| 6 |
import testlib |
| 7 |
|
| 8 |
|
| 9 |
@testlib.nondestructive |
| 10 |
class TestDialog(testlib.MachineCase): |
| 11 |
|
| 12 |
def test(self): |
| 13 |
b = self.browser |
| 14 |
d = dialoglib.DialogHelpers(b, "#dialog") |
| 15 |
|
| 16 |
# Missing coverage: |
| 17 |
# |
| 18 |
# exception in async validation |
| 19 |
|
| 20 |
def enter_online_validation_mode(): |
| 21 |
# put dialog into online validation mode by triggering a |
| 22 |
# failed validation |
| 23 |
d.set_Checkbox("flag", val=True) |
| 24 |
d.set_TextInput("text", "") |
| 25 |
b.click(d.apply_button()) |
| 26 |
b.wait_in_text(d.helper_text("text"), "Text can not be empty") |
| 27 |
d.set_Checkbox("flag", val=False) |
| 28 |
|
| 29 |
self.login_and_go("/playground/dialog", superuser=False) |
| 30 |
|
| 31 |
# DialogTextInput with excuse, explanation, warning, and synch |
| 32 |
# validation failure |
| 33 |
|
| 34 |
b.click("#open") |
| 35 |
d.wait_Checkbox("flag", val=False) |
| 36 |
self.assertFalse(d.get_Checkbox("flag")) |
| 37 |
b.wait_visible(d.field("text") + ":disabled") |
| 38 |
b.wait_in_text(d.helper_text("text"), "Disabled") |
| 39 |
|
| 40 |
d.set_Checkbox("flag", val=True) |
| 41 |
b.wait_visible(d.field("text") + ":not(:disabled)") |
| 42 |
b.wait_in_text(d.helper_text("text"), "Explanation") |
| 43 |
|
| 44 |
# test pasting text |
| 45 |
b.set_input_text(d.field("text"), "XXX", paste=True) |
| 46 |
d.wait_TextInput("text", "XXX") |
| 47 |
b.set_input_text(d.field("text"), "YYY", paste=True) |
| 48 |
d.wait_TextInput("text", "YYY") |
| 49 |
b.set_input_text(d.field("text"), "ZZZ", paste=True, append=True, value_check=False) |
| 50 |
d.wait_TextInput("text", "YYYZZZ") |
| 51 |
|
| 52 |
d.set_TextInput("text", "warn") |
| 53 |
self.assertEqual(d.get_TextInput("text"), "warn") |
| 54 |
b.wait_in_text(d.helper_text("text"), "Warning") |
| 55 |
|
| 56 |
# Excuse should have priority over Warning |
| 57 |
d.set_Checkbox("flag", val=False) |
| 58 |
b.wait_in_text(d.helper_text("text"), "Disabled") |
| 59 |
|
| 60 |
d.set_Checkbox("flag", val=True) |
| 61 |
d.set_TextInput("text", "") |
| 62 |
b.click(d.apply_button()) |
| 63 |
b.wait_in_text(d.helper_text("text"), "Text can not be empty") |
| 64 |
|
| 65 |
d.set_Checkbox("flag", val=False) |
| 66 |
b.wait_in_text(d.helper_text("text"), "Disabled") |
| 67 |
b.click(d.apply_button()) |
| 68 |
b.wait_not_present("#dialog") |
| 69 |
|
| 70 |
b.click("#open") |
| 71 |
d.set_Checkbox("flag", val=True) |
| 72 |
d.set_TextInput("text", "Text") |
| 73 |
b.click(d.apply_button()) |
| 74 |
b.wait_not_present("#dialog") |
| 75 |
b.wait_text("#text", "Text") |
| 76 |
|
| 77 |
# DialogRadioSelect with explanations and excuses |
| 78 |
|
| 79 |
b.click("#open") |
| 80 |
d.wait_RadioSelect("radio", "one") |
| 81 |
b.wait_in_text(d.id("radio", "one-label"), "One explanation") |
| 82 |
b.wait_visible(d.id("radio", "two") + ":disabled") |
| 83 |
b.wait_in_text(d.id("radio", "two-label"), "(disabled)") |
| 84 |
b.wait_in_text(d.id("radio", "two-label"), "Two explanation") |
| 85 |
d.set_RadioSelect("radio", "three") |
| 86 |
self.assertEqual(d.get_RadioSelect("radio"), "three") |
| 87 |
|
| 88 |
b.click(d.apply_button()) |
| 89 |
b.wait_not_present("#dialog") |
| 90 |
|
| 91 |
b.wait_text("#radio", "three") |
| 92 |
|
| 93 |
# DialogDropdownSelect |
| 94 |
|
| 95 |
b.click("#open") |
| 96 |
d.wait_DropdownSelect("dropdown", "one") |
| 97 |
d.set_DropdownSelect("dropdown", "three") # first call to set_async |
| 98 |
d.set_DropdownSelect("dropdown", "two") # second call, will cancel first |
| 99 |
self.assertEqual(d.get_DropdownSelect("dropdown"), "two") |
| 100 |
b.wait_in_text(d.helper_text("dropdown"), "discount") |
| 101 |
b.click(d.apply_button()) |
| 102 |
b.wait_not_present("#dialog") |
| 103 |
|
| 104 |
b.wait_text("#dropdown", "two") |
| 105 |
b.wait_text("#text2", "two") |
| 106 |
|
| 107 |
# Cancelling of irrelevant validations |
| 108 |
|
| 109 |
b.click("#open") |
| 110 |
d.set_DropdownSelect("dropdown", "three") |
| 111 |
d.wait_TextInput("text2", "three") # wait for async update to be done |
| 112 |
b.click(d.apply_button()) |
| 113 |
b.wait_in_text(d.helper_text("text3"), "Can't be empty") |
| 114 |
# start a debounced validation of text3 and remove it from the |
| 115 |
# dialog before it has finished. |
| 116 |
d.set_TextInput("text3", "x") |
| 117 |
time.sleep(0.5) |
| 118 |
d.set_TextInput("text3", "") |
| 119 |
d.set_DropdownSelect("dropdown", "one") |
| 120 |
b.click(d.apply_button()) |
| 121 |
b.wait_not_present("#dialog") |
| 122 |
|
| 123 |
# DialogDropdownSelectObject, with asynchronous updates |
| 124 |
|
| 125 |
b.click("#open") |
| 126 |
d.set_Checkbox("flag", val=True) |
| 127 |
d.wait_DropdownSelect("color", "red") |
| 128 |
self.assertEqual(d.get_TextInput("text"), "") |
| 129 |
d.set_DropdownSelect("color", "green") |
| 130 |
self.assertEqual(d.get_DropdownSelect("color"), "green") |
| 131 |
# Text does not react immediately. |
| 132 |
self.assertEqual(d.get_TextInput("text"), "") |
| 133 |
# Wait a bit and then change color again. This cancels the update. |
| 134 |
time.sleep(1) |
| 135 |
d.set_DropdownSelect("color", "blue") |
| 136 |
self.assertEqual(d.get_DropdownSelect("color"), "blue") |
| 137 |
self.assertEqual(d.get_TextInput("text"), "") |
| 138 |
# Apply while the update is still running. It should finish (1 update) |
| 139 |
b.click(d.apply_button()) |
| 140 |
b.wait_not_present("#dialog") |
| 141 |
|
| 142 |
b.wait_text("#text", "blue") |
| 143 |
b.wait_text("#color", "0/0/1") |
| 144 |
b.wait_text("#asyncUps", "1") |
| 145 |
b.wait_text("#asyncCancels", "1") |
| 146 |
|
| 147 |
# Cancelling of asynchronous tasks when the dialog is |
| 148 |
# cancelled |
| 149 |
|
| 150 |
b.click("#open") |
| 151 |
d.wait_DropdownSelect("color", "red") |
| 152 |
self.assertEqual(d.get_TextInput("text"), "") |
| 153 |
d.set_DropdownSelect("color", "green") |
| 154 |
self.assertEqual(d.get_DropdownSelect("color"), "green") |
| 155 |
# Text does not react immediately. |
| 156 |
self.assertEqual(d.get_TextInput("text"), "") |
| 157 |
b.click(d.cancel_button()) |
| 158 |
b.wait_not_present("#dialog") |
| 159 |
|
| 160 |
# Wait for update to definitely be done if it wouldn't have |
| 161 |
# been cancelled |
| 162 |
time.sleep(3) |
| 163 |
b.wait_text("#asyncUps", "0") |
| 164 |
b.wait_text("#asyncCancels", "1") |
| 165 |
|
| 166 |
# List of DialogTextInputs |
| 167 |
|
| 168 |
b.click("#open") |
| 169 |
# make sure the validation machinery is active in the |
| 170 |
# background while we modify the list. |
| 171 |
enter_online_validation_mode() |
| 172 |
b.wait_visible(d.field("list")) |
| 173 |
b.wait_not_present(d.field("list.0")) |
| 174 |
b.click(d.id("list", "add")) |
| 175 |
b.wait_visible(d.field("list.0")) |
| 176 |
d.set_TextInput("list.0", "foo") |
| 177 |
b.click(d.id("list", "add")) |
| 178 |
d.set_TextInput("list.1", "baz") |
| 179 |
b.click(d.id("list", "add")) |
| 180 |
d.set_TextInput("list.2", "bar") |
| 181 |
b.click(d.id("list.1", "remove")) |
| 182 |
d.wait_TextInput("list.1", "bar") |
| 183 |
b.wait_not_present(d.field("list.2")) |
| 184 |
b.click(d.id("list", "add")) |
| 185 |
d.set_TextInput("list.2", "magic") |
| 186 |
d.wait_TextInput("text", "magic") |
| 187 |
b.click(d.apply_button()) |
| 188 |
b.wait_not_present("#dialog") |
| 189 |
|
| 190 |
b.wait_text("#list", "foo/bar/magic") |
| 191 |
|
| 192 |
# Debounced and asynchronous validation |
| 193 |
|
| 194 |
b.click("#open") |
| 195 |
enter_online_validation_mode() |
| 196 |
# Add a field. This immediately starts a validation. (1 validation) |
| 197 |
b.click(d.id("async", "add")) |
| 198 |
b.focus(d.field("async.0.name")) |
| 199 |
b.input_text("1") |
| 200 |
# wait for debounce timeout and validation promise to be done (2 validations) |
| 201 |
b.wait_in_text(d.helper_text("async.0.name"), "Must have even number") |
| 202 |
b.input_text("2") |
| 203 |
# this starts a new debounce timeout but the validation error stays |
| 204 |
# don't wait for the debounce timeout to be over but change again while it is still pending |
| 205 |
time.sleep(0.5) |
| 206 |
b.input_text("3") |
| 207 |
# now wait for the timeout to be over but change while the promise is running |
| 208 |
time.sleep(2) |
| 209 |
b.input_text("4") |
| 210 |
# the promise for validating "123" will finish soon, but it's result must be ignored (3 validations) |
| 211 |
# let the validation for "1234" play out to completion (4 validations) |
| 212 |
time.sleep(5) |
| 213 |
# close dialog |
| 214 |
b.click(d.apply_button()) |
| 215 |
b.wait_not_present("#dialog") |
| 216 |
|
| 217 |
b.wait_text("#async", "1234:4") |
| 218 |
b.wait_text("#asyncVals", "4") |
| 219 |
|
| 220 |
b.click("#open") |
| 221 |
enter_online_validation_mode() |
| 222 |
b.click(d.id("async", "add")) # (1 validation) |
| 223 |
b.click(d.id("async", "add")) # (2 validations) |
| 224 |
b.focus(d.field("async.1.name")) |
| 225 |
b.input_text("1") |
| 226 |
# remove the first entry during the debounce timeout, this |
| 227 |
# should not disturb anything and the validation for "1" |
| 228 |
# should finish normally (3 validations) |
| 229 |
b.wait_not_present(d.helper_text("async.0.name")) |
| 230 |
b.click(d.id("async.0", "remove")) |
| 231 |
b.wait_in_text(d.helper_text("async.0.name"), "Must have even number") |
| 232 |
# remove the failure and close the dialog |
| 233 |
b.click(d.id("async.0", "remove")) |
| 234 |
b.click(d.apply_button()) |
| 235 |
b.wait_not_present("#dialog") |
| 236 |
|
| 237 |
b.wait_text("#async", "") |
| 238 |
b.wait_text("#asyncVals", "3") |
| 239 |
|
| 240 |
# Trigger validation directly via Apply. This will skip the |
| 241 |
# timeouts. |
| 242 |
|
| 243 |
b.click("#open") |
| 244 |
b.click(d.id("async", "add")) |
| 245 |
d.set_TextInput("async.0.name", "1234") |
| 246 |
b.click(d.apply_button()) |
| 247 |
b.wait_not_present("#dialog") |
| 248 |
|
| 249 |
b.wait_text("#async", "1234:4") |
| 250 |
b.wait_text("#asyncVals", "1") |
| 251 |
|
| 252 |
# Trigger validation via Apply when there are timeouts |
| 253 |
# pending. This will skip the timeouts. |
| 254 |
|
| 255 |
b.click("#open") |
| 256 |
enter_online_validation_mode() |
| 257 |
b.click(d.id("async", "add")) |
| 258 |
# now there is a timeout pending, clicking apply will run it |
| 259 |
# immediately and it will be counted. |
| 260 |
b.click(d.apply_button()) |
| 261 |
b.wait_not_present("#dialog") |
| 262 |
|
| 263 |
b.wait_text("#async", ":0") |
| 264 |
b.wait_text("#asyncVals", "1") |
| 265 |
|
| 266 |
# Type narrowing with "at()" |
| 267 |
|
| 268 |
b.click("#open") |
| 269 |
b.click(d.apply_button()) |
| 270 |
b.wait_text("#alternative", 'false') |
| 271 |
|
| 272 |
b.click("#open") |
| 273 |
b.set_checked(d.id("alternative", "checkbox"), val=True) |
| 274 |
d.set_TextInput("alternative", "1234") |
| 275 |
b.set_checked(d.id("alternative", "checkbox"), val=False) |
| 276 |
b.wait_not_present(d.field("alternative")) |
| 277 |
b.set_checked(d.id("alternative", "checkbox"), val=True) |
| 278 |
d.wait_TextInput("alternative", "") |
| 279 |
d.set_TextInput("alternative", "1234") |
| 280 |
b.click(d.apply_button()) |
| 281 |
b.wait_text("#alternative", '"1234"') |
| 282 |
|
| 283 |
# DialogError |
| 284 |
|
| 285 |
b.click("#open") |
| 286 |
|
| 287 |
d.set_DropdownSelect("error", "custom") |
| 288 |
b.click(d.apply_button()) |
| 289 |
b.wait_in_text(d.error(), "This is a failure") |
| 290 |
b.wait_in_text(d.error(), "1234-567-98A") |
| 291 |
|
| 292 |
d.set_DropdownSelect("error", "from") |
| 293 |
b.click(d.apply_button()) |
| 294 |
b.wait_in_text(d.error(), "Tool not found") |
| 295 |
b.wait_in_text(d.error(), "no such file") |
| 296 |
|
| 297 |
d.set_DropdownSelect("error", "from-random") |
| 298 |
b.click(d.apply_button()) |
| 299 |
b.wait_in_text(d.error(), "Too random") |
| 300 |
b.wait_in_text(d.error(), "1,2,3,4") |
| 301 |
|
| 302 |
d.set_DropdownSelect("error", "message") |
| 303 |
b.click(d.apply_button()) |
| 304 |
b.wait_in_text(d.error(), "Failed") |
| 305 |
b.wait_in_text(d.error(), "segmentation fault") |
| 306 |
|
| 307 |
d.set_DropdownSelect("error", "spawn") |
| 308 |
b.click(d.apply_button()) |
| 309 |
b.wait_in_text(d.error(), "--no-such-option") |
| 310 |
|
| 311 |
d.set_DropdownSelect("error", "random") |
| 312 |
b.click(d.apply_button()) |
| 313 |
b.wait_in_text(d.error(), "1,2,3,4") |
| 314 |
|
| 315 |
b.mouse(d.ouia("apply-force"), "mouseenter") |
| 316 |
b.wait_in_text(".pf-v6-c-tooltip", "Force not allowed") |
| 317 |
b.mouse(d.ouia("apply-force"), "mouseleave") # make tooltip disappear, it obscures the checkbox otherwise |
| 318 |
b.wait_not_present(".pf-v6-c-tooltip") |
| 319 |
d.set_Checkbox("allow_force", val=True) |
| 320 |
b.click(d.ouia("apply-force")) |
| 321 |
b.wait_not_present("#dialog") |
| 322 |
|
| 323 |
# init func and sub-field validation |
| 324 |
|
| 325 |
b.click("#open-with-func") |
| 326 |
d.wait_TextInput("text", "foo") |
| 327 |
d.wait_TextInput("text2", "bar") |
| 328 |
d.set_TextInput("text2", "bart") |
| 329 |
b.click(d.apply_button()) |
| 330 |
b.wait_in_text(d.helper_text("text"), "No foo without bar") |
| 331 |
d.set_TextInput("text", "food") |
| 332 |
d.set_TextInput("text2", "bar") |
| 333 |
b.wait_in_text(d.helper_text("text2"), "No bar without foo") |
| 334 |
b.click(d.cancel_button()) |
| 335 |
b.wait_not_present("#dialog") |
| 336 |
|
| 337 |
# useDialogState_async |
| 338 |
|
| 339 |
b.click("#open-async") |
| 340 |
d.set_TextInput("text", "1234") |
| 341 |
b.click(d.apply_button()) |
| 342 |
b.wait_text("#cancelled", "Cancelled: no") |
| 343 |
b.click(d.cancel_button()) |
| 344 |
b.wait_text("#cancelled", "Cancelled: yes") |
| 345 |
b.set_input_text(d.field("text"), "", value_check=False) |
| 346 |
d.wait_TextInput("text", "1234") |
| 347 |
b.wait_not_present("#dialog") |
| 348 |
|
| 349 |
b.click("#open-error") |
| 350 |
b.wait_in_text(d.error(), "Error during initialization") |
| 351 |
b.wait_in_text(d.error(), "can't get the thing") |
| 352 |
b.click(d.cancel_button()) |
| 353 |
b.wait_not_present("#dialog") |
| 354 |
|
| 355 |
b.click("#open-dialog-error") |
| 356 |
b.wait_in_text(d.error(), "Getting the thing failed") |
| 357 |
b.wait_in_text(d.error(), "can't get it") |
| 358 |
b.click(d.cancel_button()) |
| 359 |
b.wait_not_present("#dialog") |
| 360 |
|
| 361 |
def testFileChooser(self): |
| 362 |
b = self.browser |
| 363 |
m = self.machine |
| 364 |
d = dialoglib.DialogHelpers(b, "#dialog") |
| 365 |
fc = dialoglib.FileChooserHelpers(b, ".file-chooser") |
| 366 |
|
| 367 |
# Inject a mock xdg-user-dir utility. |
| 368 |
|
| 369 |
self.write_file("/usr/local/bin/xdg-user-dir", |
| 370 |
"""#! /bin/sh |
| 371 |
echo $HOME/Downloads |
| 372 |
""", perm="a+x") |
| 373 |
|
| 374 |
# Where our test files are. This is intended to be the same as |
| 375 |
# self.vm_tmpdir, but it is also hard-coded into |
| 376 |
# pkg/playground/dialog.tsx and so we hard-code it here as |
| 377 |
# well. |
| 378 |
|
| 379 |
test_files = "/var/lib/cockpittest" |
| 380 |
|
| 381 |
self.login_and_go("/playground/dialog", superuser=False) |
| 382 |
|
| 383 |
b.click("#open") |
| 384 |
|
| 385 |
# Use the get_FileChooserInput method so that Vulture doesn't |
| 386 |
# complain about it being unused. |
| 387 |
|
| 388 |
self.assertEqual(d.get_FileChooserInput("file"), "") |
| 389 |
|
| 390 |
# The first open has a empty Recent tab. |
| 391 |
|
| 392 |
b.click(d.field("file") + " .pf-v6-c-text-input-group__utilities button") |
| 393 |
b.wait_in_text(".file-chooser-listing-body", "No recent files") |
| 394 |
b.click(".file-chooser .pf-v6-c-modal-box__close button") |
| 395 |
b.wait_not_present(".file-chooser") |
| 396 |
|
| 397 |
# Basic interaction with the text input |
| 398 |
|
| 399 |
d.set_FileChooserInput("file", "/home/non-existent/foo") |
| 400 |
b.wait_in_text(d.helper_text("file"), "(No such file or directory)") |
| 401 |
|
| 402 |
b.click(d.field("file") + " .pf-v6-c-text-input-group__utilities button") |
| 403 |
b.wait_in_text(".file-chooser-listing-body", "No such file or directory") |
| 404 |
b.click(".file-chooser .pf-v6-c-modal-box__close button") |
| 405 |
b.wait_not_present(".file-chooser") |
| 406 |
|
| 407 |
m.upload(["verify/files/file-chooser-test/"], test_files) |
| 408 |
m.execute(f"mkdir '{test_files}/file-chooser-test/empty'") |
| 409 |
d.set_FileChooserInput("file", test_files) |
| 410 |
b.wait_in_text(d.helper_text("file"), "directory") |
| 411 |
|
| 412 |
# Navigate to empty directory |
| 413 |
|
| 414 |
b.click(d.field("file") + " .pf-v6-c-text-input-group__utilities button") |
| 415 |
b.wait_visible(".file-chooser") |
| 416 |
fc.set_path("cockpittest/file-chooser-test/empty") |
| 417 |
b.wait_in_text(".file-chooser-listing-body", "Directory is empty") |
| 418 |
|
| 419 |
# Go up and choose tmpdir/file-chooser-test/foo |
| 420 |
|
| 421 |
b.click(".file-chooser-listing-breadcrumbs a:contains('file-chooser-test')") |
| 422 |
b.assert_pixels(".file-chooser", "basic") |
| 423 |
b.mouse(fc.file("foo"), "click") |
| 424 |
b.click(fc.apply_button()) |
| 425 |
|
| 426 |
d.wait_FileChooserInput("file", test_files + "/file-chooser-test/foo") |
| 427 |
b.wait_in_text(d.helper_text("file"), "ASCII text") |
| 428 |
|
| 429 |
# "foo" should now be in "Recent" |
| 430 |
|
| 431 |
b.click(d.field("file") + " .pf-v6-c-text-input-group__utilities button") |
| 432 |
b.wait_visible(".file-chooser-listing-breadcrumbs nav") |
| 433 |
b.wait_visible(fc.file("foo")) |
| 434 |
b.click(fc.sidebar("Recent")) |
| 435 |
b.wait_not_present(".file-chooser-listing-breadcrumbs nav") |
| 436 |
b.wait_visible(fc.file("foo")) |
| 437 |
b.wait_in_text(fc.file("foo"), test_files + "/file-chooser-test") |
| 438 |
b.mouse(fc.file("foo"), "click") |
| 439 |
b.click(fc.apply_button()) |
| 440 |
d.wait_FileChooserInput("file", test_files + "/file-chooser-test/foo") |
| 441 |
b.wait_in_text(d.helper_text("file"), "ASCII text") |
| 442 |
|
| 443 |
# Check that "Home" has some expected files |
| 444 |
|
| 445 |
m.execute("echo hi > ~admin/.dot-file") |
| 446 |
|
| 447 |
b.click(d.field("file") + " .pf-v6-c-text-input-group__utilities button") |
| 448 |
b.click(fc.sidebar("Home")) |
| 449 |
# home can be /home/admin or /var/home/admin. |
| 450 |
home = m.execute("echo -n ~admin") |
| 451 |
b.wait_text(".file-chooser-listing-breadcrumbs", home.replace("/", "")) |
| 452 |
b.click(".file-chooser-listing-breadcrumbs a:contains('home')") |
| 453 |
b.mouse(fc.file("admin"), "dblclick") |
| 454 |
b.wait_in_text(".file-chooser-listing-body", "This directory contains only hidden files") |
| 455 |
b.click(".file-chooser-listing-body button:contains('Show hidden files')") |
| 456 |
b.wait_visible(fc.file(".ssh")) |
| 457 |
b.click(".file-chooser-listing-header button:contains('All files')") |
| 458 |
b.click(fc.file(".dot-file")) |
| 459 |
b.click(fc.apply_button()) |
| 460 |
|
| 461 |
d.wait_FileChooserInput("file", f"{home}/.dot-file") |
| 462 |
b.wait_in_text(d.helper_text("file"), "ASCII text") |
| 463 |
|
| 464 |
# Check the "Downloads" shortcut |
| 465 |
|
| 466 |
b.click(d.field("file") + " .pf-v6-c-text-input-group__utilities button") |
| 467 |
b.click(".file-chooser-sidebar tr:contains('Downloads')") |
| 468 |
b.wait_text(".file-chooser-listing-breadcrumbs", home.replace("/", "") + "Downloads") |
| 469 |
b.wait_in_text(".file-chooser-listing-body", "No such file or directory") |
| 470 |
|
| 471 |
# Check that we can't read /root |
| 472 |
|
| 473 |
fc.set_path("/root") |
| 474 |
b.wait_in_text(".file-chooser-listing-body", "Permission denied") |
| 475 |
b.assert_pixels(".file-chooser", "denied") |
| 476 |
b.click(".file-chooser .pf-v6-c-modal-box__close button") |
| 477 |
b.wait_not_present(".file-chooser") |
| 478 |
|
| 479 |
# Free text filtering |
| 480 |
|
| 481 |
d.set_FileChooserInput("file", "") |
| 482 |
b.click(d.field("file") + " .pf-v6-c-text-input-group__utilities button") |
| 483 |
b.click(fc.sidebar("Test files")) |
| 484 |
fc.set_path("file-chooser-test") |
| 485 |
|
| 486 |
b.wait_visible(fc.file("bar")) |
| 487 |
b.wait_visible(fc.file("foo")) |
| 488 |
b.wait_visible(fc.file("foobar")) |
| 489 |
|
| 490 |
b.set_input_text(".file-chooser-listing-header input", "fo") |
| 491 |
b.wait_visible(fc.file("foo")) |
| 492 |
b.wait_not_present(fc.file("bar")) |
| 493 |
b.wait_visible(fc.file("foobar")) |
| 494 |
b.assert_pixels(".file-chooser", "filtered") |
| 495 |
|
| 496 |
b.set_input_text(".file-chooser-listing-header input", "ba") |
| 497 |
b.wait_not_present(fc.file("foo")) |
| 498 |
b.wait_visible(fc.file("bar")) |
| 499 |
b.wait_visible(fc.file("foobar")) |
| 500 |
|
| 501 |
b.set_input_text(".file-chooser-listing-header input", "xxx") |
| 502 |
b.wait_in_text(".file-chooser-listing-body", "No matching results") |
| 503 |
b.click(".file-chooser-listing-body button:contains('Clear filters')") |
| 504 |
|
| 505 |
b.wait_visible(fc.file("bar")) |
| 506 |
b.wait_visible(fc.file("foo")) |
| 507 |
b.wait_visible(fc.file("foobar")) |
| 508 |
|
| 509 |
# Prepared filtering. |
| 510 |
|
| 511 |
# "No dots" was already active all the time, switch it off to |
| 512 |
# reveal more files. |
| 513 |
|
| 514 |
b.click(".file-chooser-listing-header button:contains('All files')") |
| 515 |
|
| 516 |
b.wait_visible(fc.file("bar")) |
| 517 |
b.wait_visible(fc.file("foo")) |
| 518 |
b.wait_visible(fc.file("foobar")) |
| 519 |
b.wait_visible(fc.file("dots.txt")) |
| 520 |
b.wait_visible(fc.file("only.dots")) |
| 521 |
|
| 522 |
b.mouse(fc.file("only.dots"), "dblclick") |
| 523 |
b.wait_visible(fc.file("one.dot")) |
| 524 |
b.wait_visible(fc.file("two.dots")) |
| 525 |
|
| 526 |
b.click(".file-chooser-listing-header button:contains('No dots')") |
| 527 |
|
| 528 |
b.wait_in_text(".file-chooser-listing-body", "No matching results") |
| 529 |
|
| 530 |
# Filter even more, this should get cleared as well |
| 531 |
b.set_input_text(".file-chooser-listing-header input", "x") |
| 532 |
|
| 533 |
b.click(".file-chooser-listing-body button:contains('Clear filters')") |
| 534 |
|
| 535 |
b.wait_visible(fc.file("one.dot")) |
| 536 |
b.wait_visible(fc.file("two.dots")) |
| 537 |
|
| 538 |
b.click(".file-chooser .pf-v6-c-modal-box__close button") |
| 539 |
b.wait_not_present(".file-chooser") |
| 540 |
|
| 541 |
# Test the collection |
| 542 |
|
| 543 |
b.click(d.field("file") + " .pf-v6-c-text-input-group__utilities button") |
| 544 |
b.click(fc.sidebar("Some files")) |
| 545 |
b.wait_visible(fc.file("foo")) |
| 546 |
b.wait_not_present(fc.file("dots.txt")) |
| 547 |
b.click(".file-chooser-listing-header button:contains('All files')") |
| 548 |
b.wait_visible(fc.file("foo")) |
| 549 |
b.wait_visible(fc.file("dots.txt")) |
| 550 |
b.click(fc.file("dots.txt")) |
| 551 |
b.click(fc.apply_button()) |
| 552 |
|
| 553 |
d.wait_FileChooserInput("file", "/var/lib/cockpittest/file-chooser-test/dots.txt") |
| 554 |
b.wait_in_text(d.helper_text("file"), "ASCII text") |
| 555 |
|
| 556 |
# Become superuser and access /root |
| 557 |
|
| 558 |
m.execute("echo Hello >~root/hello") # Not all images have ~root/.bashrc |
| 559 |
|
| 560 |
b.become_superuser() |
| 561 |
|
| 562 |
b.click(d.field("file") + " .pf-v6-c-text-input-group__utilities button") |
| 563 |
fc.set_path("/root/hello") |
| 564 |
b.click(fc.apply_button()) |
| 565 |
d.wait_FileChooserInput("file", "/root/hello") |
| 566 |
b.wait_in_text(d.helper_text("file"), "ASCII text") |
| 567 |
|
| 568 |
# Select a directory |
| 569 |
|
| 570 |
d.wait_FileChooserInput("dir", "") |
| 571 |
b.click(d.field("dir") + " .pf-v6-c-text-input-group__utilities button") |
| 572 |
|
| 573 |
b.wait_in_text(".file-chooser-listing-body", "No recent directories") |
| 574 |
b.click(fc.sidebar("Test files")) |
| 575 |
b.click(fc.file("file-chooser-test")) |
| 576 |
b.click(fc.apply_button()) |
| 577 |
|
| 578 |
d.wait_FileChooserInput("dir", test_files + "/file-chooser-test") |
| 579 |
|
| 580 |
b.click(d.field("dir") + " .pf-v6-c-text-input-group__utilities button") |
| 581 |
b.wait_visible(fc.file("only.dots")) |
| 582 |
b.click(fc.sidebar("Recent")) |
| 583 |
b.wait_visible(fc.file("file-chooser-test")) |
| 584 |
b.wait_not_present(fc.file("foo")) |
| 585 |
b.wait_in_text(fc.file("file-chooser-test"), test_files) |
| 586 |
|
| 587 |
b.wait_visible(fc.apply_button() + ":disabled") |
| 588 |
b.click(".file-chooser .pf-v6-c-modal-box__close button") |
| 589 |
b.wait_not_present(".file-chooser") |
| 590 |
|
| 591 |
# Check mobile layout |
| 592 |
|
| 593 |
b.set_layout("mobile") |
| 594 |
|
| 595 |
b.click(d.field("file") + " .pf-v6-c-text-input-group__utilities button") |
| 596 |
b.wait_not_visible(".file-chooser-sidebar") |
| 597 |
b.wait_visible(".file-chooser-kebab") |
| 598 |
|
| 599 |
b.select_PF(".file-chooser-kebab", "Test files") |
| 600 |
b.mouse(fc.file("file-chooser-test"), "dblclick") |
| 601 |
b.wait_visible(fc.file("empty")) |
| 602 |
|
| 603 |
b.click(".file-chooser .pf-v6-c-modal-box__close button") |
| 604 |
b.wait_not_present(".file-chooser") |
| 605 |
b.click(d.cancel_button()) |
| 606 |
b.set_layout("desktop") |
| 607 |
|
| 608 |
# Stand-alone File Chooser |
| 609 |
|
| 610 |
b.click("#open-file-chooser") |
| 611 |
b.wait_visible(".file-chooser") |
| 612 |
b.click(fc.sidebar("Some TXT files")) |
| 613 |
b.wait_visible(fc.file("foo.txt")) |
| 614 |
b.wait_not_present(fc.file("no-such-file.txt")) |
| 615 |
b.click(fc.file("foo.txt")) |
| 616 |
b.wait_text(fc.apply_button(), "Load") |
| 617 |
b.click(fc.apply_button()) |
| 618 |
b.wait_not_present(".file-chooser") |
| 619 |
|
| 620 |
b.click("#open-file-chooser") |
| 621 |
b.wait_visible(".file-chooser") |
| 622 |
b.click(fc.sidebar("Test files")) |
| 623 |
fc.set_path("file-chooser-test/text") |
| 624 |
b.wait_visible(fc.file("foo.txt")) |
| 625 |
b.wait_visible(fc.file("bar.txt")) |
| 626 |
b.click(fc.file("bar.txt")) |
| 627 |
b.click(fc.apply_button()) |
| 628 |
b.wait_in_text(fc.error(), "Does not start with \"foo\"") |
| 629 |
b.click(fc.file("foo.txt")) |
| 630 |
b.click(fc.apply_button()) |
| 631 |
b.wait_not_present(".file-chooser") |
| 632 |
|
| 633 |
|
| 634 |
if __name__ == '__main__': |
| 635 |
testlib.test_main() |