Use new api CryptoApi.getCrossSigningStatus in CrossSigningPanel (#11052)

* Use new api `CryptoApi.getCrossSigningStatus` in `CrossSigningPanel`

* Update `CrossSigningPanel-test.tsx`

* Update `publicKeysOnDevice`

* Fix `CryptoApi` import

* Fix strict type

* Fix tests

* Remove `crossSigningInfo` in `mockClientMethodsCrypto`

* Move matrix client initialization in `beforeEach`
This commit is contained in:
Florian Duros 2023-06-12 20:33:39 +02:00 committed by GitHub
parent a40d1ec670
commit d5d1ec775c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 28 deletions

View file

@ -16,7 +16,8 @@ limitations under the License.
import React from "react";
import { render, screen } from "@testing-library/react";
import { mocked } from "jest-mock";
import { Mocked, mocked } from "jest-mock";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import CrossSigningPanel from "../../../../src/components/views/settings/CrossSigningPanel";
import {
@ -28,17 +29,18 @@ import {
describe("<CrossSigningPanel />", () => {
const userId = "@alice:server.org";
const mockClient = getMockClientWithEventEmitter({
...mockClientMethodsUser(userId),
...mockClientMethodsCrypto(),
doesServerSupportUnstableFeature: jest.fn(),
});
let mockClient: Mocked<MatrixClient>;
const getComponent = () => render(<CrossSigningPanel />);
beforeEach(() => {
mockClient = getMockClientWithEventEmitter({
...mockClientMethodsUser(userId),
...mockClientMethodsCrypto(),
doesServerSupportUnstableFeature: jest.fn(),
});
mockClient.doesServerSupportUnstableFeature.mockResolvedValue(true);
mockClient.isCrossSigningReady.mockResolvedValue(false);
mocked(mockClient.crypto!.crossSigningInfo).isStoredInSecretStorage.mockClear().mockResolvedValue(null);
});
it("should render a spinner while loading", () => {
@ -72,15 +74,20 @@ describe("<CrossSigningPanel />", () => {
});
it("should render when keys are backed up", async () => {
mocked(mockClient.crypto!.crossSigningInfo).isStoredInSecretStorage.mockResolvedValue({ test: {} });
mocked(mockClient.getCrypto()!.getCrossSigningStatus).mockResolvedValue({
publicKeysOnDevice: true,
privateKeysInSecretStorage: true,
privateKeysCachedLocally: {
masterKey: true,
selfSigningKey: true,
userSigningKey: true,
},
});
getComponent();
await flushPromises();
expect(screen.getByTestId("summarised-status").innerHTML).toEqual("✅ Cross-signing is ready for use.");
expect(screen.getByText("Cross-signing private keys:").parentElement!).toMatchSnapshot();
expect(mockClient.crypto!.crossSigningInfo.isStoredInSecretStorage).toHaveBeenCalledWith(
mockClient.secretStorage,
);
});
});
@ -97,7 +104,15 @@ describe("<CrossSigningPanel />", () => {
});
it("should render when keys are backed up", async () => {
mocked(mockClient.crypto!.crossSigningInfo).isStoredInSecretStorage.mockResolvedValue({ test: {} });
mocked(mockClient.getCrypto()!.getCrossSigningStatus).mockResolvedValue({
publicKeysOnDevice: true,
privateKeysInSecretStorage: true,
privateKeysCachedLocally: {
masterKey: true,
selfSigningKey: true,
userSigningKey: true,
},
});
getComponent();
await flushPromises();
@ -105,9 +120,6 @@ describe("<CrossSigningPanel />", () => {
"Your account has a cross-signing identity in secret storage, but it is not yet trusted by this session.",
);
expect(screen.getByText("Cross-signing private keys:").parentElement!).toMatchSnapshot();
expect(mockClient.crypto!.crossSigningInfo.isStoredInSecretStorage).toHaveBeenCalledWith(
mockClient.secretStorage,
);
});
});
});