e2e: fix MM-T4054 media preview failure on Mattermost 11.10.0-rc2 - #3923
Conversation
Mattermost 11.10.0-rc2 (MM-69174) ignores thumbnail clicks until the real image has loaded and keeps a placeholder control visible meanwhile. MM-T4054 was clicking too early, so update the helper to wait for a visible loaded .file-preview__button and avoid placeholder targets. Co-authored-by: yasser khan <attitude3cena.yf@gmail.com>
The previous base64 PNG was rejected by Mattermost's image decoder, so no thumbnail/preview was generated. Combined with SizeAwareImage's load-gated clicks in 11.10+, MM-T4054 could never open the modal. Co-authored-by: yasser khan <attitude3cena.yf@gmail.com>
📝 WalkthroughWalkthroughThe Mattermost media preview E2E test replaces an invalid PNG fixture, waits for loaded image controls, expands preview selectors, adds fallback click targets, and extracts file IDs only from loaded non-placeholder images. ChangesMedia preview E2E flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
devinbinnie
left a comment
There was a problem hiding this comment.
Thank you @yasserfaraazkhan :)
There was a problem hiding this comment.
🧹 Nitpick comments (1)
e2e/specs/mattermost/media_preview.test.ts (1)
41-81: 📐 Maintainability & Code Quality | 🔵 TrivialDuplicate selector list/predicate logic across renderer scripts.
The legacy fallback selector string here (
.post-image img:not(.image-loading__placeholder), .post--attachment img:not(.image-loading__placeholder), img[src*="/api/v4/files/"]:not(.image-loading__placeholder)) is duplicated verbatim inopenImagePreview'sclickTargets(Lines 216-218), and the visible/loaded predicate logic here mirrors theisVisible/isLoadedImghelpers defined later inopenImagePreview. Since these are separately injected renderer scripts, consider extracting the shared selector strings/predicate bodies into module-level constants and interpolating them into both templates (similar to the${DOM_UTILS}pattern ine2e/helpers/serverView.ts), so future selector changes stay in sync.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@e2e/specs/mattermost/media_preview.test.ts` around lines 41 - 81, Extract the shared legacy image selector and visible/loaded image predicate logic used by waitForLoadedImagePreviewControl and openImagePreview into module-level reusable constants or script fragments, then interpolate them into both renderer templates using the existing DOM_UTILS-style pattern. Preserve the current selectors and behavior while ensuring future changes update both paths consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@e2e/specs/mattermost/media_preview.test.ts`:
- Around line 41-81: Extract the shared legacy image selector and visible/loaded
image predicate logic used by waitForLoadedImagePreviewControl and
openImagePreview into module-level reusable constants or script fragments, then
interpolate them into both renderer templates using the existing DOM_UTILS-style
pattern. Preserve the current selectors and behavior while ensuring future
changes update both paths consistently.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c7e2096e-680a-446c-a777-063548f4a581
📒 Files selected for processing (1)
e2e/specs/mattermost/media_preview.test.ts
Address CodeRabbit nitpick: extract loaded-image selectors and visible/loaded predicates into PREVIEW_IMAGE_UTILS so wait and click paths stay in sync. Co-authored-by: yasser khan <attitude3cena.yf@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@e2e/specs/mattermost/media_preview.test.ts`:
- Around line 68-85: In e2e/specs/mattermost/media_preview.test.ts:68-85, update
waitForLoadedImagePreviewControl to locate the post containing the expected
e2e-preview.png attachment and poll only that post’s loaded preview control; in
e2e/specs/mattermost/media_preview.test.ts:192-231, reuse the same
post/attachment identity and restrict fallback clicks to that attachment’s
loaded image, preserving deterministic waits and preventing unrelated posts from
satisfying readiness or being clicked.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 04345d4b-72f1-4259-8ea9-b6ea8a48562d
📒 Files selected for processing (1)
e2e/specs/mattermost/media_preview.test.ts
Address CodeRabbit feedback: locate the fixture attachment post by filename and only wait on / click that post's loaded preview control, so unrelated attachments cannot satisfy readiness. Co-authored-by: yasser khan <attitude3cena.yf@gmail.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
e2e/specs/mattermost/media_preview.test.ts (1)
197-241: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winFallback click targets don't verify the wrapped image is actually loaded.
For
HTMLImageElementtargets the filter correctly requiresisLoadedPreviewImage(loaded + visible). But for container targets (.post-image .image-loaded-container,.post-image .small-image__container,.post-image__image,.file-viewer-touch), the filter (Lines 228-229) only checks visibility plus the presence of a childimg:not(.image-loading__placeholder)— it never confirms that child image iscomplete/naturalWidth > 0. A container could pass while its inner image is still mid-load, which risks reintroducing the exact rc2 click-gating flakiness this PR is fixing, if this last-resort branch is ever reached.🐛 Proposed fix
if (target instanceof HTMLImageElement) { return isLoadedPreviewImage(target); } - return isPreviewControlVisible(target) && - Boolean(target.querySelector?.('img:not(.image-loading__placeholder)')); + return isPreviewControlVisible(target) && + isLoadedPreviewImage(target.querySelector?.('img:not(.image-loading__placeholder)')); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@e2e/specs/mattermost/media_preview.test.ts` around lines 197 - 241, Update the container-target branch in openImagePreview so it selects the wrapped image element and validates it with isLoadedPreviewImage, in addition to checking the container’s visibility. Preserve the existing direct HTMLImageElement validation and only allow fallback containers whose inner image is loaded and visible before clicking.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@e2e/specs/mattermost/media_preview.test.ts`:
- Around line 197-241: Update the container-target branch in openImagePreview so
it selects the wrapped image element and validates it with isLoadedPreviewImage,
in addition to checking the container’s visibility. Preserve the existing direct
HTMLImageElement validation and only allow fallback containers whose inner image
is loaded and visible before clicking.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 025db70b-9461-45ed-bbab-9b82d7df5968
📒 Files selected for processing (1)
e2e/specs/mattermost/media_preview.test.ts
) (cherry picked from commit d794838)
Summary
Fixes the hard E2E failure of MM-T4054 (
mattermost/media_preview) that started failing on master after CI moved from Mattermost11.10.0-rc1→11.10.0-rc2.This is not a regression from #3921 (destroyed-object guards). Evidence:
5e585bb6)11.10.0-rc111.10.0-rc2Root causes (both required):
png: invalid format: too much pixel data), so no preview/thumbnail was generated.SizeAwareImageignore clicks untilstate.loaded. On rc1, clicking still opened the modal even when the image failed to decode; on rc2 it does not.Changes in
e2e/specs/mattermost/media_preview.test.ts:has_preview_image: true)..file-preview__buttonbefore opening..image-loading__placeholder.MM-T5891 (Windows-only on the master run) passed on #3921’s own E2E and is treated as an unrelated flake; not changed here.
Ticket Link
N/A — follow-up to master E2E health after #3921 / server rc2 bump.
Checklist
npm run lint:jsfor proper code formattingE2E/RunDevice Information
This PR was tested on: Linux (Cloud VM), Mattermost
11.10.0-rc2local server, Playwright--project=linuxScreenshots
N/A (E2E-only). Local verification:
Release Note
Change Impact: 🟢 Low
Regression Risk: Limited to a single E2E test file, adjusting only test-side fixture validity and renderer DOM synchronization/click logic for the media preview modal; no production/shared modules are modified.
QA Recommendation: Rely on the existing automated E2E coverage; manual QA can be skipped.
Generated by CodeRabbitAI