FIX: long press chat message test failure (#23791)

This commit brings two fixes.

- increase the delay to trigger the action menu

- check of user activation before using vibrate:

https://developer.mozilla.org/en-US/docs/Glossary/Sticky_activation
https://developer.mozilla.org/en-US/docs/Web/Security/User_activation
https://developer.mozilla.org/en-US/docs/Web/API/UserActivation/hasBeenActive

> Sticky activation is a window state that indicates a user has pressed a button, moved a mouse, used a menu, or performed some other user interaction. It is not reset after it has been set initially (unlike transient activation).
> APIs that require sticky activation (not exhaustive):
> - Navigator.vibrate()
> - VirtualKeyboard.show()
> - Autoplay of Media and Web Audio APIs (in particular for AudioContexts).


Before this fix, we could end up with this error in the console in tests:

> Blocked call to navigator.vibrate because user hasn't tapped on the frame or any embedded 

<!-- NOTE: All pull requests should have tests (rspec in Ruby, qunit in JavaScript). If your code does not include test coverage, please include an explanation of why it was omitted. -->
This commit is contained in:
Joffrey JAFFEUX 2023-10-05 10:16:13 +02:00 committed by GitHub
parent bfe078c520
commit 6cd4b8de6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 4 deletions

View File

@ -30,7 +30,12 @@ function calculateCapabilities() {
capabilities.hasContactPicker =
"contacts" in navigator && "ContactsManager" in window;
capabilities.canVibrate = "vibrate" in navigator;
capabilities.canVibrate =
"vibrate" in navigator &&
(!("userActivation" in navigator) ||
navigator.userActivation.hasBeenActive);
capabilities.isPwa =
window.matchMedia("(display-mode: standalone)").matches ||
window.navigator.standalone ||

View File

@ -32,7 +32,6 @@ RSpec.describe "Chat message - channel", type: :system do
it "[mobile] copies the text of a single message", mobile: true do
chat_page.visit_channel(channel_1)
channel_page.click_composer # ensures we don't block on vibrate due to no action
channel_page.messages.copy_text(message_1)

View File

@ -35,7 +35,6 @@ RSpec.describe "Chat message - thread", type: :system do
it "[mobile] copies the text of a single message", mobile: true do
chat_page.visit_thread(thread_message_1.thread)
thread_page.click_composer # ensures we don't block on vibrate due to no action
thread_page.messages.copy_text(thread_message_1)

View File

@ -53,7 +53,7 @@ module PageObjects
end
if page.has_css?("html.mobile-view", wait: 0)
component.click(delay: 0.4)
component.click(delay: 0.6)
page.find(".chat-message-actions [data-id=\"select\"]").click
else
hover