-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
19 changed files
with
372 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"basicTestId": "test-button-primary", | ||
"dummyText": "Hello there", | ||
"testStyles": { | ||
"paddingTop": "10px", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"test": { | ||
"baseConfig": { | ||
"text": "Test text" | ||
}, | ||
"colors": ["is-black", "is-danger", "is-warning"], | ||
"sizes": ["is-small", "is-medium", "is-large"], | ||
"testClasses": { | ||
"isLight": "is-light", | ||
"isRounded": "is-rounded" | ||
}, | ||
"addonConfig": { | ||
"withAddon": true, | ||
"addonText": "Addon Text" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react' | ||
import { ComponentStory, ComponentMeta } from '@storybook/react' | ||
// COMPONENTS | ||
import Tag from '.' | ||
// MOCKS | ||
import mocks from './index.mocks.json' | ||
|
||
export default { | ||
title: 'Atoms/Tag', | ||
component: Tag | ||
} as ComponentMeta<typeof Tag> | ||
|
||
const Template: ComponentStory<typeof Tag> = args => <Tag {...args} /> | ||
|
||
export const BasicExample = Template.bind({}) | ||
BasicExample.storyName = 'With a text' | ||
BasicExample.args = { ...mocks.test.baseConfig } | ||
|
||
export const Colored = Template.bind({}) | ||
Colored.storyName = 'Colored' | ||
Colored.args = { | ||
...BasicExample.args, | ||
color: 'is-danger' | ||
} | ||
|
||
export const Rounded = Template.bind({}) | ||
Rounded.storyName = 'Rounded' | ||
Rounded.args = { | ||
...Colored.args, | ||
isRounded: true | ||
} | ||
|
||
export const Light = Template.bind({}) | ||
Light.storyName = 'Light color' | ||
Light.args = { | ||
...Colored.args, | ||
isLight: true | ||
} | ||
|
||
export const LargeSize = Template.bind({}) | ||
LargeSize.storyName = 'Large Size' | ||
LargeSize.args = { | ||
...Colored.args, | ||
size: 'is-large' | ||
} | ||
|
||
export const WithDelete = Template.bind({}) | ||
WithDelete.storyName = 'With a Delete' | ||
WithDelete.args = { | ||
...Colored.args, | ||
withDelete: true | ||
} | ||
|
||
export const WithAddon = Template.bind({}) | ||
WithAddon.storyName = 'With an Addon' | ||
WithAddon.args = { | ||
...Colored.args, | ||
withAddon: true, | ||
addonText: 'Addon' | ||
} | ||
|
||
export const ColoredAddon = Template.bind({}) | ||
ColoredAddon.storyName = 'Colored Addon' | ||
ColoredAddon.args = { | ||
...WithAddon.args, | ||
addonColor: 'is-info' | ||
} | ||
|
||
export const WithDeleteAddon = Template.bind({}) | ||
WithDeleteAddon.storyName = 'With a Delete Addon' | ||
WithDeleteAddon.args = { | ||
...WithAddon.args, | ||
withDelete: true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React from 'react' | ||
import { cleanup, fireEvent, render, screen } from '@testing-library/react' | ||
import '@testing-library/jest-dom' | ||
// COMPONENT | ||
import Tag from '.' | ||
// TYPES & INTERFACES | ||
import { basicColorType, sizeType } from '../../../types/styleTypes' | ||
import { TagProps } from '../../../interfaces/atomProps' | ||
// MOCKS | ||
import mocks from './index.mocks.json' | ||
|
||
describe('Tag', () => { | ||
const { baseConfig, colors, testClasses, addonConfig, sizes } = mocks.test | ||
let tagConfig: TagProps = baseConfig | ||
|
||
test('Should render with required props only', () => { | ||
render(<Tag {...tagConfig} />) | ||
const testTag = screen.getByText(tagConfig.text) | ||
expect(testTag).toBeInTheDocument() | ||
}) | ||
|
||
test('Should render with different colors', () => { | ||
colors.forEach(_color => { | ||
const coloredTestId = `test-tag-${_color.replace('is-', '')}` | ||
render(<Tag {...{ ...baseConfig, color: _color as basicColorType }} />) | ||
const testColorTag = screen.getByTestId(coloredTestId) | ||
expect(testColorTag.classList).toContain(_color) | ||
}) | ||
}) | ||
|
||
test('Should render with different sizes', () => { | ||
sizes.forEach(_size => { | ||
const coloredTestId = `test-tag-${_size.replace('is-', '')}` | ||
render( | ||
<Tag | ||
{...{ ...baseConfig, size: _size as Exclude<sizeType, 'is-normal'> }} | ||
/> | ||
) | ||
const testColorTag = screen.getByTestId(coloredTestId) | ||
expect(testColorTag.classList).toContain(_size) | ||
}) | ||
}) | ||
|
||
test('Should render with different classes', () => { | ||
Object.keys(testClasses).forEach(prop => { | ||
const classValue = (testClasses as any)[prop] | ||
const testIdWithClass = `test-tag-${classValue.replace('is-', '')}` | ||
render(<Tag {...{ ...baseConfig, [prop]: classValue }} />) | ||
const classButton = screen.getByTestId(testIdWithClass) | ||
expect(classButton.className).toContain(classValue) | ||
cleanup() | ||
}) | ||
}) | ||
|
||
test('Should check that its delete button has been clicked', () => { | ||
tagConfig = { ...baseConfig, withDelete: true, onDeleteClick: jest.fn() } | ||
render(<Tag {...tagConfig} />) | ||
const clickButton = screen.getByTestId('test-tag-delete') | ||
fireEvent.click(clickButton) | ||
expect(tagConfig.onDeleteClick).toHaveBeenCalled() | ||
expect(tagConfig.onDeleteClick).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
test('Should render the tags variation with its addon text', () => { | ||
const tagsTestId = 'test-tags-has-addons' | ||
render(<Tag {...{ ...baseConfig, ...addonConfig }} />) | ||
const testTags = screen.getByTestId(tagsTestId) | ||
expect(testTags).toBeInTheDocument() | ||
}) | ||
|
||
test('Should check that its delete button has been clicked with the tags variation', () => { | ||
tagConfig = { | ||
...baseConfig, | ||
withAddon: true, | ||
withDelete: true, | ||
onDeleteClick: jest.fn() | ||
} | ||
render(<Tag {...tagConfig} />) | ||
const clickButton = screen.getByTestId('test-tags-has-addons-delete') | ||
fireEvent.click(clickButton) | ||
expect(tagConfig.onDeleteClick).toHaveBeenCalled() | ||
expect(tagConfig.onDeleteClick).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |
Oops, something went wrong.