Skip to content

Commit 3269d71

Browse files
committed
Add a test to check for hook to run only on single row
1 parent 6b8b4da commit 3269d71

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

src/steps/ValidationStep/tests/ValidationStep.test.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,72 @@ describe("Validation step tests", () => {
623623
expect(newLastNameCell).toBeInTheDocument()
624624
})
625625

626+
test("Row hook only runs on a single row", async () => {
627+
const NAME = "John"
628+
const NEW_NAME = "Kate"
629+
const LAST_NAME = "Doe"
630+
const initialData = [
631+
{
632+
name: NAME,
633+
lastName: LAST_NAME,
634+
},
635+
{
636+
name: "Johnny",
637+
lastName: "Doeson",
638+
},
639+
]
640+
const fields = [
641+
{
642+
label: "Name",
643+
key: "name",
644+
fieldType: {
645+
type: "input",
646+
},
647+
},
648+
{
649+
label: "lastName",
650+
key: "lastName",
651+
fieldType: {
652+
type: "input",
653+
},
654+
},
655+
] as const
656+
657+
const mockedHook = jest.fn((a) => a)
658+
await act(async () => {
659+
render(
660+
<Providers
661+
theme={defaultTheme}
662+
rsiValues={{
663+
...mockValues,
664+
fields,
665+
rowHook: mockedHook,
666+
}}
667+
>
668+
<ModalWrapper isOpen={true} onClose={() => {}}>
669+
<ValidationStep initialData={initialData} file={file} />
670+
</ModalWrapper>
671+
</Providers>,
672+
)
673+
})
674+
675+
// initially row hook is called for each row
676+
expect(mockedHook.mock.calls.length).toBe(2)
677+
678+
const nameCell = screen.getByRole("gridcell", {
679+
name: NAME,
680+
})
681+
expect(nameCell).toBeInTheDocument()
682+
683+
// activate input
684+
await userEvent.click(nameCell)
685+
686+
await userEvent.keyboard(NEW_NAME + "{enter}")
687+
688+
expect(mockedHook.mock.calls[2][0]?.name).toBe(NEW_NAME)
689+
expect(mockedHook.mock.calls.length).toBe(3)
690+
})
691+
626692
test("Row hook raises error", async () => {
627693
const WRONG_NAME = "Johnny"
628694
const RIGHT_NAME = "Jonathan"

0 commit comments

Comments
 (0)