Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: add drag events helper function #21296

Closed
wants to merge 1 commit into from

Conversation

tomasmatus
Copy link
Member

This enables to simulate drag events and allows to test drag&drop file upload in c-files in cockpit-project/cockpit-files#551

This enables to simulate drag events and allows to test drag&drop file
upload in c-files in cockpit-project/cockpit-files#551
@martinpitt
Copy link
Member

test/common/testlib.py:580: unused method 'drag' (60% confidence)

You need to add that to tools/vulture_suppressions/testlib.py. Note that you can add a temporary extra commit to the files PR to point the COCKPIT_REPO_COMMIT to this SHA, to prove that it works.

Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My recommendation is that this is currently too specific to be in testlib (hardcoded file contents, we don't want that approach for non-files DnD). How about for now you just keep this in that one c-files test case with b.eval_js()?

Thanks!

@@ -194,6 +194,33 @@ window.ph_mouse = function(sel, type, x, y, btn, ctrlKey, shiftKey, altKey, meta
throw new Error(sel + " is disabled or somehow doesn't process events");
};

window.ph_drag_event = function(sel, eventType, filename) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename that to drag_file_event() -- it is (or rather, should be) specific to dnd'ing files, not e.g. an object from/to within the page.

Comment on lines +201 to +202
if (el.offsetWidth <= 0 && el.offsetHeight <= 0 && el.tagName != 'svg')
throw new Error(sel + " is not visible");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please call ph_is_visible(). But moreover, don't call this at all here. testlib.py already calls wait_visible() on the selector, so this is redundant.

"""

self.wait_visible(selector)
return self.call_js_func('ph_drag_event', selector, dragType, filename)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really shouldn't use this "create direct Event objects" approach for generic DnD events. We found a lot of bugs when we moved Firefox tests to actual mouse clicks/moves/etc. I understand why we need it for that specific "file DnD" use case, though.

@tomasmatus
Copy link
Member Author

How about for now you just keep this in that one c-files test case with b.eval_js()?

yes I think this makes a lot of sense.

@tomasmatus tomasmatus closed this Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants