Skip to content

Commit

Permalink
Merge pull request #58 from suisin-deriv/suisin/93479/test_case_for_j…
Browse files Browse the repository at this point in the history
…urisdiction_clickable_description

Suisin/chore: test case for jurisdiction clickable description
  • Loading branch information
matin-deriv committed Apr 27, 2023
2 parents 39a96c6 + 071ce45 commit de37b21
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import JurisdictionClickableDescription from '../jurisdiction-clickable-description';

describe('JurisdictionClickableDescription', () => {
type TClickableDescription = { text: string; type: 'link' | 'text' };
type TMockProps = {
clickable_description: TClickableDescription[];
toggleCardFlip: jest.Mock;
};

const mock_props: TMockProps = {
clickable_description: [
{
text: 'Click here',
type: 'link',
},
{
text: 'to learn more about the documents required for verification.',
type: 'text',
},
],
toggleCardFlip: jest.fn(),
};

it('should render JurisdictionClickableDescription', () => {
render(<JurisdictionClickableDescription {...mock_props} />);
const container = screen.getByTestId('dt_jurisdiction_clickable_description');
expect(container).toHaveClass('cfd-card-clickable-description-link');
expect(screen.getByText('Click here')).toBeInTheDocument();
expect(screen.getByText('to learn more about the documents required for verification.')).toBeInTheDocument();
});

it('should call toggleCardFlip when link is clicked', () => {
render(<JurisdictionClickableDescription {...mock_props} />);
screen.getByText('Click here').click();
expect(mock_props.toggleCardFlip).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ const JurisdictionClickableDescription = ({
{clickable_description.map(description_part => {
return description_part.type === 'link' ? (
<span key={description_part.text} onClick={toggleCardFlip}>
<Text as='span' size='xxs' className='cfd-card-clickable-description-link'>
<Text
data-testid='dt_jurisdiction_clickable_description'
as='span'
size='xxs'
className='cfd-card-clickable-description-link'
>
{description_part.text}
</Text>
&nbsp;
Expand Down

0 comments on commit de37b21

Please sign in to comment.