-
+
);
}
diff --git a/app/javascript/packages/react-hooks/index.ts b/app/javascript/packages/react-hooks/index.ts
index 94fc83bbfb1..10c1e14a8de 100644
--- a/app/javascript/packages/react-hooks/index.ts
+++ b/app/javascript/packages/react-hooks/index.ts
@@ -1,3 +1,4 @@
export { default as useDidUpdateEffect } from './use-did-update-effect';
export { default as useIfStillMounted } from './use-if-still-mounted';
+export { default as useImmutableCallback } from './use-immutable-callback';
export { default as useInstanceId } from './use-instance-id';
diff --git a/spec/javascripts/packages/document-capture/hooks/use-immutable-callback-spec.jsx b/app/javascript/packages/react-hooks/use-immutable-callback.spec.tsx
similarity index 71%
rename from spec/javascripts/packages/document-capture/hooks/use-immutable-callback-spec.jsx
rename to app/javascript/packages/react-hooks/use-immutable-callback.spec.tsx
index bbda26b59b0..6ec20b0b72b 100644
--- a/spec/javascripts/packages/document-capture/hooks/use-immutable-callback-spec.jsx
+++ b/app/javascript/packages/react-hooks/use-immutable-callback.spec.tsx
@@ -1,9 +1,9 @@
import sinon from 'sinon';
import { renderHook } from '@testing-library/react-hooks';
-import useImmutableCallback from '@18f/identity-document-capture/hooks/use-immutable-callback';
+import useImmutableCallback from './use-immutable-callback';
-describe('document-capture/hooks/use-immutable-callback', () => {
- const callback1 = () => {};
+describe('useImmutableCallback', () => {
+ const callback1 = (_arg1: any, _arg2: any) => {};
const callback2 = sinon.stub().callsFake(() => {});
it('maintains a consistent reference', () => {
@@ -24,9 +24,8 @@ describe('document-capture/hooks/use-immutable-callback', () => {
});
rerender({ fn: callback2 });
- const args = [1, 2];
- result.current(...args);
+ result.current(1, 2);
- expect(callback2).to.have.been.calledWith(...args);
+ expect(callback2).to.have.been.calledWith(1, 2);
});
});
diff --git a/app/javascript/packages/document-capture/hooks/use-immutable-callback.js b/app/javascript/packages/react-hooks/use-immutable-callback.ts
similarity index 57%
rename from app/javascript/packages/document-capture/hooks/use-immutable-callback.js
rename to app/javascript/packages/react-hooks/use-immutable-callback.ts
index c1e7932b466..06fbb4ef3d4 100644
--- a/app/javascript/packages/document-capture/hooks/use-immutable-callback.js
+++ b/app/javascript/packages/react-hooks/use-immutable-callback.ts
@@ -6,21 +6,17 @@ import { useRef, useEffect, useCallback } from 'react';
*
* @see https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
*
- * @template {(...args: any[]) => any} F
- *
- * @param {F} fn
- * @param {any[]=} dependencies Callback dependencies
- *
- * @return {F}
+ * @param fn
+ * @param dependencies Callback dependencies
*/
-function useImmutableCallback(fn, dependencies = []) {
- const ref = useRef(/** @type {F} */ (() => {}));
+function useImmutableCallback
any>(fn: F, dependencies: any[] = []) {
+ const ref = useRef((() => {}) as F);
useEffect(() => {
ref.current = fn;
}, [fn, ...dependencies]);
- return useCallback(/** @type {F} */ ((...args) => ref.current(...args)), [ref]);
+ return useCallback(((...args) => ref.current(...args)) as F, [ref]);
}
export default useImmutableCallback;
diff --git a/app/javascript/packages/verify-flow/steps/personal-key-confirm/personal-key-confirm-step.spec.tsx b/app/javascript/packages/verify-flow/steps/personal-key-confirm/personal-key-confirm-step.spec.tsx
index 4e2af8ac167..63d4cca1be1 100644
--- a/app/javascript/packages/verify-flow/steps/personal-key-confirm/personal-key-confirm-step.spec.tsx
+++ b/app/javascript/packages/verify-flow/steps/personal-key-confirm/personal-key-confirm-step.spec.tsx
@@ -13,7 +13,7 @@ describe('PersonalKeyConfirmStep', () => {
registerField: () => () => {},
};
- it('allows the user to return to the previous step', () => {
+ it('allows the user to return to the previous step by clicking "Back" button', () => {
const toPreviousStep = sinon.spy();
const { getByText } = render(
,
@@ -23,4 +23,15 @@ describe('PersonalKeyConfirmStep', () => {
expect(toPreviousStep).to.have.been.called();
});
+
+ it('allows the user to return to the previous step by pressing Escape', () => {
+ const toPreviousStep = sinon.spy();
+ const { getByRole } = render(
+ ,
+ );
+
+ userEvent.type(getByRole('textbox'), '{esc}');
+
+ expect(toPreviousStep).to.have.been.called();
+ });
});
diff --git a/app/javascript/packages/verify-flow/steps/personal-key-confirm/personal-key-confirm-step.tsx b/app/javascript/packages/verify-flow/steps/personal-key-confirm/personal-key-confirm-step.tsx
index 8dc1b2d4aae..f9f5f76d6a8 100644
--- a/app/javascript/packages/verify-flow/steps/personal-key-confirm/personal-key-confirm-step.tsx
+++ b/app/javascript/packages/verify-flow/steps/personal-key-confirm/personal-key-confirm-step.tsx
@@ -18,7 +18,7 @@ function PersonalKeyConfirmStep(stepProps: PersonalKeyConfirmStepProps) {
-
+