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

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy committed Aug 18, 2023
1 parent 60106a1 commit 498b9dd
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const MILLIS_IN_DAY = 86400000;
export function getDaysArray(weekday: Intl.DateTimeFormatOptions["weekday"] = "short"): string[] {
const now = new Date();
const { format } = new Intl.DateTimeFormat(getUserLanguage(), { weekday });
return [...Array(7).keys()].map((day) => format(new Date().getTime() - (now.getDay() - day) * MILLIS_IN_DAY));
return [...Array(7).keys()].map((day) => format(now.getTime() - (now.getDay() - day) * MILLIS_IN_DAY));
}

function getMonthsArray(month: Intl.DateTimeFormatOptions["month"] = "short"): string[] {
Expand All @@ -44,7 +44,7 @@ export function formatDate(date: Date, showTwelveHour = false, locale?: string):
hour: "numeric",
minute: "2-digit",
hour12: showTwelveHour,
}).format(new Date());
}).format(date);
} else if (now.getFullYear() === date.getFullYear()) {
return new Intl.DateTimeFormat(_locale, {
weekday: "short",
Expand All @@ -53,7 +53,7 @@ export function formatDate(date: Date, showTwelveHour = false, locale?: string):
hour: "numeric",
minute: "2-digit",
hour12: showTwelveHour,
}).format(new Date());
}).format(date);
}
return formatFullDate(date, showTwelveHour, true, _locale);
}
Expand Down Expand Up @@ -214,7 +214,7 @@ export function formatFullDateNoDayNoTime(date: Date, locale?: string): string {
}

export function formatRelativeTime(date: Date, showTwelveHour = false): string {
const now = new Date(Date.now());
const now = new Date();
if (withinCurrentDay(date, now)) {
return formatTime(date, showTwelveHour);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/components/views/dialogs/ForwardDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ const ForwardDialog: React.FC<IProps> = ({ matrixClient: cli, event, permalinkCr
},
event_id: "$9999999999999999999999999999999999999999999",
room_id: event.getRoomId(),
origin_server_ts: event.getTs(),
});
mockEvent.sender = {
name: profileInfo.displayname || userId,
Expand Down
2 changes: 1 addition & 1 deletion src/languageHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class UserFriendlyError extends Error {

export function getUserLanguage(): string {
const language = SettingsStore.getValue("language", null, /*excludeDefault:*/ true);
if (language) {
if (typeof language === "string" && !!language) {
return language;
} else {
return normalizeLanguageKey(getLanguageFromBrowser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports[`<MatrixChat /> with a soft-logged-out session should show the soft-logo
Matrix
</aside>
<div
class="mx_Dropdown mx_AuthBody_language"
class="mx_Dropdown mx_LanguageDropdown mx_AuthBody_language"
>
<div
aria-describedby="mx_LanguageDropdown_value"
Expand Down
2 changes: 1 addition & 1 deletion test/components/views/rooms/SearchResultTile-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("SearchResultTile", () => {
room_id: ROOM_ID,
content: { body: `Message #${i}` },
event_id: `$${i}:server`,
origin_server_ts: undefined,
origin_server_ts: i,
}),
),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe("<DeviceDetails />", () => {

beforeEach(() => {
jest.setSystemTime(now);
jest.spyOn(Date, "now").mockImplementation(() => now);
});

it("renders device without metadata", () => {
Expand Down
1 change: 1 addition & 0 deletions test/test-utils/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const makeBeaconEvent = (
room_id: roomId,
sender,
content: ContentHelpers.makeBeaconContent(geoUri, timestamp, beaconInfoId, description),
origin_server_ts: 0,
});
};

Expand Down
2 changes: 2 additions & 0 deletions test/test-utils/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const makeLegacyLocationEvent = (geoUri: string): MatrixEvent => {
msgtype: "m.location",
geo_uri: geoUri,
},
origin_server_ts: 0,
});
};

Expand All @@ -41,6 +42,7 @@ export const makeLocationEvent = (geoUri: string, assetType?: LocationAssetType)
"Human-readable label",
assetType,
),
origin_server_ts: 0,
});
};

Expand Down

0 comments on commit 498b9dd

Please sign in to comment.