Skip to content

Commit

Permalink
feat: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kostasdano committed Oct 13, 2023
1 parent fe240ae commit accbe28
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/components/Tag/Tag.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import { fireEvent, render } from '../../test';

import Tag from './Tag';

const handleSelect = jest.fn();
const handleClear = jest.fn();

describe('Tag', () => {
test('that on selectable Tag the onSelect handler is being called', () => {
const { getByTestId } = render(
<Tag onSelect={handleSelect} dataTestPrefixId="test">
Tag
</Tag>
);

const tag = getByTestId('test_tag_container');
expect(tag).toBeInTheDocument();

fireEvent.click(tag);

expect(handleSelect).toHaveBeenCalledTimes(1);
});

test('that selectable Tag is rendered correctly when selected', () => {
const { getByTestId } = render(
<Tag onSelect={handleSelect} isSelected dataTestPrefixId="test">
Tag
</Tag>
);
const tag = getByTestId('test_tag_container');
expect(tag).toBeInTheDocument();

const tagCheck = getByTestId('test_tag_prefix');
expect(tagCheck).toBeInTheDocument();
});

test('that on clearable Tag the onClear handler is being called', () => {
const { getByTestId } = render(
<Tag onClear={handleClear} dataTestPrefixId="test">
Tag
</Tag>
);
const tag = getByTestId('test_tag_container');
expect(tag).toBeInTheDocument();

const tagClear = getByTestId('test_tag_suffix');
expect(tagClear).toBeInTheDocument();

fireEvent.click(tagClear);

expect(handleClear).toHaveBeenCalledTimes(1);
});
});

0 comments on commit accbe28

Please sign in to comment.