Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added data-tag attribute to passageCard #1493

Merged
merged 4 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/components/passage/__tests__/passage-card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 5,7 @@ import * as React from 'react';
import {fakePassage} from '../../../test-util';
import {passageIsEmpty} from '../../../util/passage-is-empty';
import {PassageCard, PassageCardProps} from '../passage-card';
import {lorem} from 'faker';

jest.mock('../../tag/tag-stripe');
jest.mock('../../../util/passage-is-empty');
Expand Down Expand Up @@ -32,6 33,25 @@ describe('<PassageCard>', () => {
);
}

it('should include data-passage-tag attribute with space-separated tags', () => {
const tags = [lorem.slug(), lorem.slug()];
const passage = fakePassage({tags});
renderComponent({passage});

// eslint-disable-next-line testing-library/no-node-access
const passageElement=document.querySelector('.passage-card')
expect(passageElement).toHaveAttribute('data-passage-tags', tags.join(' '));
});

it('should include data-passage-tag with an empty string when passage has no tags', () => {
const passage = fakePassage({tags:[]});
renderComponent({passage});

// eslint-disable-next-line testing-library/no-node-access
const passageElement=document.querySelector('.passage-card')
expect(passageElement).toHaveAttribute('data-passage-tags', '');
});

it('displays the passage name', () => {
const passage = fakePassage();

Expand Down
4 changes: 2 additions & 2 deletions src/components/passage/passage-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 107,7 @@ export const PassageCard: React.FC<PassageCardProps> = React.memo(props => {
onDrag={onDrag}
onStop={onDragStop}
>
<div className={className} ref={container} style={style}>
<div className={className} ref={container} style={style} data-passage-tags={passage.tags.join(' ')}>
<SelectableCard
highlighted={passage.highlighted}
label={passage.name}
Expand All @@ -124,4 124,4 @@ export const PassageCard: React.FC<PassageCardProps> = React.memo(props => {
);
});

PassageCard.displayName = 'PassageCard';
PassageCard.displayName = 'PassageCard';
Loading