Skip to content

Commit

Permalink
test: add more test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
WodPachua committed Oct 15, 2024
1 parent 947c20c commit 5f68d39
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/components/repeat/repeat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,44 @@ describe('Repeat Component Tests', () => {
);
});
});

it('Should submit origin and cloned instances successfully', async () => {
const { methods: { setValue } } = mockContext;
setValue.mockImplementation((id, value) => {
mockContext.formFields.push({ id, value });
});

render(<Repeat field={mockField} />);

fireEvent.click(screen.getByText(/add/i));
fireEvent.click(screen.getByText(/add/i));

await waitFor(() => {
expect(mockContext.formFields.length).toBe(3);
});

expect(setValue).toHaveBeenCalledTimes(2);
expect(mockContext.formFields).toEqual(
expect.arrayContaining([
expect.objectContaining({ id: 'testField', value: undefined }),
expect.objectContaining({ id: 'testField_1', value: undefined }),
expect.objectContaining({ id: 'testField_2', value: undefined }),
])
);
});

it('Should Initialize repeat field in edit mode with instances', async () => {
const prePopulatedFields = [
{ ...mockField, id: 'testField' },
{ ...mockField, id: 'testField_1' },
];
mockContext.formFields = prePopulatedFields;

render(<Repeat field={mockField} />);

await waitFor(() => {
expect(screen.getAllByText('Test Field').length).toBe(2);
});
});

});

0 comments on commit 5f68d39

Please sign in to comment.