Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix paste for personal key confirmation (IdV app) #6443

Merged
merged 2 commits into from
Jun 3, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ describe('PersonalKeyInput', () => {
expect(input.value).to.equal('1234-1234-1234-1234');
});

it('allows the user to paste the personal key from their clipboard', async () => {
const { getByRole } = render(<PersonalKeyInput />);

const input = getByRole('textbox') as HTMLInputElement;

input.focus();
await userEvent.paste('1234-1234-1234-1234');

expect(input.value).to.equal('1234-1234-1234-1234');
});

it('validates the input value against the expected value (case-insensitive, crockford)', async () => {
const { getByRole } = render(<PersonalKeyInput expectedValue="abcd-0011-DEFG-1111" />);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { forwardRef, useCallback } from 'react';
import type { ForwardedRef } from 'react';
import Cleave from 'cleave.js/react';
import type { ReactInstanceWithCleave } from 'cleave.js/react/props';
import { t } from '@18f/identity-i18n';
import { ValidatedField } from '@18f/identity-validated-field';
import type { ValidatedFieldValidator } from '@18f/identity-validated-field';

/**
* Internal Cleave.js React instance API methods.
*/
interface CleaveInstanceInternalAPI {
updateValueState: () => void;
}

interface PersonalKeyInputProps {
/**
* The correct personal key to validate against.
Expand Down Expand Up @@ -42,6 +50,9 @@ function PersonalKeyInput(
return (
<ValidatedField validate={validate}>
<Cleave
onInit={(owner) => {
(owner as ReactInstanceWithCleave & CleaveInstanceInternalAPI).updateValueState();
}}
options={{
blocks: [4, 4, 4, 4],
delimiter: '-',
Expand Down
14 changes: 14 additions & 0 deletions spec/support/shared_examples_for_personal_keys.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'rbconfig'

shared_examples_for 'personal key page' do
include PersonalKeyHelper
include JavascriptDriverHelper
Expand Down Expand Up @@ -36,6 +38,14 @@
copied_text = page.evaluate_async_script('navigator.clipboard.readText().then(arguments[0])')

expect(copied_text).to eq(scrape_personal_key)

click_continue
mod = mac? ? :meta : :control
page.find(':focus').send_keys [mod, 'v']

path_before_submit = current_path
within('[role=dialog]') { click_on t('forms.buttons.continue') }
expect(current_path).not_to eq path_before_submit
end

it 'validates as case-insensitive, crockford-normalized, length-limited, dash-flexible' do
Expand All @@ -61,4 +71,8 @@
expect(current_path).not_to eq path_before_submit
end
end

def mac?
RbConfig::CONFIG['host_os'].match? 'darwin'
end
end