Skip to content

Commit ccf0762

Browse files
authored
Don't show release announcements while toasts are displayed (#30770)
* Don't show release announcements while toasts are displayed Otherwise they can clash and look like a mess. * Dismiss the toast in the e2e test * Update screenshot
1 parent 4dc087c commit ccf0762

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

playwright/e2e/release-announcement/releaseAnnouncement.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ test.describe("Release announcement", () => {
2929
"should display the new room list release announcement",
3030
{ tag: "@screenshot" },
3131
async ({ page, app, room, util }) => {
32+
// dismiss the toast so the announcement appears
33+
await page.getByRole("button", { name: "Dismiss" }).click();
34+
3235
const name = "Chats has a new look!";
3336

3437
// The release announcement should be displayed
-7.92 KB
Loading

src/stores/ReleaseAnnouncementStore.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { cloneDeep } from "lodash";
1313
import SettingsStore from "../settings/SettingsStore";
1414
import { SettingLevel } from "../settings/SettingLevel";
1515
import { Features } from "../settings/Settings";
16+
import ToastStore from "./ToastStore";
1617

1718
/**
1819
* The features are shown in the array order.
@@ -76,6 +77,9 @@ export class ReleaseAnnouncementStore extends TypedEventEmitter<ReleaseAnnouncem
7677
SettingsStore.watchSetting("releaseAnnouncementData", null, () => {
7778
this.emit("releaseAnnouncementChanged", this.getReleaseAnnouncement());
7879
});
80+
ToastStore.sharedInstance().on("update", () => {
81+
this.emit("releaseAnnouncementChanged", this.getReleaseAnnouncement());
82+
});
7983
}
8084

8185
/**
@@ -104,6 +108,9 @@ export class ReleaseAnnouncementStore extends TypedEventEmitter<ReleaseAnnouncem
104108
const isReleaseAnnouncementEnabled = this.isReleaseAnnouncementEnabled();
105109
if (!isReleaseAnnouncementEnabled) return null;
106110

111+
// also don't show release announcements if any toasts are on screen
112+
if (ToastStore.sharedInstance().getToasts().length > 0) return null;
113+
107114
const viewedReleaseAnnouncements = this.getViewedReleaseAnnouncements();
108115

109116
// Find the first feature that has not been viewed

test/unit-tests/stores/ReleaseAnnouncementStore-test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import { mocked } from "jest-mock";
1111
import SettingsStore, { type CallbackFn } from "../../../src/settings/SettingsStore";
1212
import { type Feature, ReleaseAnnouncementStore } from "../../../src/stores/ReleaseAnnouncementStore";
1313
import { type SettingLevel } from "../../../src/settings/SettingLevel";
14+
import ToastStore from "../../../src/stores/ToastStore";
1415

1516
jest.mock("../../../src/settings/SettingsStore");
17+
jest.mock("../../../src/stores/ToastStore");
1618

1719
describe("ReleaseAnnouncementStore", () => {
1820
let releaseAnnouncementStore: ReleaseAnnouncementStore;
@@ -48,6 +50,11 @@ describe("ReleaseAnnouncementStore", () => {
4850
return "watcherId";
4951
});
5052

53+
mocked(ToastStore.sharedInstance).mockReturnValue({
54+
on: jest.fn(),
55+
getToasts: jest.fn().mockReturnValue([]),
56+
} as any);
57+
5158
releaseAnnouncementStore = new ReleaseAnnouncementStore();
5259
});
5360

@@ -118,4 +125,10 @@ describe("ReleaseAnnouncementStore", () => {
118125
expect(await promise).toBe("newRoomList_sort");
119126
expect(releaseAnnouncementStore.getReleaseAnnouncement()).toBe("newRoomList_sort");
120127
});
128+
129+
it("should return null when there are toasts on screen", async () => {
130+
mocked(ToastStore.sharedInstance().getToasts).mockReturnValue([{} as any]);
131+
132+
expect(releaseAnnouncementStore.getReleaseAnnouncement()).toBeNull();
133+
});
121134
});

0 commit comments

Comments
 (0)