This repository was archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 139
Bugfix/story issues #51
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
81b0aa7
chore(storybook): add width and height to story canvas
koca 428d0fb
fix(storybook): refactor progress story
koca 0394727
test(radio): add tests for Radio component
koca 8de8fd0
chore(radio-group): fix radio group stories
koca 9c0890e
fix(radio-button-group): clean RadioButtonGroup children
koca f032e09
test(radio-button-group): add tests for RadioButtonGroup component
koca 70fd1cf
fix(select): fix select slot issue
koca 3f5e067
fix(radio): remove defaultchecked from attrs
koca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,45 +1,35 @@ | ||
import { storiesOf } from '@storybook/vue' | ||
import { CSSReset, Progress as KProgress, Stack } from '..' | ||
import { CSSReset, Progress as KProgress, Stack, Box } from '..' | ||
|
||
storiesOf('UI | Progress', module) | ||
.add('Default Progress', () => ({ | ||
components: { CSSReset, KProgress }, | ||
.addDecorator(story => ({ | ||
components: { CSSReset, Box, story: story() }, | ||
template: ` | ||
<div> | ||
<CSSReset /> | ||
<KProgress :value="80" /> | ||
</div> | ||
` | ||
<Box w="full" maxWidth="400px" mx="auto" mt="8" p="3"> | ||
<CSSReset></CSSReset> | ||
<story></story> | ||
koca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Box>` | ||
})) | ||
|
||
.add('Default Progress', () => ({ | ||
components: { KProgress }, | ||
template: `<KProgress :value="80" />` | ||
})) | ||
.add('With stripe', () => ({ | ||
components: { CSSReset, KProgress }, | ||
template: ` | ||
<div> | ||
<CSSReset /> | ||
<KProgress hasStripe :value="64" /> | ||
</div> | ||
` | ||
components: { KProgress }, | ||
template: `<KProgress hasStripe :value="64" />` | ||
})) | ||
.add('With sizes', () => ({ | ||
components: { CSSReset, KProgress, Stack }, | ||
components: { KProgress, Stack }, | ||
template: ` | ||
<div> | ||
<CSSReset /> | ||
<Stack :spacing="5"> | ||
<KProgress rounded="sm" color="green" size="sm" /> | ||
<KProgress color="green" size="md" /> | ||
<KProgress color="green" size="lg" /> | ||
<KProgress color="green" height="32px" /> | ||
</Stack> | ||
</div> | ||
` | ||
<Stack :spacing="5"> | ||
<KProgress rounded="sm" color="green" size="sm" /> | ||
<KProgress color="green" size="md" /> | ||
<KProgress color="green" size="lg" /> | ||
<KProgress color="green" height="32px" /> | ||
</Stack>` | ||
})) | ||
.add('With color', () => ({ | ||
components: { CSSReset, KProgress }, | ||
template: ` | ||
<div> | ||
<CSSReset /> | ||
<KProgress color="pink" hasStripe /> | ||
</div> | ||
` | ||
components: { KProgress }, | ||
template: `<KProgress color="pink" hasStripe />` | ||
})) |
This file contains hidden or 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 hidden or 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,77 @@ | ||
import Radio from '../' | ||
import { render, userEvent } from '@/tests/test-utils' | ||
|
||
const renderComponent = (props) => { | ||
const inlineAttrs = (props && props.inlineAttrs) || '' | ||
const base = { | ||
components: { Radio }, | ||
template: `<Radio ${inlineAttrs}>radio</Radio>`, | ||
...props | ||
} | ||
return render(base) | ||
} | ||
|
||
it('should render correctly', () => { | ||
const { asFragment } = renderComponent() | ||
expect(asFragment()).toMatchSnapshot() | ||
}) | ||
|
||
it('should display a disabled radio', () => { | ||
const inlineAttrs = 'isDisabled' | ||
const { getByText, container } = renderComponent({ inlineAttrs }) | ||
const input = container.querySelector('input') | ||
|
||
expect(input).toHaveAttribute('disabled') | ||
expect(getByText('radio').parentNode).toHaveStyle('cursor: not-allowed;') | ||
}) | ||
|
||
it('should display a radio with a checked state', () => { | ||
const inlineAttrs = 'defaultIsChecked' | ||
const { container } = renderComponent({ inlineAttrs }) | ||
const input = container.querySelector('input') | ||
|
||
expect(input).toBeChecked() | ||
}) | ||
|
||
it('should display a radio with an unchecked state', () => { | ||
const inlineAttrs = ':isChecked="false"' | ||
const { container } = renderComponent({ inlineAttrs }) | ||
const input = container.querySelector('input') | ||
|
||
expect(input).not.toBeChecked() | ||
}) | ||
|
||
it('should have a checked state when setting defaultIsChecked', () => { | ||
const inlineAttrs = 'defaultIsChecked' | ||
const { container } = renderComponent({ inlineAttrs }) | ||
const input = container.querySelector('input') | ||
|
||
expect(input).toBeChecked() | ||
}) | ||
|
||
test('Uncontrolled - should not check if disabled', async () => { | ||
const inlineAttrs = 'isDisabled' | ||
const { container, getByText } = renderComponent({ inlineAttrs }) | ||
const input = container.querySelector('input') | ||
const radio = getByText('radio') | ||
|
||
expect(input).toBeDisabled() | ||
|
||
await userEvent.click(radio) | ||
|
||
expect(input).not.toBeChecked() | ||
}) | ||
|
||
test('Uncontrolled - should be checked always', async () => { | ||
const { container, getByText } = renderComponent() | ||
const input = container.querySelector('input') | ||
const radio = getByText('radio') | ||
|
||
// click the first time, it's checked | ||
await userEvent.click(radio) | ||
expect(input).toBeChecked() | ||
|
||
// click the second time, it should be still checked | ||
await userEvent.click(radio) | ||
expect(input).toBeChecked() | ||
}) | ||
codebender828 marked this conversation as resolved.
Show resolved
Hide resolved
|
27 changes: 27 additions & 0 deletions
27
packages/chakra-ui-core/src/Radio/tests/__snapshots__/Radio.test.js.snap
This file contains hidden or 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,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should render correctly 1`] = ` | ||
<DocumentFragment> | ||
<label | ||
class="css-1qf83f9" | ||
> | ||
<input | ||
class="css-0 css-f8n5zr" | ||
type="radio" | ||
/> | ||
<div | ||
aria-hidden="true" | ||
class="css-1kfhqjz css-aufuif" | ||
> | ||
<span | ||
class="css-1qfw50u" | ||
/> | ||
</div> | ||
<div | ||
class="css-np4rym" | ||
> | ||
radio | ||
</div> | ||
</label> | ||
</DocumentFragment> | ||
`; |
This file contains hidden or 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 hidden or 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
76 changes: 76 additions & 0 deletions
76
packages/chakra-ui-core/src/RadioButtonGroup/tests/RadioButtonGroup.test.js
This file contains hidden or 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,76 @@ | ||
import { Button, Radio, RadioGroup, RadioButtonGroup } from '../../' | ||
import { render, defaultProviders } from '@/tests/test-utils' | ||
|
||
// mocks | ||
jest.mock('breadstick/dist/components/Alert/styles.css', () => ({})) // jest tries to import styles and fails... | ||
|
||
const CustomRadio = { | ||
name: 'CustomRadio', | ||
props: { | ||
isChecked: Boolean, | ||
isDisabled: Boolean, | ||
value: [String, Number], | ||
mx: String, | ||
dataTestid: String | ||
}, | ||
inheritAttrs: true, | ||
render (h) { | ||
return h(Button, { | ||
props: { | ||
...this.$props, | ||
isDisabled: this.isDisabled, | ||
variantColor: this.isChecked ? 'red' : 'gray' | ||
}, | ||
attrs: { | ||
role: 'radio', | ||
'aria-checked': this.isChecked, | ||
'data-testid': this.dataTestid | ||
} | ||
}, this.$slots.default) | ||
} | ||
} | ||
|
||
const renderComponent = (props) => { | ||
const base = { | ||
components: { Button, Radio, RadioGroup, RadioButtonGroup, CustomRadio }, | ||
provide: () => defaultProviders(), | ||
template: ` | ||
<RadioButtonGroup defaultValue="item-2" isInline> | ||
<CustomRadio value="item-1" data-testid="item-1">Custom Radio 1</CustomRadio> | ||
<CustomRadio value="item-2" data-testid="item-2">Custom Radio 2</CustomRadio> | ||
<CustomRadio value="item-3" data-testid="item-3">Custom Radio 3</CustomRadio> | ||
<CustomRadio isDisabled value="item-4" data-testid="item-4">Custom Radio 4</CustomRadio> | ||
</RadioButtonGroup> | ||
`, | ||
...props | ||
} | ||
return render(base) | ||
} | ||
|
||
it('should render correctly', () => { | ||
const { asFragment } = renderComponent() | ||
|
||
expect(asFragment()).toMatchSnapshot() | ||
}) | ||
|
||
it('should display children', () => { | ||
const { getByText } = renderComponent() | ||
expect(getByText('Custom Radio 1')).toBeInTheDocument() | ||
expect(getByText('Custom Radio 2')).toBeInTheDocument() | ||
}) | ||
|
||
test('defaultValue works', () => { | ||
const { getByTestId } = renderComponent() | ||
const one = getByTestId('item-1') | ||
const two = getByTestId('item-2') | ||
|
||
expect(one).not.toHaveAttribute('aria-checked') | ||
expect(two).toHaveAttribute('aria-checked', 'true') | ||
}) | ||
|
||
test('CustomRadio isDisabled works', () => { | ||
const { getByTestId } = renderComponent() | ||
const last = getByTestId('item-4') | ||
|
||
expect(last).toHaveAttribute('disabled') | ||
}) |
50 changes: 50 additions & 0 deletions
50
...ges/chakra-ui-core/src/RadioButtonGroup/tests/__snapshots__/RadioButtonGroup.test.js.snap
This file contains hidden or 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,50 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should render correctly 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="css-0" | ||
role="radiogroup" | ||
> | ||
<button | ||
class="css-0 css-rup5mm" | ||
data-testid="item-1" | ||
role="radio" | ||
tabindex="-1" | ||
type="button" | ||
> | ||
Custom Radio 1 | ||
</button> | ||
<button | ||
aria-checked="true" | ||
class="css-0 css-1f3kv3a" | ||
data-testid="item-2" | ||
role="radio" | ||
tabindex="0" | ||
type="button" | ||
> | ||
Custom Radio 2 | ||
</button> | ||
<button | ||
class="css-0 css-rup5mm" | ||
data-testid="item-3" | ||
role="radio" | ||
tabindex="-1" | ||
type="button" | ||
> | ||
Custom Radio 3 | ||
</button> | ||
<button | ||
aria-disabled="true" | ||
class="css-0 css-rup5mm" | ||
data-testid="item-4" | ||
disabled="disabled" | ||
role="radio" | ||
tabindex="-1" | ||
type="button" | ||
> | ||
Custom Radio 4 | ||
</button> | ||
</div> | ||
</DocumentFragment> | ||
`; |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.