Add some FunctionalJavascript tests + fix JS error on inbox init

Created on 21 October 2024, about 1 month ago

Problem/Motivation

The module relies heavily on javascript but doesn't have tests for it, add some.
On top of testing functionality, it would catch any JS errors via \Drupal\FunctionalJavascriptTests\WebDriverTestBase::failOnJavaScriptErrors

Also, there is currently a JS error, breaking ajax, related to the inbox init :
{code}
TypeError: Cannot read properties of undefined (reading 'find')
at setActiveThread (/modules/contrib/private_message/js/private_message_inbox_block.js?sli8zh:109:15)
at Drupal.PrivateMessages.setActiveThread (/modules/contrib/private_message/js/private_message_inbox_block.js?sli8zh:219:11)
at Object.success (/modules/contrib/private_message/js/private_message_thread.js?sli8zh:248:36)
at c (/core/assets/vendor/jquery/jquery.min.js?v=3.7.1:2:25304)
at Object.fireWith [as resolveWith] (/core/assets/vendor/jquery/jquery.min.js?v=3.7.1:2:26053)
at l (/core/assets/vendor/jquery/jquery.min.js?v=3.7.1:2:77782)
at XMLHttpRequest. (/core/assets/vendor/jquery/jquery.min.js?v=3.7.1:2:80265) (WebDriver\Exception\JavaScriptError)
{code}

Steps to reproduce

Add the inbox block to the /private-messages page, check console.

Proposed resolution

It looks like commit "Fixing bug for private message inbox block, where Drupal.behaviors is firing before the block is loaded into the page" added a setTimeout on the inbox init, but this doesn't work properly because private_message_thread.js:248 calls Drupal.PrivateMessages.setActiveThread which is defined but the container var it uses/requires is not defined, until the inbox init gets executed.

I could not reproduce the scenario that the commit mentions, so I propose to revert it.
If this is reproductible in tests, then I suspect it could be fixed in another way than using setTimeout which causes issues.

Remaining tasks

?

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium herved

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024