Skip to content

Commit

Permalink
tag component housekeeping (#16355)
Browse files Browse the repository at this point in the history
* tag component housekeeping

* added snapshot testing
  • Loading branch information
NidhiKJha authored Nov 3, 2022
1 parent 8bdf820 commit 58da1d8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ui/components/component-library/tag/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ The `Tag` accepts all props below as well as all [Box](/docs/ui-components-ui-bo
### Label

The text content of the `Tag` component

<Canvas>
<Story id="ui-components-component-library-tag-tag-stories-js--label" />
</Canvas>
16 changes: 16 additions & 0 deletions ui/components/component-library/tag/__snapshots__/tag.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Tag should render the label inside the tag and match snapshot 1`] = `
<div>
<div
class="box mm-tag box--padding-right-1 box--padding-left-1 box--display-inline-block box--flex-direction-row box--justify-content-center box--align-items-center box--background-color-background-default box--rounded-pill box--border-color-border-default box--border-width-1 box--border-style-solid"
data-testid="tag"
>
<p
class="box text text--body-sm text--color-text-default box--flex-direction-row"
>
Imported
</p>
</div>
</div>
`;
6 changes: 5 additions & 1 deletion ui/components/component-library/tag/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
export const Tag = ({ label, className, labelProps, ...props }) => {
return (
<Box
className={classnames('tag', className)}
className={classnames('mm-tag', className)}
backgroundColor={COLORS.BACKGROUND_DEFAULT}
borderColor={COLORS.BORDER_DEFAULT}
borderWidth={1}
Expand Down Expand Up @@ -47,4 +47,8 @@ Tag.propTypes = {
* Additional classNames to be added to the Tag component
*/
className: PropTypes.string,
/**
* Tag also accepts all props from Box
*/
...Box.propTypes,
};
2 changes: 1 addition & 1 deletion ui/components/component-library/tag/tag.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.tag {
.mm-tag {
height: auto;
width: max-content;
padding-top: 1px;
Expand Down
6 changes: 6 additions & 0 deletions ui/components/component-library/tag/tag.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ export default {
export const DefaultStory = (args) => <Tag {...args} />;

DefaultStory.storyName = 'Default';

export const Label = (args) => <Tag {...args}>Anchor Element</Tag>;

Label.args = {
label: 'Label Story',
};
7 changes: 5 additions & 2 deletions ui/components/component-library/tag/tag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import React from 'react';
import { Tag } from './tag';

describe('Tag', () => {
it('should render the label inside the tag', () => {
const { getByTestId } = render(<Tag data-testid="tag" label="Imported" />);
it('should render the label inside the tag and match snapshot', () => {
const { getByTestId, container } = render(
<Tag data-testid="tag" label="Imported" />,
);
expect(getByTestId('tag')).toBeDefined();
expect(getByTestId('tag')).toHaveTextContent('Imported');
expect(container).toMatchSnapshot();
});
});

0 comments on commit 58da1d8

Please sign in to comment.