mattermost-mobile-upstream/detox/e2e/support/ui/screen/thread_options.ts
cursor[bot] 87745da41a
Some checks are pending
ci / lint-typecheck (push) Waiting to run
ci / detox-lint-typecheck (push) Waiting to run
ci / android-unit-test (push) Waiting to run
ci / test (push) Waiting to run
fix(e2e): stabilize ABAC grant waits, post-logout login, and channel attributes reload on main (#10334)
* fix(e2e): converge ABAC decisions server-side before asserting the app's live update

The server can pin a stale render decision for 15 minutes: an evaluation that
runs while another request holds the attribute-view refresh lock reads the
pre-write view and caches that subject, and the later refresh does not drop it.
The app re-checked on the attribute event and ~33s later in every failing run,
so the 60s grant wait depended on the server converging in time.

- convergeDepartment writes the attribute, polls the server's decision as the
  user and re-writes the same value once per server refresh interval while the
  decision is still the old one
- MM-70693_2 / MM-68219_5 save the value once more after the server converged,
  so the app's live attribute-event path is checked against a known-good server
- beforeAll converges both users instead of a fixed 31s wait
- createChannelMember throws the server error instead of a TypeError

* fix(e2e): reach the login form from the server screen after logout instead of reloading

In all three MM-T3251 beforeAll timeouts (06d6c19, e3e8916, b8b7310) the app
landed on the server screen after logout, as SessionManager.onLogout routes it.
LoginScreen.login waited 10s for login.screen, then retryWithReload reloaded,
slept 10s and reconnected, pushing the 300s hook over budget.

- LoginScreen.reachLoginForm connects from the server screen when it is there
- AccountScreen.logout waits for the first of the logout-not-complete dialog or
  a logged-out screen instead of a fixed 10s probe
- optional probes (lingering logout dialog, Removed from team, scheduled-post
  tooltips) use isOptionalElementPresent: a passing not.toExist per check, so an
  absent element costs no failure payload (a failed 2s toBeVisible probe took
  47.5s in e3e8916), polled with synchronization off on iOS

* fix(e2e): stop pushing to the device right before reloadApp in the channel attributes DM test

MM-T6304_1 posted into the logged-in user's DM and then reloaded. On Android
shard 5 (4e2a508, e3e8916) the FCM push for that post landed 31ms and 6ms
before reactNativeReload, SQLite reported disk I/O error / database corruption,
the app came back blank and the remaining 7 tests of the spec failed. The DM is
listed without a post, so the test no longer creates one.

* fix(e2e): harden one-off setup and sheet races found in main E2E artifacts

- ABAC specs: createAbacChannel retries transient errors and throws the server
  error; the 9a4b375 redacted_files TypeError was an unchecked apiCreateChannel
- smoke messaging MM-T4786_6 and channel_bookmarks_permissions: check and retry
  the setup calls whose unchecked failures (9a4b375, 96a33da) broke every retry
- ThreadOptionsScreen.tapSheetRowIos re-taps only while the row still exists;
  e0f851d MM-T4808_1 re-tapped a row the closing sheet had removed
- MM-T5107_2 waits for the saved notify_props on the server before reopening
  the screen, which reads its values once at mount (4db91d8)

* fix(e2e): address review of the ABAC convergence and login/logout probes

- ABAC convergence fits the 300s test budget: one minute per in-test
  convergence (two in beforeAll), re-writes every 10s (every write already
  forces the next view refresh; the 15-minute subject cache is the gate), and
  logs converged/reasserts/elapsedMs so CI shows whether the server was stale
- convergeDepartment documents the server defect with a TODO; a failed login
  as the user throws its own error instead of reading as a stale decision
- allOrFirstError moves to the tested converge module
- AccountScreen.open checks the tooltip is visible before tapping, names the
  tooltip in the error, uses the ChannelScreen testIDs; JSDoc on open/logout
- isOptionalElementPresent logs the error it reads as present
- reachLoginForm takes the server to connect to, defaulting to Server 1

* fix(e2e): address CodeRabbit review on #10334

- MM-T6304_1 records the DM as opened (channel_open_time) so filterAutoclosedDMs
  keeps the post-less DM in the sidebar after the reload
- pollUntilConverged caps its sleep at the remaining budget, so nothing is
  found after the deadline
- isElementPresentNow reads only a failed expectation ("Test Failed:") as
  present and rethrows crashes and lost connections

* fix(e2e): address review: deadline before every poll pass, one iOS sync window for tooltip dismissal

- pollUntilConverged checks the deadline before every pass after the first, so
  a late timer or a long reassert can no longer report a state that appeared
  after the budget; a zero budget still makes exactly one pass. Tests cover a
  timer that overshoots the deadline and a reassert that runs past it.
- AccountScreen dismisses the scheduled-post tooltips as one
  withSynchronizationDisabled action on iOS (probe, visibility wait, tap and
  disappearance wait for both variants); Android unchanged.

* fix(e2e): do not report a state observed after the convergence deadline

Co-authored-by: mattermost-code <matty-code@mattermost.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: mattermost-code <matty-code@mattermost.com>
2026-11-18 12:32:28 +08:00

101 lines
4.5 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {isIos, isOptionalElementPresent, timeouts, wait, waitForElementToExist, waitForElementToNotExist, withSynchronizationDisabled} from '@support/utils';
import {expect, waitFor} from 'detox';
import {logDebug} from '../../../../provision/log';
class ThreadOptionsScreen {
testID = {
threadOptionsScreen: 'thread_options.screen',
replyThreadOption: 'post_options.reply_post.option',
followThreadOption: 'post_options.follow_thread.option',
followingThreadOption: 'post_options.following_thread.option',
openInChannelOption: 'thread_options.open_in_channel.option',
markAsReadOption: 'thread_options.mark_as_read.option',
markAsUnreadOption: 'thread_options.mark_as_unread.option',
saveThreadOption: 'post_options.Save_post.option',
unsaveThreadOption: 'post_options.Unsave_post.option',
copyLinkOption: 'post_options.copy_permalink.option',
};
threadOptionsScreen = element(by.id(this.testID.threadOptionsScreen));
replyThreadOption = element(by.id(this.testID.replyThreadOption));
followThreadOption = element(by.id(this.testID.followThreadOption));
followingThreadOption = element(by.id(this.testID.followingThreadOption));
openInChannelOption = element(by.id(this.testID.openInChannelOption));
markAsReadOption = element(by.id(this.testID.markAsReadOption));
markAsUnreadOption = element(by.id(this.testID.markAsUnreadOption));
saveThreadOption = element(by.id(this.testID.saveThreadOption));
unsaveThreadOption = element(by.id(this.testID.unsaveThreadOption));
copyLinkOption = element(by.id(this.testID.copyLinkOption));
toBeVisible = async () => {
await waitForElementToExist(this.threadOptionsScreen, timeouts.TEN_SEC);
return threadOptionsScreen;
};
close = async () => {
if (isIos()) {
await this.threadOptionsScreen.swipe('down');
} else {
await device.pressBack();
}
await wait(timeouts.ONE_SEC);
await expect(this.threadOptionsScreen).not.toBeVisible();
await wait(timeouts.ONE_SEC);
};
// Same gorhom+Reanimated path as PostOptionsScreen.tapSheetRowIos: center taps miss
// the Save row on iOS 26, and Detox sync never idles so waitFor cannot see dismiss.
// A tap that landed can still outlast the first wait on a loaded runner (one probe took
// 4.5s in e0f851d), so the row is tapped again only while it is still there; re-tapping a
// row the closing sheet already removed fails with "No elements found".
private tapSheetRowIos = async (option: Detox.NativeElement) => {
await withSynchronizationDisabled(async () => {
await waitForElementToExist(this.threadOptionsScreen, timeouts.TEN_SEC);
await waitForElementToExist(option, timeouts.TEN_SEC);
await option.tap({x: 1, y: 1});
try {
await waitForElementToNotExist(this.threadOptionsScreen, timeouts.FIVE_SEC);
return;
} catch (error) {
if (!(await isOptionalElementPresent(option))) {
await waitForElementToNotExist(this.threadOptionsScreen, timeouts.FIVE_SEC);
return;
}
logDebug(`ThreadOptionsScreen.tapSheetRowIos: sheet still open with the row, tapping again: ${(error as Error).message}`);
}
await option.tap({x: 1, y: 1});
await waitForElementToNotExist(this.threadOptionsScreen, timeouts.FIVE_SEC);
});
};
tapSaveThread = async () => {
if (isIos()) {
await this.tapSheetRowIos(this.saveThreadOption);
return;
}
await this.toBeVisible();
await waitFor(this.saveThreadOption).toExist().withTimeout(timeouts.FIVE_SEC);
await this.saveThreadOption.tap();
await waitFor(this.threadOptionsScreen).not.toExist().withTimeout(timeouts.TEN_SEC);
};
tapUnsaveThread = async () => {
if (isIos()) {
await this.tapSheetRowIos(this.unsaveThreadOption);
return;
}
await this.toBeVisible();
await waitFor(this.unsaveThreadOption).toExist().withTimeout(timeouts.FIVE_SEC);
await this.unsaveThreadOption.tap();
await waitFor(this.threadOptionsScreen).not.toExist().withTimeout(timeouts.TEN_SEC);
};
}
const threadOptionsScreen = new ThreadOptionsScreen();
export default threadOptionsScreen;