Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 498b9dd

Browse files
committed
Fix tests
1 parent 60106a1 commit 498b9dd

File tree

8 files changed

+12
-7
lines changed

8 files changed

+12
-7
lines changed

src/DateUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const MILLIS_IN_DAY = 86400000;
2525
export function getDaysArray(weekday: Intl.DateTimeFormatOptions["weekday"] = "short"): string[] {
2626
const now = new Date();
2727
const { format } = new Intl.DateTimeFormat(getUserLanguage(), { weekday });
28-
return [...Array(7).keys()].map((day) => format(new Date().getTime() - (now.getDay() - day) * MILLIS_IN_DAY));
28+
return [...Array(7).keys()].map((day) => format(now.getTime() - (now.getDay() - day) * MILLIS_IN_DAY));
2929
}
3030

3131
function getMonthsArray(month: Intl.DateTimeFormatOptions["month"] = "short"): string[] {
@@ -44,7 +44,7 @@ export function formatDate(date: Date, showTwelveHour = false, locale?: string):
4444
hour: "numeric",
4545
minute: "2-digit",
4646
hour12: showTwelveHour,
47-
}).format(new Date());
47+
}).format(date);
4848
} else if (now.getFullYear() === date.getFullYear()) {
4949
return new Intl.DateTimeFormat(_locale, {
5050
weekday: "short",
@@ -53,7 +53,7 @@ export function formatDate(date: Date, showTwelveHour = false, locale?: string):
5353
hour: "numeric",
5454
minute: "2-digit",
5555
hour12: showTwelveHour,
56-
}).format(new Date());
56+
}).format(date);
5757
}
5858
return formatFullDate(date, showTwelveHour, true, _locale);
5959
}
@@ -214,7 +214,7 @@ export function formatFullDateNoDayNoTime(date: Date, locale?: string): string {
214214
}
215215

216216
export function formatRelativeTime(date: Date, showTwelveHour = false): string {
217-
const now = new Date(Date.now());
217+
const now = new Date();
218218
if (withinCurrentDay(date, now)) {
219219
return formatTime(date, showTwelveHour);
220220
} else {

src/components/views/dialogs/ForwardDialog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ const ForwardDialog: React.FC<IProps> = ({ matrixClient: cli, event, permalinkCr
216216
},
217217
event_id: "$9999999999999999999999999999999999999999999",
218218
room_id: event.getRoomId(),
219+
origin_server_ts: event.getTs(),
219220
});
220221
mockEvent.sender = {
221222
name: profileInfo.displayname || userId,

src/languageHandler.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class UserFriendlyError extends Error {
9393

9494
export function getUserLanguage(): string {
9595
const language = SettingsStore.getValue("language", null, /*excludeDefault:*/ true);
96-
if (language) {
96+
if (typeof language === "string" && !!language) {
9797
return language;
9898
} else {
9999
return normalizeLanguageKey(getLanguageFromBrowser());

test/components/structures/__snapshots__/MatrixChat-test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ exports[`<MatrixChat /> with a soft-logged-out session should show the soft-logo
3737
Matrix
3838
</aside>
3939
<div
40-
class="mx_Dropdown mx_AuthBody_language"
40+
class="mx_Dropdown mx_LanguageDropdown mx_AuthBody_language"
4141
>
4242
<div
4343
aria-describedby="mx_LanguageDropdown_value"

test/components/views/rooms/SearchResultTile-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe("SearchResultTile", () => {
9393
room_id: ROOM_ID,
9494
content: { body: `Message #${i}` },
9595
event_id: `$${i}:server`,
96-
origin_server_ts: undefined,
96+
origin_server_ts: i,
9797
}),
9898
),
9999
});

test/components/views/settings/devices/DeviceDetails-test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe("<DeviceDetails />", () => {
4545

4646
beforeEach(() => {
4747
jest.setSystemTime(now);
48+
jest.spyOn(Date, "now").mockImplementation(() => now);
4849
});
4950

5051
it("renders device without metadata", () => {

test/test-utils/beacon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export const makeBeaconEvent = (
103103
room_id: roomId,
104104
sender,
105105
content: ContentHelpers.makeBeaconContent(geoUri, timestamp, beaconInfoId, description),
106+
origin_server_ts: 0,
106107
});
107108
};
108109

test/test-utils/location.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const makeLegacyLocationEvent = (geoUri: string): MatrixEvent => {
2727
msgtype: "m.location",
2828
geo_uri: geoUri,
2929
},
30+
origin_server_ts: 0,
3031
});
3132
};
3233

@@ -41,6 +42,7 @@ export const makeLocationEvent = (geoUri: string, assetType?: LocationAssetType)
4142
"Human-readable label",
4243
assetType,
4344
),
45+
origin_server_ts: 0,
4446
});
4547
};
4648

0 commit comments

Comments
 (0)