Repository navigation
test(e2e): Mattermost webapp interaction, channel UI, and downloads #3857
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
db20b56
E2E: Playwright harness, fixtures, and CI wiring (1/10).
yasserfaraazkhan f46ebbc
E2E: Main-process test hooks and shared launch helpers (2/10).
yasserfaraazkhan 4c86fea
E2E: Mattermost shell helpers and bookmarks/custom groups specs (3/10).
yasserfaraazkhan a2f373b
Merge origin/master into e2e/03-mattermost-shell
yasserfaraazkhan 17086f2
Address CodeRabbit review on mattermost shell E2E helpers
yasserfaraazkhan fd75868
E2E: Channel menu helper and Mattermost UI specs (#3858)
yasserfaraazkhan 0922144
E2E: Downloads coverage (#3859)
yasserfaraazkhan 5670666
Address CodeRabbit review on mattermost E2E helpers and specs.
yasserfaraazkhan e81d4dd
Fix cancelled E2E status checks and add E2E/Override label support.
yasserfaraazkhan 6d81908
Address CodeRabbit review on downloads E2E helpers and specs.
yasserfaraazkhan 19b915b
Scope E2E workflow cancellation to the triggering PR branch.
yasserfaraazkhan f7aa85b
Harden bad-server and drag-and-drop E2E specs against real load failu…
yasserfaraazkhan b64f379
fix coderabbit comments
yasserfaraazkhan 7d492f2
Restore pull-requests:write for E2E label jobs.
yasserfaraazkhan 48d392f
fix coderabbit comments
yasserfaraazkhan eab67d9
fix ci
yasserfaraazkhan e560f83
fix(e2e): tighten TLS error match, clean up created teams, drop dead …
yasserfaraazkhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,299 @@ | ||
| // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. | ||
| // See LICENSE.txt for license information. | ||
|
|
||
| import {expect} from '@playwright/test'; | ||
|
|
||
| import type {ServerView} from './serverView'; | ||
|
|
||
| export const POST_TEXTBOX_SELECTOR = [ | ||
| '#post_textbox', | ||
| '[data-testid="post_textbox"]', | ||
| '.post-create__input [contenteditable="true"]', | ||
| '[role="textbox"]', | ||
| ].join(', '); | ||
|
|
||
| /** | ||
| * Wait until the Mattermost webapp shell is interactive in a server view. | ||
| */ | ||
| export async function waitForMattermostShell( | ||
| win: ServerView, | ||
| options?: {channelItem?: string; timeout?: number}, | ||
| ) { | ||
| const channelItem = options?.channelItem ?? '#sidebarItem_town-square'; | ||
| const timeout = options?.timeout ?? 60_000; | ||
|
|
||
| await expect.poll(async () => { | ||
| try { | ||
| await win.waitForSelector(channelItem, {timeout: 2_000}); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| }, {timeout, message: `Mattermost shell must expose ${channelItem}`}).toBe(true); | ||
| } | ||
|
|
||
| /** | ||
| * Reload the server view when the channel shell failed to mount (blank hex background). | ||
| */ | ||
| export async function recoverServerViewIfNeeded( | ||
| win: ServerView, | ||
| options?: {channelItem?: string}, | ||
| ) { | ||
| const channelItem = options?.channelItem ?? '#sidebarItem_town-square'; | ||
| const healthy = await win.runInRenderer(` | ||
| return Boolean( | ||
| document.querySelector('#channelHeaderTitle') | ||
| && document.querySelector(${JSON.stringify(channelItem)}), | ||
| ); | ||
| `).catch(() => false); | ||
|
|
||
| if (healthy) { | ||
| return; | ||
| } | ||
|
|
||
| await win.runInRenderer('window.location.reload(); return true;', true); | ||
| await waitForMattermostShell(win, {channelItem}); | ||
| } | ||
|
|
||
| /** | ||
| * Type into the post textbox, preferring DOM insertion so Slate keeps text nodes. | ||
| */ | ||
| export async function typeIntoPostTextbox(win: ServerView, text: string): Promise<void> { | ||
| await win.waitForSelector(POST_TEXTBOX_SELECTOR, {timeout: 10_000}); | ||
| await win.click(POST_TEXTBOX_SELECTOR); | ||
|
|
||
| const inserted = await win.runInRenderer(` | ||
| const value = ${JSON.stringify(text)}; | ||
|
|
||
| const isVisible = (element) => { | ||
| if (!element || !element.isConnected) { | ||
| return false; | ||
| } | ||
| const style = window.getComputedStyle(element); | ||
| if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0') { | ||
| return false; | ||
| } | ||
| const rect = element.getBoundingClientRect(); | ||
| return rect.width > 0 && rect.height > 0; | ||
| }; | ||
|
|
||
| const candidates = [ | ||
| document.querySelector('[data-slate-editor="true"]'), | ||
| document.querySelector('#post_textbox[contenteditable="true"]'), | ||
| document.querySelector('[data-testid="post_textbox"][contenteditable="true"]'), | ||
| document.querySelector('#post_textbox'), | ||
| document.querySelector('[data-testid="post_textbox"]'), | ||
| document.querySelector('.post-create__input [contenteditable="true"]'), | ||
| document.querySelector('textarea#post_textbox'), | ||
| ].filter(Boolean); | ||
|
|
||
| let root = null; | ||
| for (const candidate of candidates) { | ||
| if (!isVisible(candidate)) { | ||
| continue; | ||
| } | ||
| if (candidate.matches('[contenteditable="true"], textarea, input')) { | ||
| root = candidate; | ||
| break; | ||
| } | ||
| const nested = candidate.querySelector('[contenteditable="true"], textarea, input'); | ||
| if (nested && isVisible(nested)) { | ||
| root = nested; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!root) { | ||
| return false; | ||
| } | ||
|
|
||
| root.focus?.(); | ||
| root.setAttribute('spellcheck', 'true'); | ||
|
|
||
| if (root instanceof HTMLTextAreaElement || root instanceof HTMLInputElement) { | ||
| root.value = value; | ||
| root.dispatchEvent(new Event('input', {bubbles: true})); | ||
| return root.value.includes(value.slice(0, 8)); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| const selection = window.getSelection(); | ||
| selection?.removeAllRanges(); | ||
| document.execCommand('selectAll', false); | ||
| document.execCommand('delete', false); | ||
| const insertedText = document.execCommand('insertText', false, value); | ||
| root.dispatchEvent(new InputEvent('input', {bubbles: true, data: value, inputType: 'insertText'})); | ||
| const content = root.innerText || root.textContent || ''; | ||
| return insertedText && content.includes(value.slice(0, 8)); | ||
| `, true); | ||
|
|
||
| if (!inserted) { | ||
| const mod = process.platform === 'darwin' ? 'Meta' : 'Control'; | ||
| await win.keyboard.press(`${mod}+A`); | ||
| await win.keyboard.press('Backspace'); | ||
| await win.keyboard.type(text); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Select a word in the post textbox and return viewport coordinates for it. | ||
| * Native spell-check menus require the right-click to land on misspelled text. | ||
| */ | ||
| export async function getPostTextboxWordPoint( | ||
| win: ServerView, | ||
| word: string, | ||
| ): Promise<{x: number; y: number} | null> { | ||
| return win.runInRenderer(` | ||
| const target = ${JSON.stringify(word)}; | ||
|
|
||
| const isVisible = (element) => { | ||
| if (!element || !element.isConnected) { | ||
| return false; | ||
| } | ||
| const style = window.getComputedStyle(element); | ||
| if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0') { | ||
| return false; | ||
| } | ||
| const rect = element.getBoundingClientRect(); | ||
| return rect.width > 0 && rect.height > 0; | ||
| }; | ||
|
|
||
| const resolveEditor = () => { | ||
| const candidates = [ | ||
| document.querySelector('[data-slate-editor="true"]'), | ||
| document.querySelector('#post_textbox[contenteditable="true"]'), | ||
| document.querySelector('[data-testid="post_textbox"][contenteditable="true"]'), | ||
| document.querySelector('#post_textbox'), | ||
| document.querySelector('[data-testid="post_textbox"]'), | ||
| document.querySelector('.post-create__input [contenteditable="true"]'), | ||
| document.querySelector('.AdvancedTextEditor [contenteditable="true"]'), | ||
| document.querySelector('[role="textbox"][contenteditable="true"]'), | ||
| document.querySelector('textarea#post_textbox'), | ||
| ].filter(Boolean); | ||
|
|
||
| for (const candidate of candidates) { | ||
| if (!isVisible(candidate)) { | ||
| continue; | ||
| } | ||
| if (candidate.matches('[contenteditable="true"], textarea, input')) { | ||
| return candidate; | ||
| } | ||
| const nested = candidate.querySelector('[contenteditable="true"], textarea, input'); | ||
| if (nested && isVisible(nested)) { | ||
| return nested; | ||
| } | ||
| } | ||
| return null; | ||
| }; | ||
|
|
||
| const getTextareaWordPoint = (textarea, needle) => { | ||
| const text = textarea.value || ''; | ||
| const index = text.indexOf(needle); | ||
| if (index < 0) { | ||
| return null; | ||
| } | ||
|
|
||
| textarea.focus(); | ||
| textarea.setSelectionRange(index, index + needle.length); | ||
|
|
||
| const mirror = document.createElement('div'); | ||
| const properties = [ | ||
| 'direction', 'boxSizing', 'width', 'height', 'overflowX', 'overflowY', | ||
| 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', | ||
| 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', | ||
| 'fontStyle', 'fontVariant', 'fontWeight', 'fontStretch', 'fontSize', | ||
| 'fontSizeAdjust', 'lineHeight', 'fontFamily', 'textAlign', 'textTransform', | ||
| 'textIndent', 'textDecoration', 'letterSpacing', 'wordSpacing', 'whiteSpace', | ||
| ]; | ||
| const computed = window.getComputedStyle(textarea); | ||
| mirror.style.position = 'absolute'; | ||
| mirror.style.visibility = 'hidden'; | ||
| mirror.style.top = '0'; | ||
| mirror.style.left = '0'; | ||
| mirror.style.whiteSpace = 'pre-wrap'; | ||
| mirror.style.wordWrap = 'break-word'; | ||
| for (const property of properties) { | ||
| mirror.style[property] = computed[property]; | ||
| } | ||
| mirror.style.width = computed.width; | ||
| mirror.textContent = text.slice(0, index); | ||
| const marker = document.createElement('span'); | ||
| marker.textContent = text.slice(index, index + needle.length) || '.'; | ||
| mirror.appendChild(marker); | ||
| document.body.appendChild(mirror); | ||
| const mirrorRect = mirror.getBoundingClientRect(); | ||
| const markerRect = marker.getBoundingClientRect(); | ||
| const textareaRect = textarea.getBoundingClientRect(); | ||
| document.body.removeChild(mirror); | ||
|
|
||
| // markerRect is relative to the mirror (anchored at 0,0 in body coords), | ||
| // so (markerRect - mirrorRect) gives the offset inside the mirror. Add that | ||
| // to the textarea's viewport position and subtract scroll for the final point. | ||
| return { | ||
| x: Math.round( | ||
| textareaRect.left + (markerRect.left - mirrorRect.left) - textarea.scrollLeft, | ||
| ), | ||
| y: Math.round( | ||
| textareaRect.top + (markerRect.top - mirrorRect.top) - textarea.scrollTop + (markerRect.height / 2), | ||
| ), | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| }; | ||
| }; | ||
|
|
||
| const findRangeInRoot = (root, needle) => { | ||
| const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT); | ||
| let node = walker.nextNode(); | ||
| while (node) { | ||
| const text = node.textContent || ''; | ||
| const index = text.indexOf(needle); | ||
| if (index >= 0) { | ||
| const range = document.createRange(); | ||
| range.setStart(node, index); | ||
| range.setEnd(node, index + needle.length); | ||
| const rect = range.getBoundingClientRect(); | ||
| if (rect.width > 0 && rect.height > 0) { | ||
| return {range, rect}; | ||
| } | ||
| } | ||
| node = walker.nextNode(); | ||
| } | ||
| return null; | ||
| }; | ||
|
|
||
| const root = resolveEditor(); | ||
| if (!root) { | ||
| return null; | ||
| } | ||
|
|
||
| root.setAttribute('spellcheck', 'true'); | ||
|
|
||
| if (root instanceof HTMLTextAreaElement || root instanceof HTMLInputElement) { | ||
| return getTextareaWordPoint(root, target); | ||
| } | ||
|
|
||
| const match = findRangeInRoot(root, target); | ||
| if (!match) { | ||
| const fullText = root.innerText || root.textContent || ''; | ||
| const index = fullText.indexOf(target); | ||
| if (index < 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const rect = root.getBoundingClientRect(); | ||
| const ratio = (index + (target.length / 2)) / Math.max(fullText.length, 1); | ||
| root.focus?.(); | ||
| return { | ||
| x: Math.round(rect.left + Math.min(rect.width * ratio, Math.max(rect.width - 8, 8))), | ||
| y: Math.round(rect.top + Math.max(rect.height * 0.7, 20)), | ||
| }; | ||
| } | ||
|
|
||
| const selection = window.getSelection(); | ||
| selection?.removeAllRanges(); | ||
| selection?.addRange(match.range); | ||
| root.focus?.(); | ||
|
|
||
| return { | ||
| x: Math.round(match.rect.left + (match.rect.width / 2)), | ||
| y: Math.round(match.rect.top + (match.rect.height / 2)), | ||
| }; | ||
| `, true); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.