Skip to content

Commit

Permalink
feat: for tap sign in, automatically fill text box with badge number (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mathcolo authored Sep 11, 2024
1 parent 7dea21a commit cb617ad
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
11 changes: 9 additions & 2 deletions js/components/operatorSignIn/attestation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ export const Attestation = ({
employees,
onComplete,
loading,
prefill,
}: {
badge: string;
employees: ApiResult<Employee[]>;
onComplete: () => void;
loading: boolean;
prefill: boolean;
}): ReactElement => {
const [entered, setEntered] = useState<string>("");
const defaultValue = prefill ? badge : "";

const [entered, setEntered] = useState<string>(defaultValue);
const ready = entered === badge;

if (employees.status === "loading") {
Expand All @@ -42,7 +46,7 @@ export const Attestation = ({
<div className="text-sm">
Step 2 of 2
<SignInText />
<SignaturePrompt onChange={setEntered} />
<SignaturePrompt defaultValue={defaultValue} onChange={setEntered} />
<SignatureHint badge={badge} signatureText={entered} />
<p className="my-3">
By pressing the button below I, <b className="fs-mask">{name}</b>,
Expand Down Expand Up @@ -136,8 +140,10 @@ const SignatureHint = ({

export const SignaturePrompt = ({
onChange,
defaultValue,
}: {
onChange: (value: string) => void;
defaultValue: string;
}): ReactElement => {
return (
<div>
Expand All @@ -150,6 +156,7 @@ export const SignaturePrompt = ({
type="text"
className="w-full"
inputMode="numeric"
defaultValue={defaultValue}
onChange={(evt) => {
onChange(evt.target.value);
}}
Expand Down
1 change: 1 addition & 0 deletions js/components/operatorSignIn/operatorSignInModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ const OperatorSignInModalContent = ({
}}
/>
: <Attestation
prefill={badge.method === "nfc"}
badge={badge.number}
loading={loading}
onComplete={() => {
Expand Down
43 changes: 33 additions & 10 deletions js/test/components/operatorSignIn/attestation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe("Attestation", () => {
const view = render(
<Attestation
badge="123"
prefill={false}
onComplete={jest.fn()}
loading={false}
employees={EMPLOYEES}
Expand All @@ -29,6 +30,7 @@ describe("Attestation", () => {
const view = render(
<Attestation
badge="123"
prefill={false}
onComplete={jest.fn()}
loading={false}
employees={EMPLOYEES}
Expand All @@ -41,6 +43,7 @@ describe("Attestation", () => {
const view = render(
<Attestation
badge="00000000"
prefill={false}
onComplete={jest.fn()}
loading={false}
employees={EMPLOYEES}
Expand All @@ -49,22 +52,40 @@ describe("Attestation", () => {
expect(view.getByText("Operator #00000000")).toBeInTheDocument();
});

test("contains signature text box", () => {
const view = render(
<Attestation
badge="123"
onComplete={jest.fn()}
loading={false}
employees={EMPLOYEES}
/>,
);
expect(view.getByRole("textbox")).toBeInTheDocument();
describe("signature text box", () => {
test("it's there", () => {
const view = render(
<Attestation
badge="123"
prefill={false}
onComplete={jest.fn()}
loading={false}
employees={EMPLOYEES}
/>,
);
expect(view.getByRole("textbox")).toBeInTheDocument();
expect(view.getByRole("textbox")).toHaveValue("");
});

test("it pre-fills if requested", () => {
const view = render(
<Attestation
badge="123"
prefill={true}
onComplete={jest.fn()}
loading={false}
employees={EMPLOYEES}
/>,
);
expect(view.getByRole("textbox")).toHaveValue("123");
});
});

test("contains Complete button", () => {
const view = render(
<Attestation
badge="123"
prefill={false}
onComplete={jest.fn()}
loading={false}
employees={EMPLOYEES}
Expand All @@ -80,6 +101,7 @@ describe("Attestation", () => {
const view = render(
<Attestation
badge="123"
prefill={false}
onComplete={onComplete}
loading={false}
employees={EMPLOYEES}
Expand All @@ -101,6 +123,7 @@ describe("Attestation", () => {
const view = render(
<Attestation
badge="123"
prefill={false}
onComplete={onComplete}
loading={false}
employees={EMPLOYEES}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe("OperatorSignInModal", () => {
await userEvent.click(view.getByRole("button", { name: "OK" }));

expect(view.getByText("Step 2 of 2")).toBeInTheDocument();
expect(view.getByRole("textbox")).toHaveValue(""); // Not pre-filled if manually typed
await userEvent.type(view.getByRole("textbox"), "123");
await userEvent.click(
view.getByRole("button", { name: "Complete Fit for Duty Check" }),
Expand Down

0 comments on commit cb617ad

Please sign in to comment.