You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-31 13:44:28 +03:00
Don't reference the notification levels by colour (#12138)
* Don't reference the notification levels by colour We're about to change what colours they are so either we'd have to rename a bunch of constants. We may as well make things not reference what colour anything is in the actual UI. Hopefully these constants are clear enough. * Rename NotificationColor -> NotificationLevel * Red -> Highlight * Grey -> Notification * Bold -> Activity * Anywhere else that calls it 'color' -> 'level' Also fixes some weird mixes of US & UK English. It turns out this is referenced in... quite a lot of places, so this is quite a large PR. It can't really be much smaller, sorry. * One test rename & some hiding due to ts-ignore * More hiding behind ts-ignore * Damn you, @ts-ignore... * Fix test CSS values * Missed some colour -> level Co-authored-by: Florian Duros <florianduros@element.io> * Change other instances of variables renamed in suggestion * Update new test for renames --------- Co-authored-by: Florian Duros <florianduros@element.io>
This commit is contained in:
@ -34,7 +34,7 @@ import {
|
||||
getUnreadNotificationCount,
|
||||
determineUnreadState,
|
||||
} from "../src/RoomNotifs";
|
||||
import { NotificationColor } from "../src/stores/notifications/NotificationColor";
|
||||
import { NotificationLevel } from "../src/stores/notifications/NotificationLevel";
|
||||
import SettingsStore from "../src/settings/SettingsStore";
|
||||
import { MatrixClientPeg } from "../src/MatrixClientPeg";
|
||||
|
||||
@ -252,10 +252,10 @@ describe("RoomNotifs test", () => {
|
||||
});
|
||||
|
||||
it("shows nothing by default", async () => {
|
||||
const { color, symbol, count } = determineUnreadState(room);
|
||||
const { level, symbol, count } = determineUnreadState(room);
|
||||
|
||||
expect(symbol).toBe(null);
|
||||
expect(color).toBe(NotificationColor.None);
|
||||
expect(level).toBe(NotificationLevel.None);
|
||||
expect(count).toBe(0);
|
||||
});
|
||||
|
||||
@ -269,20 +269,20 @@ describe("RoomNotifs test", () => {
|
||||
event.status = EventStatus.NOT_SENT;
|
||||
room.addPendingEvent(event, "txn");
|
||||
|
||||
const { color, symbol, count } = determineUnreadState(room);
|
||||
const { level, symbol, count } = determineUnreadState(room);
|
||||
|
||||
expect(symbol).toBe("!");
|
||||
expect(color).toBe(NotificationColor.Unsent);
|
||||
expect(level).toBe(NotificationLevel.Unsent);
|
||||
expect(count).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("indicates the user has been invited to a channel", async () => {
|
||||
room.updateMyMembership("invite");
|
||||
|
||||
const { color, symbol, count } = determineUnreadState(room);
|
||||
const { level, symbol, count } = determineUnreadState(room);
|
||||
|
||||
expect(symbol).toBe("!");
|
||||
expect(color).toBe(NotificationColor.Red);
|
||||
expect(level).toBe(NotificationLevel.Highlight);
|
||||
expect(count).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
@ -294,10 +294,10 @@ describe("RoomNotifs test", () => {
|
||||
membership: "knock",
|
||||
});
|
||||
jest.spyOn(room, "getMember").mockReturnValue(roomMember);
|
||||
const { color, symbol, count } = determineUnreadState(room);
|
||||
const { level, symbol, count } = determineUnreadState(room);
|
||||
|
||||
expect(symbol).toBe("!");
|
||||
expect(color).toBe(NotificationColor.Red);
|
||||
expect(level).toBe(NotificationLevel.Highlight);
|
||||
expect(count).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
@ -306,27 +306,27 @@ describe("RoomNotifs test", () => {
|
||||
room.setUnreadNotificationCount(NotificationCountType.Total, 99);
|
||||
muteRoom(room);
|
||||
|
||||
const { color, count } = determineUnreadState(room);
|
||||
const { level, count } = determineUnreadState(room);
|
||||
|
||||
expect(color).toBe(NotificationColor.None);
|
||||
expect(level).toBe(NotificationLevel.None);
|
||||
expect(count).toBe(0);
|
||||
});
|
||||
|
||||
it("uses the correct number of unreads", async () => {
|
||||
room.setUnreadNotificationCount(NotificationCountType.Total, 999);
|
||||
|
||||
const { color, count } = determineUnreadState(room);
|
||||
const { level, count } = determineUnreadState(room);
|
||||
|
||||
expect(color).toBe(NotificationColor.Grey);
|
||||
expect(level).toBe(NotificationLevel.Notification);
|
||||
expect(count).toBe(999);
|
||||
});
|
||||
|
||||
it("uses the correct number of highlights", async () => {
|
||||
room.setUnreadNotificationCount(NotificationCountType.Highlight, 888);
|
||||
|
||||
const { color, count } = determineUnreadState(room);
|
||||
const { level, count } = determineUnreadState(room);
|
||||
|
||||
expect(color).toBe(NotificationColor.Red);
|
||||
expect(level).toBe(NotificationLevel.Highlight);
|
||||
expect(count).toBe(888);
|
||||
});
|
||||
});
|
||||
|
@ -56,7 +56,7 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () {
|
||||
return container.querySelector(".mx_RightPanel_threadsButton");
|
||||
}
|
||||
|
||||
function isIndicatorOfType(container: HTMLElement, type: "red" | "gray" | "bold") {
|
||||
function isIndicatorOfType(container: HTMLElement, type: "highlight" | "notification" | "activity") {
|
||||
return container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")!.className.includes(type);
|
||||
}
|
||||
|
||||
@ -85,10 +85,10 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () {
|
||||
|
||||
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Total, 1);
|
||||
expect(getThreadButton(container)!.className.includes("mx_LegacyRoomHeader_button--unread")).toBeTruthy();
|
||||
expect(isIndicatorOfType(container, "gray")).toBe(true);
|
||||
expect(isIndicatorOfType(container, "notification")).toBe(true);
|
||||
|
||||
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Highlight, 1);
|
||||
expect(isIndicatorOfType(container, "red")).toBe(true);
|
||||
expect(isIndicatorOfType(container, "highlight")).toBe(true);
|
||||
|
||||
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Total, 0);
|
||||
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Highlight, 0);
|
||||
@ -122,7 +122,7 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () {
|
||||
},
|
||||
});
|
||||
room.addReceipt(receipt);
|
||||
expect(isIndicatorOfType(container, "bold")).toBe(true);
|
||||
expect(isIndicatorOfType(container, "activity")).toBe(true);
|
||||
|
||||
// Sending the last event should clear the notification.
|
||||
let event = mkEvent({
|
||||
@ -158,7 +158,7 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () {
|
||||
},
|
||||
});
|
||||
room.addLiveEvents([event]);
|
||||
expect(isIndicatorOfType(container, "bold")).toBe(true);
|
||||
expect(isIndicatorOfType(container, "activity")).toBe(true);
|
||||
|
||||
// Sending a read receipt on an earlier event shouldn't do anything.
|
||||
receipt = new MatrixEvent({
|
||||
@ -173,7 +173,7 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () {
|
||||
},
|
||||
});
|
||||
room.addReceipt(receipt);
|
||||
expect(isIndicatorOfType(container, "bold")).toBe(true);
|
||||
expect(isIndicatorOfType(container, "activity")).toBe(true);
|
||||
|
||||
// Sending a receipt on the latest event should clear the notification.
|
||||
receipt = new MatrixEvent({
|
||||
|
@ -19,7 +19,7 @@ import React from "react";
|
||||
|
||||
import { StatelessNotificationBadge } from "../../../../../src/components/views/rooms/NotificationBadge/StatelessNotificationBadge";
|
||||
import SettingsStore from "../../../../../src/settings/SettingsStore";
|
||||
import { NotificationColor } from "../../../../../src/stores/notifications/NotificationColor";
|
||||
import { NotificationLevel } from "../../../../../src/stores/notifications/NotificationLevel";
|
||||
|
||||
describe("NotificationBadge", () => {
|
||||
describe("StatelessNotificationBadge", () => {
|
||||
@ -27,7 +27,7 @@ describe("NotificationBadge", () => {
|
||||
const cb = jest.fn();
|
||||
|
||||
const { getByRole } = render(
|
||||
<StatelessNotificationBadge symbol="" color={NotificationColor.Red} count={5} onClick={cb} />,
|
||||
<StatelessNotificationBadge symbol="" level={NotificationLevel.Highlight} count={5} onClick={cb} />,
|
||||
);
|
||||
|
||||
fireEvent.click(getByRole("button")!);
|
||||
@ -40,7 +40,7 @@ describe("NotificationBadge", () => {
|
||||
});
|
||||
|
||||
const { container } = render(
|
||||
<StatelessNotificationBadge symbol="" color={NotificationColor.Bold} count={1} />,
|
||||
<StatelessNotificationBadge symbol="" level={NotificationLevel.Activity} count={1} />,
|
||||
);
|
||||
|
||||
expect(container.firstChild).toBeNull();
|
||||
|
@ -18,19 +18,19 @@ import React from "react";
|
||||
import { render } from "@testing-library/react";
|
||||
|
||||
import { StatelessNotificationBadge } from "../../../../../src/components/views/rooms/NotificationBadge/StatelessNotificationBadge";
|
||||
import { NotificationColor } from "../../../../../src/stores/notifications/NotificationColor";
|
||||
import { NotificationLevel } from "../../../../../src/stores/notifications/NotificationLevel";
|
||||
|
||||
describe("StatelessNotificationBadge", () => {
|
||||
it("is highlighted when unsent", () => {
|
||||
const { container } = render(
|
||||
<StatelessNotificationBadge symbol="!" count={0} color={NotificationColor.Unsent} />,
|
||||
<StatelessNotificationBadge symbol="!" count={0} level={NotificationLevel.Unsent} />,
|
||||
);
|
||||
expect(container.querySelector(".mx_NotificationBadge_highlighted")).not.toBe(null);
|
||||
});
|
||||
|
||||
it("has knock style", () => {
|
||||
const { container } = render(
|
||||
<StatelessNotificationBadge symbol="!" count={0} color={NotificationColor.Red} knocked={true} />,
|
||||
<StatelessNotificationBadge symbol="!" count={0} level={NotificationLevel.Highlight} knocked={true} />,
|
||||
);
|
||||
expect(container.querySelector(".mx_NotificationBadge_dot")).not.toBeInTheDocument();
|
||||
expect(container.querySelector(".mx_NotificationBadge_knocked")).toBeInTheDocument();
|
||||
|
@ -25,7 +25,7 @@ import { SDKContext, SdkContextClass } from "../../../../../src/contexts/SDKCont
|
||||
import RightPanelStore from "../../../../../src/stores/right-panel/RightPanelStore";
|
||||
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../../test-utils";
|
||||
import { RoomNotificationState } from "../../../../../src/stores/notifications/RoomNotificationState";
|
||||
import { NotificationColor } from "../../../../../src/stores/notifications/NotificationColor";
|
||||
import { NotificationLevel } from "../../../../../src/stores/notifications/NotificationLevel";
|
||||
import { NotificationStateEvents } from "../../../../../src/stores/notifications/NotificationState";
|
||||
import { RightPanelPhases } from "../../../../../src/stores/right-panel/RightPanelStorePhases";
|
||||
|
||||
@ -46,11 +46,11 @@ describe("<VideoRoomChatButton />", () => {
|
||||
return room;
|
||||
};
|
||||
|
||||
const mockRoomNotificationState = (room: Room, color: NotificationColor): RoomNotificationState => {
|
||||
const mockRoomNotificationState = (room: Room, level: NotificationLevel): RoomNotificationState => {
|
||||
const roomNotificationState = new RoomNotificationState(room);
|
||||
|
||||
// @ts-ignore ugly mocking
|
||||
roomNotificationState._color = color;
|
||||
roomNotificationState._level = level;
|
||||
jest.spyOn(sdkContext.roomNotificationStateStore, "getRoomState").mockReturnValue(roomNotificationState);
|
||||
return roomNotificationState;
|
||||
};
|
||||
@ -105,7 +105,7 @@ describe("<VideoRoomChatButton />", () => {
|
||||
|
||||
it("renders button with an unread marker when room is unread", () => {
|
||||
const room = makeRoom();
|
||||
mockRoomNotificationState(room, NotificationColor.Bold);
|
||||
mockRoomNotificationState(room, NotificationLevel.Activity);
|
||||
getComponent(room);
|
||||
|
||||
// snapshot includes `data-indicator` attribute
|
||||
@ -116,14 +116,14 @@ describe("<VideoRoomChatButton />", () => {
|
||||
it("adds unread marker when room notification state changes to unread", () => {
|
||||
const room = makeRoom();
|
||||
// start in read state
|
||||
const notificationState = mockRoomNotificationState(room, NotificationColor.None);
|
||||
const notificationState = mockRoomNotificationState(room, NotificationLevel.None);
|
||||
getComponent(room);
|
||||
|
||||
// no unread marker
|
||||
expect(screen.getByLabelText("Chat").hasAttribute("data-indicator")).toBeFalsy();
|
||||
|
||||
// @ts-ignore ugly mocking
|
||||
notificationState._color = NotificationColor.Red;
|
||||
notificationState._level = NotificationLevel.Highlight;
|
||||
notificationState.emit(NotificationStateEvents.Update);
|
||||
|
||||
// unread marker
|
||||
@ -133,14 +133,14 @@ describe("<VideoRoomChatButton />", () => {
|
||||
it("clears unread marker when room notification state changes to read", () => {
|
||||
const room = makeRoom();
|
||||
// start in unread state
|
||||
const notificationState = mockRoomNotificationState(room, NotificationColor.Red);
|
||||
const notificationState = mockRoomNotificationState(room, NotificationLevel.Highlight);
|
||||
getComponent(room);
|
||||
|
||||
// unread marker
|
||||
expect(screen.getByLabelText("Chat").hasAttribute("data-indicator")).toBeTruthy();
|
||||
|
||||
// @ts-ignore ugly mocking
|
||||
notificationState._color = NotificationColor.None;
|
||||
notificationState._level = NotificationLevel.None;
|
||||
notificationState.emit(NotificationStateEvents.Update);
|
||||
|
||||
// unread marker cleared
|
||||
|
@ -26,7 +26,7 @@ import { SpaceButton } from "../../../../src/components/views/spaces/SpaceTreeLe
|
||||
import { MetaSpace, SpaceKey } from "../../../../src/stores/spaces";
|
||||
import SpaceStore from "../../../../src/stores/spaces/SpaceStore";
|
||||
import { StaticNotificationState } from "../../../../src/stores/notifications/StaticNotificationState";
|
||||
import { NotificationColor } from "../../../../src/stores/notifications/NotificationColor";
|
||||
import { NotificationLevel } from "../../../../src/stores/notifications/NotificationLevel";
|
||||
|
||||
jest.mock("../../../../src/stores/spaces/SpaceStore", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
@ -117,7 +117,7 @@ describe("SpaceButton", () => {
|
||||
});
|
||||
|
||||
it("should render notificationState if one is provided", () => {
|
||||
const notificationState = new StaticNotificationState(null, 8, NotificationColor.Grey);
|
||||
const notificationState = new StaticNotificationState(null, 8, NotificationLevel.Notification);
|
||||
|
||||
const { container, asFragment } = render(
|
||||
<SpaceButton
|
||||
|
@ -20,7 +20,7 @@ import { MatrixClient, NotificationCountType, Room } from "matrix-js-sdk/src/mat
|
||||
import { useRoomThreadNotifications } from "../../../src/hooks/room/useRoomThreadNotifications";
|
||||
import { stubClient } from "../../test-utils";
|
||||
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
||||
import { NotificationColor } from "../../../src/stores/notifications/NotificationColor";
|
||||
import { NotificationLevel } from "../../../src/stores/notifications/NotificationLevel";
|
||||
import { populateThread } from "../../test-utils/threads";
|
||||
|
||||
function render(room: Room) {
|
||||
@ -41,21 +41,21 @@ describe("useRoomThreadNotifications", () => {
|
||||
it("returns none if no thread in the room has notifications", async () => {
|
||||
const { result } = render(room);
|
||||
|
||||
expect(result.current).toBe(NotificationColor.None);
|
||||
expect(result.current).toBe(NotificationLevel.None);
|
||||
});
|
||||
|
||||
it("returns red if a thread in the room has a highlight notification", async () => {
|
||||
room.setThreadUnreadNotificationCount("flooble", NotificationCountType.Highlight, 1);
|
||||
const { result } = render(room);
|
||||
|
||||
expect(result.current).toBe(NotificationColor.Red);
|
||||
expect(result.current).toBe(NotificationLevel.Highlight);
|
||||
});
|
||||
|
||||
it("returns grey if a thread in the room has a normal notification", async () => {
|
||||
room.setThreadUnreadNotificationCount("flooble", NotificationCountType.Total, 1);
|
||||
const { result } = render(room);
|
||||
|
||||
expect(result.current).toBe(NotificationColor.Grey);
|
||||
expect(result.current).toBe(NotificationLevel.Notification);
|
||||
});
|
||||
|
||||
it("returns bold if a thread in the room unread messages", async () => {
|
||||
@ -68,6 +68,6 @@ describe("useRoomThreadNotifications", () => {
|
||||
|
||||
const { result } = render(room);
|
||||
|
||||
expect(result.current).toBe(NotificationColor.Bold);
|
||||
expect(result.current).toBe(NotificationLevel.Activity);
|
||||
});
|
||||
});
|
||||
|
@ -19,7 +19,7 @@ import { EventStatus, NotificationCountType, PendingEventOrdering, Room } from "
|
||||
|
||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { useUnreadNotifications } from "../../src/hooks/useUnreadNotifications";
|
||||
import { NotificationColor } from "../../src/stores/notifications/NotificationColor";
|
||||
import { NotificationLevel } from "../../src/stores/notifications/NotificationLevel";
|
||||
import { mkEvent, muteRoom, stubClient } from "../test-utils";
|
||||
|
||||
describe("useUnreadNotifications", () => {
|
||||
@ -40,10 +40,10 @@ describe("useUnreadNotifications", () => {
|
||||
|
||||
it("shows nothing by default", async () => {
|
||||
const { result } = renderHook(() => useUnreadNotifications(room));
|
||||
const { color, symbol, count } = result.current;
|
||||
const { level, symbol, count } = result.current;
|
||||
|
||||
expect(symbol).toBe(null);
|
||||
expect(color).toBe(NotificationColor.None);
|
||||
expect(level).toBe(NotificationLevel.None);
|
||||
expect(count).toBe(0);
|
||||
});
|
||||
|
||||
@ -58,10 +58,10 @@ describe("useUnreadNotifications", () => {
|
||||
room.addPendingEvent(event, "txn");
|
||||
|
||||
const { result } = renderHook(() => useUnreadNotifications(room));
|
||||
const { color, symbol, count } = result.current;
|
||||
const { level, symbol, count } = result.current;
|
||||
|
||||
expect(symbol).toBe("!");
|
||||
expect(color).toBe(NotificationColor.Unsent);
|
||||
expect(level).toBe(NotificationLevel.Unsent);
|
||||
expect(count).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
@ -69,10 +69,10 @@ describe("useUnreadNotifications", () => {
|
||||
room.updateMyMembership("invite");
|
||||
|
||||
const { result } = renderHook(() => useUnreadNotifications(room));
|
||||
const { color, symbol, count } = result.current;
|
||||
const { level, symbol, count } = result.current;
|
||||
|
||||
expect(symbol).toBe("!");
|
||||
expect(color).toBe(NotificationColor.Red);
|
||||
expect(level).toBe(NotificationLevel.Highlight);
|
||||
expect(count).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
@ -81,9 +81,9 @@ describe("useUnreadNotifications", () => {
|
||||
muteRoom(room);
|
||||
|
||||
const { result } = renderHook(() => useUnreadNotifications(room));
|
||||
const { color, count } = result.current;
|
||||
const { level, count } = result.current;
|
||||
|
||||
expect(color).toBe(NotificationColor.None);
|
||||
expect(level).toBe(NotificationLevel.None);
|
||||
expect(count).toBe(0);
|
||||
});
|
||||
|
||||
@ -91,9 +91,9 @@ describe("useUnreadNotifications", () => {
|
||||
setUnreads(999, 0);
|
||||
|
||||
const { result } = renderHook(() => useUnreadNotifications(room));
|
||||
const { color, count } = result.current;
|
||||
const { level, count } = result.current;
|
||||
|
||||
expect(color).toBe(NotificationColor.Grey);
|
||||
expect(level).toBe(NotificationLevel.Notification);
|
||||
expect(count).toBe(999);
|
||||
});
|
||||
|
||||
@ -101,9 +101,9 @@ describe("useUnreadNotifications", () => {
|
||||
setUnreads(0, 888);
|
||||
|
||||
const { result } = renderHook(() => useUnreadNotifications(room));
|
||||
const { color, count } = result.current;
|
||||
const { level, count } = result.current;
|
||||
|
||||
expect(color).toBe(NotificationColor.Red);
|
||||
expect(level).toBe(NotificationLevel.Highlight);
|
||||
expect(count).toBe(888);
|
||||
});
|
||||
});
|
||||
|
@ -46,7 +46,7 @@ import { MatrixClientPeg } from "../../src/MatrixClientPeg";
|
||||
import RoomListStore from "../../src/stores/room-list/RoomListStore";
|
||||
import { DefaultTagID } from "../../src/stores/room-list/models";
|
||||
import { RoomNotificationStateStore } from "../../src/stores/notifications/RoomNotificationStateStore";
|
||||
import { NotificationColor } from "../../src/stores/notifications/NotificationColor";
|
||||
import { NotificationLevel } from "../../src/stores/notifications/NotificationLevel";
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
@ -1467,7 +1467,7 @@ describe("SpaceStore", () => {
|
||||
const room = mkRoom(room1);
|
||||
const state = RoomNotificationStateStore.instance.getRoomState(room);
|
||||
// @ts-ignore
|
||||
state._color = NotificationColor.Grey;
|
||||
state._level = NotificationLevel.Notification;
|
||||
jest.spyOn(RoomListStore.instance, "orderedLists", "get").mockReturnValue({
|
||||
[DefaultTagID.Untagged]: [room],
|
||||
});
|
||||
|
@ -14,18 +14,18 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { humanReadableNotificationColor, NotificationColor } from "../../../src/stores/notifications/NotificationColor";
|
||||
import { humanReadableNotificationLevel, NotificationLevel } from "../../../src/stores/notifications/NotificationLevel";
|
||||
|
||||
describe("NotificationColor", () => {
|
||||
describe("humanReadableNotificationColor", () => {
|
||||
describe("NotificationLevel", () => {
|
||||
describe("humanReadableNotificationLevel", () => {
|
||||
it.each([
|
||||
[NotificationColor.None, "None"],
|
||||
[NotificationColor.Bold, "Bold"],
|
||||
[NotificationColor.Grey, "Grey"],
|
||||
[NotificationColor.Red, "Red"],
|
||||
[NotificationColor.Unsent, "Unsent"],
|
||||
[NotificationLevel.None, "None"],
|
||||
[NotificationLevel.Activity, "Activity"],
|
||||
[NotificationLevel.Notification, "Notification"],
|
||||
[NotificationLevel.Highlight, "Highlight"],
|
||||
[NotificationLevel.Unsent, "Unsent"],
|
||||
])("correctly maps the output", (color, output) => {
|
||||
expect(humanReadableNotificationColor(color)).toBe(output);
|
||||
expect(humanReadableNotificationLevel(color)).toBe(output);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -28,7 +28,7 @@ import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { mkEvent, muteRoom, stubClient } from "../../test-utils";
|
||||
import { RoomNotificationState } from "../../../src/stores/notifications/RoomNotificationState";
|
||||
import { NotificationStateEvents } from "../../../src/stores/notifications/NotificationState";
|
||||
import { NotificationColor } from "../../../src/stores/notifications/NotificationColor";
|
||||
import { NotificationLevel } from "../../../src/stores/notifications/NotificationLevel";
|
||||
import { createMessageEventContent } from "../../test-utils/events";
|
||||
|
||||
describe("RoomNotificationState", () => {
|
||||
@ -109,7 +109,7 @@ describe("RoomNotificationState", () => {
|
||||
event.status = EventStatus.NOT_SENT;
|
||||
room.addPendingEvent(event, "txn");
|
||||
|
||||
expect(roomNotifState.color).toBe(NotificationColor.Unsent);
|
||||
expect(roomNotifState.level).toBe(NotificationLevel.Unsent);
|
||||
expect(roomNotifState.symbol).toBe("!");
|
||||
expect(roomNotifState.count).toBeGreaterThan(0);
|
||||
});
|
||||
@ -121,7 +121,7 @@ describe("RoomNotificationState", () => {
|
||||
setUnreads(room, 1234, 0);
|
||||
room.updateMyMembership("join"); // emit
|
||||
|
||||
expect(roomNotifState.color).toBe(NotificationColor.None);
|
||||
expect(roomNotifState.level).toBe(NotificationLevel.None);
|
||||
expect(roomNotifState.symbol).toBe(null);
|
||||
expect(roomNotifState.count).toBe(0);
|
||||
});
|
||||
@ -131,7 +131,7 @@ describe("RoomNotificationState", () => {
|
||||
|
||||
room.updateMyMembership("invite"); // emit
|
||||
|
||||
expect(roomNotifState.color).toBe(NotificationColor.Red);
|
||||
expect(roomNotifState.level).toBe(NotificationLevel.Highlight);
|
||||
expect(roomNotifState.symbol).toBe("!");
|
||||
expect(roomNotifState.count).toBeGreaterThan(0);
|
||||
});
|
||||
@ -142,7 +142,7 @@ describe("RoomNotificationState", () => {
|
||||
setUnreads(room, 4321, 0);
|
||||
room.updateMyMembership("join"); // emit
|
||||
|
||||
expect(roomNotifState.color).toBe(NotificationColor.Grey);
|
||||
expect(roomNotifState.level).toBe(NotificationLevel.Notification);
|
||||
expect(roomNotifState.symbol).toBe(null);
|
||||
expect(roomNotifState.count).toBe(4321);
|
||||
});
|
||||
@ -153,7 +153,7 @@ describe("RoomNotificationState", () => {
|
||||
setUnreads(room, 0, 69);
|
||||
room.updateMyMembership("join"); // emit
|
||||
|
||||
expect(roomNotifState.color).toBe(NotificationColor.Red);
|
||||
expect(roomNotifState.level).toBe(NotificationLevel.Highlight);
|
||||
expect(roomNotifState.symbol).toBe(null);
|
||||
expect(roomNotifState.count).toBe(69);
|
||||
});
|
||||
@ -173,7 +173,7 @@ describe("RoomNotificationState", () => {
|
||||
addThread(room);
|
||||
room.updateMyMembership("join"); // emit
|
||||
|
||||
expect(roomNotifState.color).toBe(NotificationColor.Bold);
|
||||
expect(roomNotifState.level).toBe(NotificationLevel.Activity);
|
||||
expect(roomNotifState.symbol).toBe(null);
|
||||
});
|
||||
});
|
||||
|
@ -22,7 +22,7 @@ import { ImportanceAlgorithm } from "../../../../../src/stores/room-list/algorit
|
||||
import { SortAlgorithm } from "../../../../../src/stores/room-list/algorithms/models";
|
||||
import * as RoomNotifs from "../../../../../src/RoomNotifs";
|
||||
import { DefaultTagID, RoomUpdateCause } from "../../../../../src/stores/room-list/models";
|
||||
import { NotificationColor } from "../../../../../src/stores/notifications/NotificationColor";
|
||||
import { NotificationLevel } from "../../../../../src/stores/notifications/NotificationLevel";
|
||||
import { AlphabeticAlgorithm } from "../../../../../src/stores/room-list/algorithms/tag-sorting/AlphabeticAlgorithm";
|
||||
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../../test-utils";
|
||||
import { RecentAlgorithm } from "../../../../../src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm";
|
||||
@ -75,16 +75,16 @@ describe("ImportanceAlgorithm", () => {
|
||||
};
|
||||
|
||||
const unreadStates: Record<string, ReturnType<(typeof RoomNotifs)["determineUnreadState"]>> = {
|
||||
red: { symbol: null, count: 1, color: NotificationColor.Red },
|
||||
grey: { symbol: null, count: 1, color: NotificationColor.Grey },
|
||||
none: { symbol: null, count: 0, color: NotificationColor.None },
|
||||
red: { symbol: null, count: 1, level: NotificationLevel.Highlight },
|
||||
grey: { symbol: null, count: 1, level: NotificationLevel.Notification },
|
||||
none: { symbol: null, count: 0, level: NotificationLevel.None },
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(RoomNotifs, "determineUnreadState").mockReturnValue({
|
||||
symbol: null,
|
||||
count: 0,
|
||||
color: NotificationColor.None,
|
||||
level: NotificationLevel.None,
|
||||
});
|
||||
});
|
||||
|
||||
@ -190,7 +190,7 @@ describe("ImportanceAlgorithm", () => {
|
||||
jest.spyOn(RoomNotifs, "determineUnreadState").mockReturnValue({
|
||||
symbol: null,
|
||||
count: 0,
|
||||
color: NotificationColor.None,
|
||||
level: NotificationLevel.None,
|
||||
});
|
||||
const algorithm = setupAlgorithm(sortAlgorithm);
|
||||
|
||||
@ -360,7 +360,7 @@ describe("ImportanceAlgorithm", () => {
|
||||
jest.spyOn(RoomNotifs, "determineUnreadState").mockReturnValue({
|
||||
symbol: null,
|
||||
count: 0,
|
||||
color: NotificationColor.None,
|
||||
level: NotificationLevel.None,
|
||||
});
|
||||
const algorithm = setupAlgorithm(sortAlgorithm);
|
||||
|
||||
|
@ -26,7 +26,7 @@ import { RoomNotificationStateStore } from "../../../../../src/stores/notificati
|
||||
import * as RoomNotifs from "../../../../../src/RoomNotifs";
|
||||
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../../test-utils";
|
||||
import { DEFAULT_PUSH_RULES, makePushRule } from "../../../../test-utils/pushRules";
|
||||
import { NotificationColor } from "../../../../../src/stores/notifications/NotificationColor";
|
||||
import { NotificationLevel } from "../../../../../src/stores/notifications/NotificationLevel";
|
||||
|
||||
describe("NaturalAlgorithm", () => {
|
||||
const userId = "@alice:server.org";
|
||||
@ -197,7 +197,7 @@ describe("NaturalAlgorithm", () => {
|
||||
jest.spyOn(RoomNotifs, "determineUnreadState").mockReturnValue({
|
||||
symbol: null,
|
||||
count: 0,
|
||||
color: NotificationColor.None,
|
||||
level: NotificationLevel.None,
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user