Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,43 @@ module.exports = {
},
{
files: ["test/**/*.{ts,tsx}", "cypress/**/*.ts"],
extends: ["plugin:matrix-org/jest"],
rules: {
// We don't need super strict typing in test utilities
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": "off",

// Jest/Cypress specific

// Disabled tests are a reality for now but as soon as all of the xits are
// eliminated, we should enforce this.
"jest/no-disabled-tests": "off",
// TODO: There are many tests with invalid expects that should be fixed,
// https://github.com/vector-im/element-web/issues/24709
"jest/valid-expect": "off",
// TODO: There are many cases to refactor away,
// https://github.com/vector-im/element-web/issues/24710
"jest/no-conditional-expect": "off",
// Also treat "oldBackendOnly" as a test function.
// Used in some crypto tests.
"jest/no-standalone-expect": [
"error",
{
additionalTestBlockFunctions: ["beforeAll", "beforeEach", "oldBackendOnly"],
},
],
},
},
{
files: ["cypress/**/*.ts"],
parserOptions: {
project: ["./cypress/tsconfig.json"],
},
rules: {
// Cypress "promises" work differently - disable some related rules
"jest/valid-expect-in-promise": "off",
"jest/no-done-callback": "off",
},
},
],
settings: {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/sliding-sync/sliding-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ describe("Sliding Sync", () => {
});

// Regression test for https://github.com/vector-im/element-web/issues/21462
it("should not cancel replies when permalinks are clicked ", () => {
it("should not cancel replies when permalinks are clicked", () => {
cy.get<string>("@roomId").then((roomId) => {
// we require a first message as you cannot click the permalink text with the avatar in the way
return cy
Expand Down
43 changes: 22 additions & 21 deletions cypress/e2e/spotlight/spotlight.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Timeoutable = Cypress.Timeoutable;
import Withinable = Cypress.Withinable;
import Shadow = Cypress.Shadow;

export enum Filter {
enum Filter {
People = "people",
PublicRooms = "public_rooms",
}
Expand Down Expand Up @@ -297,27 +297,28 @@ describe("Spotlight", () => {

// TODO: We currently can’t test finding rooms on other homeservers/other protocols
// We obviously don’t have federation or bridges in cypress tests
Comment on lines 298 to 299

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cy.intercept is a thing, not sure why we "can't"

Unrelated to this PR off

/*
const room3Name = "Matrix HQ";
const room3Id = "#matrix:matrix.org";

it("should find unknown public rooms on other homeservers", () => {
cy.openSpotlightDialog().within(() => {
cy.spotlightFilter(Filter.PublicRooms);
cy.spotlightSearch().clear().type(room3Name);
cy.get("[aria-haspopup=true][role=button]").click();
}).then(() => {
cy.contains(".mx_GenericDropdownMenu_Option--header", "matrix.org")
.next("[role=menuitemradio]")
.click();
cy.wait(3_600_000);
}).then(() => cy.spotlightDialog().within(() => {
cy.spotlightResults().should("have.length", 1);
cy.spotlightResults().eq(0).should("contain", room3Name);
cy.spotlightResults().eq(0).should("contain", room3Id);
}));
it.skip("should find unknown public rooms on other homeservers", () => {
cy.openSpotlightDialog()
.within(() => {
cy.spotlightFilter(Filter.PublicRooms);
cy.spotlightSearch().clear().type(room3Name);
cy.get("[aria-haspopup=true][role=button]").click();
})
.then(() => {
cy.contains(".mx_GenericDropdownMenu_Option--header", "matrix.org")
.next("[role=menuitemradio]")
.click();
cy.wait(3_600_000);
})
.then(() =>
cy.spotlightDialog().within(() => {
cy.spotlightResults().should("have.length", 1);
cy.spotlightResults().eq(0).should("contain", room3Name);
cy.spotlightResults().eq(0).should("contain", room3Id);
}),
);
});
*/

it("should find known people", () => {
cy.openSpotlightDialog()
.within(() => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-deprecate": "^0.7.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-matrix-org": "1.0.0",
"eslint-plugin-react": "^7.28.0",
Expand Down
2 changes: 1 addition & 1 deletion test/ContentMessages-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,6 @@ describe("uploadFile", () => {
const prom = uploadFile(client, "!roomId:server", file);
mocked(client.uploadContent).mock.calls[0][1]!.abortController!.abort();
deferred.resolve({ content_uri: "mxc://foo/bar" });
await expect(prom).rejects.toThrowError(UploadCanceledError);
await expect(prom).rejects.toThrow(UploadCanceledError);
});
});
34 changes: 9 additions & 25 deletions test/DecryptionFailureTracker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function createFailedDecryptionEvent() {
}

describe("DecryptionFailureTracker", function () {
it("tracks a failed decryption for a visible event", function (done) {
it("tracks a failed decryption for a visible event", function () {
const failedDecryptionEvent = createFailedDecryptionEvent();

let count = 0;
Expand All @@ -59,11 +59,9 @@ describe("DecryptionFailureTracker", function () {
tracker.trackFailures();

expect(count).not.toBe(0, "should track a failure for an event that failed decryption");

done();
});

it("tracks a failed decryption with expected raw error for a visible event", function (done) {
it("tracks a failed decryption with expected raw error for a visible event", function () {
const failedDecryptionEvent = createFailedDecryptionEvent();

let count = 0;
Expand All @@ -89,11 +87,9 @@ describe("DecryptionFailureTracker", function () {

expect(count).not.toBe(0, "should track a failure for an event that failed decryption");
expect(reportedRawCode).toBe("INBOUND_SESSION_MISMATCH_ROOM_ID", "Should add the rawCode to the event context");

done();
});

it("tracks a failed decryption for an event that becomes visible later", function (done) {
it("tracks a failed decryption for an event that becomes visible later", function () {
const failedDecryptionEvent = createFailedDecryptionEvent();

let count = 0;
Expand All @@ -114,11 +110,9 @@ describe("DecryptionFailureTracker", function () {
tracker.trackFailures();

expect(count).not.toBe(0, "should track a failure for an event that failed decryption");

done();
});

it("does not track a failed decryption for an event that never becomes visible", function (done) {
it("does not track a failed decryption for an event that never becomes visible", function () {
const failedDecryptionEvent = createFailedDecryptionEvent();

let count = 0;
Expand All @@ -137,11 +131,9 @@ describe("DecryptionFailureTracker", function () {
tracker.trackFailures();

expect(count).toBe(0, "should not track a failure for an event that never became visible");

done();
});

it("does not track a failed decryption where the event is subsequently successfully decrypted", (done) => {
it("does not track a failed decryption where the event is subsequently successfully decrypted", () => {
const decryptedEvent = createFailedDecryptionEvent();
const tracker = new DecryptionFailureTracker(
(total) => {
Expand All @@ -164,13 +156,12 @@ describe("DecryptionFailureTracker", function () {

// Immediately track the newest failures
tracker.trackFailures();
done();
});

it(
"does not track a failed decryption where the event is subsequently successfully decrypted " +
"and later becomes visible",
(done) => {
() => {
const decryptedEvent = createFailedDecryptionEvent();
const tracker = new DecryptionFailureTracker(
(total) => {
Expand All @@ -193,11 +184,10 @@ describe("DecryptionFailureTracker", function () {

// Immediately track the newest failures
tracker.trackFailures();
done();
},
);

it("only tracks a single failure per event, despite multiple failed decryptions for multiple events", (done) => {
it("only tracks a single failure per event, despite multiple failed decryptions for multiple events", () => {
const decryptedEvent = createFailedDecryptionEvent();
const decryptedEvent2 = createFailedDecryptionEvent();

Expand Down Expand Up @@ -231,11 +221,9 @@ describe("DecryptionFailureTracker", function () {
tracker.trackFailures();

expect(count).toBe(2, count + " failures tracked, should only track a single failure per event");

done();
});

it("should not track a failure for an event that was tracked previously", (done) => {
it("should not track a failure for an event that was tracked previously", () => {
const decryptedEvent = createFailedDecryptionEvent();

let count = 0;
Expand All @@ -261,11 +249,9 @@ describe("DecryptionFailureTracker", function () {
tracker.trackFailures();

expect(count).toBe(1, "should only track a single failure per event");

done();
});

xit("should not track a failure for an event that was tracked in a previous session", (done) => {
it.skip("should not track a failure for an event that was tracked in a previous session", () => {
// This test uses localStorage, clear it beforehand
localStorage.clear();

Expand Down Expand Up @@ -304,8 +290,6 @@ describe("DecryptionFailureTracker", function () {
secondTracker.trackFailures();

expect(count).toBe(1, count + " failures tracked, should only track a single failure per event");

done();
});

it("should count different error codes separately for multiple failures with different error codes", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/Notifier-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ describe("Notifier", () => {
);
});

it("should display the expected notification for a broadcast chunk with sequence = 1", () => {
it("should display the expected notification for a broadcast chunk with sequence = 2", () => {
const audioEvent = mkAudioEvent({ sequence: 2 });
Notifier.displayPopupNotification(audioEvent, testRoom);
expect(MockPlatform.displayNotification).not.toHaveBeenCalled();
Expand Down
2 changes: 1 addition & 1 deletion test/PosthogAnalytics-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const getFakePosthog = (): PostHog =>
register: jest.fn(),
} as unknown as PostHog);

export interface ITestEvent extends IPosthogEvent {
interface ITestEvent extends IPosthogEvent {
eventName: "JestTestEvents";
foo?: string;
}
Expand Down
2 changes: 1 addition & 1 deletion test/RoomNotifs-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe("RoomNotifs test", () => {
expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, THREAD_ID)).toBe(0);
});

it("counts notifications type", () => {
it("counts thread notifications type", () => {
room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Total, 2);
room.setThreadUnreadNotificationCount(THREAD_ID, NotificationCountType.Highlight, 1);

Expand Down
2 changes: 1 addition & 1 deletion test/ScalarAuthClient-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("ScalarAuthClient", function () {

await sac.connect();

expect(sac.exchangeForScalarToken).toBeCalledWith(tokenObject);
expect(sac.exchangeForScalarToken).toHaveBeenCalledWith(tokenObject);
expect(sac.hasCredentials).toBeTruthy();
// @ts-ignore private property
expect(sac.scalarToken).toEqual("wokentoken");
Expand Down
40 changes: 20 additions & 20 deletions test/SlidingSyncManager-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("SlidingSyncManager", () => {
mocked(slidingSync.getRoomSubscriptions).mockReturnValue(subs);
mocked(slidingSync.modifyRoomSubscriptions).mockResolvedValue("yep");
await manager.setRoomVisible(roomId, true);
expect(slidingSync.modifyRoomSubscriptions).toBeCalledWith(new Set<string>([roomId]));
expect(slidingSync.modifyRoomSubscriptions).toHaveBeenCalledWith(new Set<string>([roomId]));
});
it("adds a custom subscription for a lazy-loadable room", async () => {
const roomId = "!lazy:id";
Expand All @@ -72,9 +72,9 @@ describe("SlidingSyncManager", () => {
mocked(slidingSync.getRoomSubscriptions).mockReturnValue(subs);
mocked(slidingSync.modifyRoomSubscriptions).mockResolvedValue("yep");
await manager.setRoomVisible(roomId, true);
expect(slidingSync.modifyRoomSubscriptions).toBeCalledWith(new Set<string>([roomId]));
expect(slidingSync.modifyRoomSubscriptions).toHaveBeenCalledWith(new Set<string>([roomId]));
// we aren't prescriptive about what the sub name is.
expect(slidingSync.useCustomSubscription).toBeCalledWith(roomId, expect.anything());
expect(slidingSync.useCustomSubscription).toHaveBeenCalledWith(roomId, expect.anything());
});
});

Expand All @@ -86,7 +86,7 @@ describe("SlidingSyncManager", () => {
await manager.ensureListRegistered(listKey, {
sort: ["by_recency"],
});
expect(slidingSync.setList).toBeCalledWith(
expect(slidingSync.setList).toHaveBeenCalledWith(
listKey,
expect.objectContaining({
sort: ["by_recency"],
Expand All @@ -103,7 +103,7 @@ describe("SlidingSyncManager", () => {
await manager.ensureListRegistered(listKey, {
sort: ["by_recency"],
});
expect(slidingSync.setList).toBeCalledWith(
expect(slidingSync.setList).toHaveBeenCalledWith(
listKey,
expect.objectContaining({
sort: ["by_recency"],
Expand All @@ -121,8 +121,8 @@ describe("SlidingSyncManager", () => {
await manager.ensureListRegistered(listKey, {
ranges: [[0, 52]],
});
expect(slidingSync.setList).not.toBeCalled();
expect(slidingSync.setListRanges).toBeCalledWith(listKey, [[0, 52]]);
expect(slidingSync.setList).not.toHaveBeenCalled();
expect(slidingSync.setListRanges).toHaveBeenCalledWith(listKey, [[0, 52]]);
});

it("no-ops for idential changes", async () => {
Expand All @@ -136,8 +136,8 @@ describe("SlidingSyncManager", () => {
ranges: [[0, 42]],
sort: ["by_recency"],
});
expect(slidingSync.setList).not.toBeCalled();
expect(slidingSync.setListRanges).not.toBeCalled();
expect(slidingSync.setList).not.toHaveBeenCalled();
expect(slidingSync.setListRanges).not.toHaveBeenCalled();
});
});

Expand All @@ -163,20 +163,20 @@ describe("SlidingSyncManager", () => {
[50, 59],
[60, 69],
];
expect(slidingSync.getListData).toBeCalledTimes(wantWindows.length);
expect(slidingSync.setList).toBeCalledTimes(1);
expect(slidingSync.setListRanges).toBeCalledTimes(wantWindows.length - 1);
expect(slidingSync.getListData).toHaveBeenCalledTimes(wantWindows.length);
expect(slidingSync.setList).toHaveBeenCalledTimes(1);
expect(slidingSync.setListRanges).toHaveBeenCalledTimes(wantWindows.length - 1);
wantWindows.forEach((range, i) => {
if (i === 0) {
expect(slidingSync.setList).toBeCalledWith(
expect(slidingSync.setList).toHaveBeenCalledWith(
SlidingSyncManager.ListSearch,
expect.objectContaining({
ranges: [[0, batchSize - 1], range],
}),
);
return;
}
expect(slidingSync.setListRanges).toBeCalledWith(SlidingSyncManager.ListSearch, [
expect(slidingSync.setListRanges).toHaveBeenCalledWith(SlidingSyncManager.ListSearch, [
[0, batchSize - 1],
range,
]);
Expand All @@ -193,9 +193,9 @@ describe("SlidingSyncManager", () => {
};
});
await manager.startSpidering(batchSize, gapMs);
expect(slidingSync.getListData).toBeCalledTimes(1);
expect(slidingSync.setList).toBeCalledTimes(1);
expect(slidingSync.setList).toBeCalledWith(
expect(slidingSync.getListData).toHaveBeenCalledTimes(1);
expect(slidingSync.setList).toHaveBeenCalledTimes(1);
expect(slidingSync.setList).toHaveBeenCalledWith(
SlidingSyncManager.ListSearch,
expect.objectContaining({
ranges: [
Expand All @@ -216,9 +216,9 @@ describe("SlidingSyncManager", () => {
};
});
await manager.startSpidering(batchSize, gapMs);
expect(slidingSync.getListData).toBeCalledTimes(1);
expect(slidingSync.setList).toBeCalledTimes(1);
expect(slidingSync.setList).toBeCalledWith(
expect(slidingSync.getListData).toHaveBeenCalledTimes(1);
expect(slidingSync.setList).toHaveBeenCalledTimes(1);
expect(slidingSync.setList).toHaveBeenCalledWith(
SlidingSyncManager.ListSearch,
expect.objectContaining({
ranges: [
Expand Down
Loading