mirror of https://github.com/vector-im/riot-web
Fix jest/valid-expects lints (#11238)
parent
d7d60a3255
commit
f5f31eb7d8
|
@ -174,9 +174,6 @@ module.exports = {
|
||||||
// Disabled tests are a reality for now but as soon as all of the xits are
|
// Disabled tests are a reality for now but as soon as all of the xits are
|
||||||
// eliminated, we should enforce this.
|
// eliminated, we should enforce this.
|
||||||
"jest/no-disabled-tests": "off",
|
"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",
|
|
||||||
// Also treat "oldBackendOnly" as a test function.
|
// Also treat "oldBackendOnly" as a test function.
|
||||||
// Used in some crypto tests.
|
// Used in some crypto tests.
|
||||||
"jest/no-standalone-expect": [
|
"jest/no-standalone-expect": [
|
||||||
|
@ -194,6 +191,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
rules: {
|
rules: {
|
||||||
// Cypress "promises" work differently - disable some related rules
|
// Cypress "promises" work differently - disable some related rules
|
||||||
|
"jest/valid-expect": "off",
|
||||||
"jest/valid-expect-in-promise": "off",
|
"jest/valid-expect-in-promise": "off",
|
||||||
"jest/no-done-callback": "off",
|
"jest/no-done-callback": "off",
|
||||||
},
|
},
|
||||||
|
|
|
@ -60,9 +60,7 @@ describe("ConfirmRedactDialog", () => {
|
||||||
user: client.getSafeUserId(),
|
user: client.getSafeUserId(),
|
||||||
});
|
});
|
||||||
jest.spyOn(mxEvent, "getId").mockReturnValue(undefined);
|
jest.spyOn(mxEvent, "getId").mockReturnValue(undefined);
|
||||||
expect(async () => {
|
await expect(confirmDeleteVoiceBroadcastStartedEvent()).rejects.toThrow("cannot redact event without ID");
|
||||||
await confirmDeleteVoiceBroadcastStartedEvent();
|
|
||||||
}).rejects.toThrow("cannot redact event without ID");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should raise an error for an event without room-ID", async () => {
|
it("should raise an error for an event without room-ID", async () => {
|
||||||
|
@ -74,9 +72,9 @@ describe("ConfirmRedactDialog", () => {
|
||||||
user: client.getSafeUserId(),
|
user: client.getSafeUserId(),
|
||||||
});
|
});
|
||||||
jest.spyOn(mxEvent, "getRoomId").mockReturnValue(undefined);
|
jest.spyOn(mxEvent, "getRoomId").mockReturnValue(undefined);
|
||||||
expect(async () => {
|
await expect(confirmDeleteVoiceBroadcastStartedEvent()).rejects.toThrow(
|
||||||
await confirmDeleteVoiceBroadcastStartedEvent();
|
`cannot redact event ${mxEvent.getId()} without room ID`,
|
||||||
}).rejects.toThrow(`cannot redact event ${mxEvent.getId()} without room ID`);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when redacting a voice broadcast started event", () => {
|
describe("when redacting a voice broadcast started event", () => {
|
||||||
|
|
|
@ -79,7 +79,7 @@ describe("<CreateRoomDialog />", () => {
|
||||||
screen.getByText(
|
screen.getByText(
|
||||||
"Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.",
|
"Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.",
|
||||||
),
|
),
|
||||||
);
|
).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should use server .well-known force_disable for encryption setting", async () => {
|
it("should use server .well-known force_disable for encryption setting", async () => {
|
||||||
|
@ -99,7 +99,7 @@ describe("<CreateRoomDialog />", () => {
|
||||||
screen.getByText(
|
screen.getByText(
|
||||||
"Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.",
|
"Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.",
|
||||||
),
|
),
|
||||||
);
|
).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should use defaultEncrypted prop", async () => {
|
it("should use defaultEncrypted prop", async () => {
|
||||||
|
@ -150,7 +150,7 @@ describe("<CreateRoomDialog />", () => {
|
||||||
screen.getByText(
|
screen.getByText(
|
||||||
"Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.",
|
"Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.",
|
||||||
),
|
),
|
||||||
);
|
).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should override defaultEncrypted when server forces enabled encryption", async () => {
|
it("should override defaultEncrypted when server forces enabled encryption", async () => {
|
||||||
|
@ -161,7 +161,7 @@ describe("<CreateRoomDialog />", () => {
|
||||||
// server forces encryption to enabled, even though defaultEncrypted is true
|
// server forces encryption to enabled, even though defaultEncrypted is true
|
||||||
expect(getE2eeEnableToggleInputElement()).toBeChecked();
|
expect(getE2eeEnableToggleInputElement()).toBeChecked();
|
||||||
expect(getE2eeEnableToggleIsDisabled()).toBeTruthy();
|
expect(getE2eeEnableToggleIsDisabled()).toBeTruthy();
|
||||||
expect(screen.getByText("Your server requires encryption to be enabled in private rooms."));
|
expect(screen.getByText("Your server requires encryption to be enabled in private rooms.")).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should enable encryption toggle and disable field when server forces encryption", async () => {
|
it("should enable encryption toggle and disable field when server forces encryption", async () => {
|
||||||
|
@ -172,7 +172,7 @@ describe("<CreateRoomDialog />", () => {
|
||||||
expect(getE2eeEnableToggleInputElement()).toBeChecked();
|
expect(getE2eeEnableToggleInputElement()).toBeChecked();
|
||||||
expect(getE2eeEnableToggleIsDisabled()).toBeTruthy();
|
expect(getE2eeEnableToggleIsDisabled()).toBeTruthy();
|
||||||
|
|
||||||
expect(screen.getByText("Your server requires encryption to be enabled in private rooms."));
|
expect(screen.getByText("Your server requires encryption to be enabled in private rooms.")).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should warn when trying to create a room with an invalid form", async () => {
|
it("should warn when trying to create a room with an invalid form", async () => {
|
||||||
|
|
|
@ -66,7 +66,7 @@ describe("DevtoolsDialog", () => {
|
||||||
|
|
||||||
expect(copiedBtn).toBeInTheDocument();
|
expect(copiedBtn).toBeInTheDocument();
|
||||||
expect(navigator.clipboard.writeText).toHaveBeenCalled();
|
expect(navigator.clipboard.writeText).toHaveBeenCalled();
|
||||||
expect(navigator.clipboard.readText()).resolves.toBe(room.roomId);
|
await expect(navigator.clipboard.readText()).resolves.toBe(room.roomId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("copies the thread root id when provided", async () => {
|
it("copies the thread root id when provided", async () => {
|
||||||
|
@ -82,6 +82,6 @@ describe("DevtoolsDialog", () => {
|
||||||
|
|
||||||
expect(copiedBtn).toBeInTheDocument();
|
expect(copiedBtn).toBeInTheDocument();
|
||||||
expect(navigator.clipboard.writeText).toHaveBeenCalled();
|
expect(navigator.clipboard.writeText).toHaveBeenCalled();
|
||||||
expect(navigator.clipboard.readText()).resolves.toBe(threadRootId);
|
await expect(navigator.clipboard.readText()).resolves.toBe(threadRootId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -509,18 +509,23 @@ describe("<DeviceItem />", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when userId is the same as userId from client, uses isCrossSigningVerified to determine if button is shown", async () => {
|
it("when userId is the same as userId from client, uses isCrossSigningVerified to determine if button is shown", async () => {
|
||||||
|
const deferred = defer<DeviceVerificationStatus>();
|
||||||
|
mockCrypto.getDeviceVerificationStatus.mockReturnValue(deferred.promise);
|
||||||
|
|
||||||
mockClient.getSafeUserId.mockReturnValueOnce(defaultUserId);
|
mockClient.getSafeUserId.mockReturnValueOnce(defaultUserId);
|
||||||
mockClient.getUserId.mockReturnValueOnce(defaultUserId);
|
mockClient.getUserId.mockReturnValueOnce(defaultUserId);
|
||||||
renderComponent();
|
renderComponent();
|
||||||
await act(flushPromises);
|
await act(flushPromises);
|
||||||
|
|
||||||
// set trust to be false for isVerified, true for isCrossSigningVerified
|
// set trust to be false for isVerified, true for isCrossSigningVerified
|
||||||
setMockDeviceTrust(false, true);
|
deferred.resolve({
|
||||||
|
isVerified: () => false,
|
||||||
|
crossSigningVerified: true,
|
||||||
|
} as DeviceVerificationStatus);
|
||||||
|
|
||||||
|
await expect(screen.findByText(device.displayName!)).resolves.toBeInTheDocument();
|
||||||
// expect to see no button in this case
|
// expect to see no button in this case
|
||||||
// TODO `toBeInTheDocument` is not called, if called the test is failing
|
expect(screen.queryByRole("button")).not.toBeInTheDocument();
|
||||||
expect(screen.queryByRole("button")).not.toBeInTheDocument;
|
|
||||||
expect(screen.getByText(device.displayName!)).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("with verified user and device, displays no button and a 'Trusted' label", async () => {
|
it("with verified user and device, displays no button and a 'Trusted' label", async () => {
|
||||||
|
|
|
@ -114,7 +114,7 @@ describe("OIDC authorization", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw when query params do not include state and code", async () => {
|
it("should throw when query params do not include state and code", async () => {
|
||||||
expect(async () => await completeOidcLogin({})).rejects.toThrow(
|
await expect(completeOidcLogin({})).rejects.toThrow(
|
||||||
"Invalid query parameters for OIDC native login. `code` and `state` are required.",
|
"Invalid query parameters for OIDC native login. `code` and `state` are required.",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -55,8 +55,8 @@ describe("getOidcClientId()", () => {
|
||||||
issuer: "https://issuerWithoutStaticClientId.org/",
|
issuer: "https://issuerWithoutStaticClientId.org/",
|
||||||
registrationEndpoint: undefined,
|
registrationEndpoint: undefined,
|
||||||
};
|
};
|
||||||
expect(
|
await expect(
|
||||||
async () => await getOidcClientId(authConfigWithoutRegistration, clientName, baseUrl, staticOidcClients),
|
getOidcClientId(authConfigWithoutRegistration, clientName, baseUrl, staticOidcClients),
|
||||||
).rejects.toThrow(OidcError.DynamicRegistrationNotSupported);
|
).rejects.toThrow(OidcError.DynamicRegistrationNotSupported);
|
||||||
// didn't try to register
|
// didn't try to register
|
||||||
expect(fetchMockJest).toHaveFetchedTimes(0);
|
expect(fetchMockJest).toHaveFetchedTimes(0);
|
||||||
|
@ -67,7 +67,7 @@ describe("getOidcClientId()", () => {
|
||||||
...delegatedAuthConfig,
|
...delegatedAuthConfig,
|
||||||
registrationEndpoint: undefined,
|
registrationEndpoint: undefined,
|
||||||
};
|
};
|
||||||
expect(async () => await getOidcClientId(authConfigWithoutRegistration, clientName, baseUrl)).rejects.toThrow(
|
await expect(getOidcClientId(authConfigWithoutRegistration, clientName, baseUrl)).rejects.toThrow(
|
||||||
OidcError.DynamicRegistrationNotSupported,
|
OidcError.DynamicRegistrationNotSupported,
|
||||||
);
|
);
|
||||||
// didn't try to register
|
// didn't try to register
|
||||||
|
@ -104,7 +104,7 @@ describe("getOidcClientId()", () => {
|
||||||
fetchMockJest.post(registrationEndpoint, {
|
fetchMockJest.post(registrationEndpoint, {
|
||||||
status: 500,
|
status: 500,
|
||||||
});
|
});
|
||||||
expect(() => getOidcClientId(delegatedAuthConfig, clientName, baseUrl)).rejects.toThrow(
|
await expect(getOidcClientId(delegatedAuthConfig, clientName, baseUrl)).rejects.toThrow(
|
||||||
OidcError.DynamicRegistrationFailed,
|
OidcError.DynamicRegistrationFailed,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -115,7 +115,7 @@ describe("getOidcClientId()", () => {
|
||||||
// no clientId in response
|
// no clientId in response
|
||||||
body: "{}",
|
body: "{}",
|
||||||
});
|
});
|
||||||
expect(() => getOidcClientId(delegatedAuthConfig, clientName, baseUrl)).rejects.toThrow(
|
await expect(getOidcClientId(delegatedAuthConfig, clientName, baseUrl)).rejects.toThrow(
|
||||||
OidcError.DynamicRegistrationInvalid,
|
OidcError.DynamicRegistrationInvalid,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue