-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from keyurparalkar/release
high priorty bug fixes
- Loading branch information
Showing
10 changed files
with
4,114 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: check-unit-tests | ||
on: push | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install modules | ||
run: yarn | ||
- name: Run tests | ||
run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
|
||
"types": [ | ||
|
||
{ "type": "feat", "section": "Features" }, | ||
|
||
{ "type": "fix", "section": "Bug Fixes" }, | ||
|
||
{ "type": "chore", "hidden": true }, | ||
|
||
{ "type": "docs", "hidden": true }, | ||
|
||
{ "type": "style", "hidden": true }, | ||
|
||
{ "type": "refactor", "hidden": true }, | ||
|
||
{ "type": "perf", "hidden": true }, | ||
|
||
{ "type": "test", "hidden": true } | ||
|
||
], | ||
|
||
"commitUrlFormat": "https://github.com/keyurparalkar/react-headless-passcode/commits/{{hash}}", | ||
|
||
"compareUrlFormat": "https://github.com/keyurparalkar/react-headless-passcode/compare/{{previousTag}}...{{currentTag}}" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "jsdom", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import "@testing-library/jest-dom"; | ||
import { render, renderHook, screen, waitFor } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import usePasscode from "./usePasscode"; | ||
|
||
const TestComponent = (props: { isAlphaNumeric: boolean }) => { | ||
const { passcode, getEventHandlers, refs } = usePasscode({ | ||
count: 4, | ||
isAlphaNumeric: props.isAlphaNumeric, | ||
}); | ||
|
||
return ( | ||
<> | ||
{passcode.map((value: string | number, index: number) => ( | ||
<input | ||
ref={(el) => el && (refs.current[index] = el)} | ||
type="text" | ||
inputMode="numeric" | ||
autoComplete="one-time-code" | ||
maxLength={1} | ||
pattern="\d{1}" | ||
value={String(value)} | ||
key={`index-${index}`} | ||
data-testid={`index-${index}`} | ||
{...getEventHandlers(index)} | ||
/> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
describe("test basic workflow", () => { | ||
it("1. test whether passing count prop creates an array(input elements) with size count", () => { | ||
render(<TestComponent isAlphaNumeric={false} />); | ||
expect(screen.getAllByTestId(/index-[0-9]/)).toHaveLength(4); | ||
}); | ||
|
||
it("2. test if the focus changes to next element when typed", async () => { | ||
render(<TestComponent isAlphaNumeric={false} />); | ||
// focus on the first input | ||
const firstInput: HTMLInputElement = screen.getByTestId("index-0"); | ||
firstInput.focus(); | ||
expect(firstInput).toHaveFocus(); | ||
|
||
//Type in first input and check the focus of next input | ||
userEvent.type(firstInput, "1"); | ||
const secondtInput: HTMLInputElement = screen.getByTestId("index-1"); | ||
await waitFor(() => { | ||
expect(secondtInput).toHaveFocus(); | ||
}); | ||
}); | ||
|
||
it("3. test if the focus changes to previous element when backspaced", async () => { | ||
render(<TestComponent isAlphaNumeric={false} />); | ||
// focus on the first input | ||
const firstInput: HTMLInputElement = screen.getByTestId("index-0"); | ||
firstInput.focus(); | ||
|
||
//Type in first input and check the focus of next input | ||
userEvent.type(firstInput, "1"); | ||
const secondtInput: HTMLInputElement = screen.getByTestId("index-1"); | ||
await waitFor(() => { | ||
expect(secondtInput).toHaveFocus(); | ||
}); | ||
|
||
//Backspace and observe focus shift | ||
userEvent.keyboard("{Backspace}"); | ||
await waitFor(() => { | ||
expect(firstInput).toHaveFocus(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.