Bump react-focus-lock (#7858)

* react-focus-lock to 2.5.1

Signed-off-by: Kerry Archibald <kerrya@element.io>

* use enzyme in ASSD test so focus lock finds active element

Signed-off-by: Kerry Archibald <kerrya@element.io>

* findById and flushPromises to test utils

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2022-02-21 18:09:01 +01:00 committed by GitHub
parent 8b9263c808
commit 9db59d75b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 64 additions and 96 deletions

View file

@ -15,52 +15,63 @@ limitations under the License.
*/
import React from 'react';
import TestRenderer from 'react-test-renderer';
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import sdk from '../../../skinned-sdk';
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
import { stubClient } from '../../../test-utils';
import { findById, flushPromises } from '../../../utils/test-utils';
const AccessSecretStorageDialog = sdk.getComponent("dialogs.security.AccessSecretStorageDialog");
describe("AccessSecretStorageDialog", function() {
it("Closes the dialog if _onRecoveryKeyNext is called with a valid key", (done) => {
const testInstance = TestRenderer.create(
it("Closes the dialog if _onRecoveryKeyNext is called with a valid key", async () => {
const onFinished = jest.fn();
const checkPrivateKey = jest.fn().mockResolvedValue(true);
const wrapper = mount(
<AccessSecretStorageDialog
checkPrivateKey={(p) => p && p.recoveryKey && p.recoveryKey == "a"}
onFinished={(v) => {
if (v) { done(); }
}}
checkPrivateKey={checkPrivateKey}
onFinished={onFinished}
/>,
);
testInstance.getInstance().setState({
wrapper.setState({
recoveryKeyValid: true,
recoveryKey: "a",
});
const e = { preventDefault: () => {} };
testInstance.getInstance().onRecoveryKeyNext(e);
wrapper.find('form').simulate('submit', e);
await flushPromises();
expect(checkPrivateKey).toHaveBeenCalledWith({ recoveryKey: "a" });
expect(onFinished).toHaveBeenCalledWith({ recoveryKey: "a" });
});
it("Considers a valid key to be valid", async function() {
const testInstance = TestRenderer.create(
const wrapper = mount(
<AccessSecretStorageDialog
checkPrivateKey={() => true}
/>,
);
const v = "asdf";
const e = { target: { value: v } };
stubClient();
MatrixClientPeg.get().keyBackupKeyFromRecoveryKey = () => 'a raw key';
MatrixClientPeg.get().checkSecretStorageKey = () => true;
testInstance.getInstance().onRecoveryKeyChange(e);
const v = "asdf";
const e = { target: { value: v } };
act(() => {
findById(wrapper, 'mx_securityKey').find('input').simulate('change', e);
});
// force a validation now because it debounces
await testInstance.getInstance().validateRecoveryKey();
const { recoveryKeyValid } = testInstance.getInstance().state;
await wrapper.instance().validateRecoveryKey();
const { recoveryKeyValid } = wrapper.instance().state;
expect(recoveryKeyValid).toBe(true);
});
it("Notifies the user if they input an invalid Security Key", async function() {
const testInstance = TestRenderer.create(
const wrapper = mount(
<AccessSecretStorageDialog
checkPrivateKey={async () => false}
/>,
@ -70,22 +81,24 @@ describe("AccessSecretStorageDialog", function() {
MatrixClientPeg.get().keyBackupKeyFromRecoveryKey = () => {
throw new Error("that's no key");
};
testInstance.getInstance().onRecoveryKeyChange(e);
// force a validation now because it debounces
await testInstance.getInstance().validateRecoveryKey();
const { recoveryKeyValid, recoveryKeyCorrect } = testInstance.getInstance().state;
act(() => {
findById(wrapper, 'mx_securityKey').find('input').simulate('change', e);
});
// force a validation now because it debounces
await wrapper.instance().validateRecoveryKey();
const { recoveryKeyValid, recoveryKeyCorrect } = wrapper.instance().state;
expect(recoveryKeyValid).toBe(false);
expect(recoveryKeyCorrect).toBe(false);
const notification = testInstance.root.findByProps({
className: "mx_AccessSecretStorageDialog_recoveryKeyFeedback " +
"mx_AccessSecretStorageDialog_recoveryKeyFeedback_invalid",
});
expect(notification.props.children).toEqual("Invalid Security Key");
wrapper.setProps({});
const notification = wrapper.find(".mx_AccessSecretStorageDialog_recoveryKeyFeedback");
expect(notification.props().children).toEqual("Invalid Security Key");
});
it("Notifies the user if they input an invalid passphrase", async function() {
const testInstance = TestRenderer.create(
const wrapper = mount(
<AccessSecretStorageDialog
checkPrivateKey={() => false}
onFinished={() => {}}
@ -100,12 +113,12 @@ describe("AccessSecretStorageDialog", function() {
const e = { target: { value: "a" } };
stubClient();
MatrixClientPeg.get().isValidRecoveryKey = () => false;
testInstance.getInstance().onPassPhraseChange(e);
await testInstance.getInstance().onPassPhraseNext({ preventDefault: () => {} });
const notification = testInstance.root.findByProps({
className: "mx_AccessSecretStorageDialog_keyStatus",
});
expect(notification.props.children).toEqual(
wrapper.instance().onPassPhraseChange(e);
await wrapper.instance().onPassPhraseNext({ preventDefault: () => { } });
wrapper.setProps({});
const notification = wrapper.find(".mx_AccessSecretStorageDialog_keyStatus");
expect(notification.props().children).toEqual(
["\uD83D\uDC4E ", "Unable to access secret storage. Please verify that you " +
"entered the correct Security Phrase."]);
});