Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit e988316

Browse files
committed
test(input): add tests for input component and fix readonly
1 parent 979bb01 commit e988316

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

packages/chakra-ui-core/src/CInput/CInput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const CInput = {
9090
},
9191
attrs: {
9292
'aria-readonly': this.isReadOnly,
93-
'read-only': this.formControl.isReadOnly,
93+
readonly: this.formControl.isReadOnly,
9494
disabled: this.formControl.isDisabled,
9595
'aria-disabled': this.formControl.isDisabled,
9696
'aria-invalid': this.formControl.isInvalid,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { CInput } from '../..'
2+
import { render, screen, userEvent } from '@/tests/test-utils'
3+
4+
const renderComponent = (props) => {
5+
const inlineAttrs = (props && props.inlineAttrs) || ''
6+
const base = {
7+
data: () => ({ text: 'hello' }),
8+
components: { CInput },
9+
template: `<CInput data-testid="input" placeholder="input placeholder" v-model="text" ${inlineAttrs}/>`,
10+
...props
11+
}
12+
return render(base)
13+
}
14+
15+
test('should render correctly', () => {
16+
const { asFragment } = renderComponent()
17+
expect(asFragment()).toMatchSnapshot()
18+
})
19+
20+
test('v-model works', () => {
21+
renderComponent()
22+
const input = screen.getByTestId('input')
23+
24+
userEvent.type(input, ' world')
25+
expect(input).toHaveValue('hello world')
26+
})
27+
28+
test('readonly input renders correctly', () => {
29+
renderComponent({ inlineAttrs: 'isReadOnly' })
30+
const input = screen.getByTestId('input')
31+
32+
expect(input).toHaveAttribute('readonly')
33+
})
34+
35+
test('disabled input renders correctly', () => {
36+
renderComponent({ inlineAttrs: 'isDisabled' })
37+
const input = screen.getByTestId('input')
38+
39+
expect(input).toHaveAttribute('disabled')
40+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`should render correctly 1`] = `
4+
<DocumentFragment>
5+
<input
6+
class="css-fzcsno css-1l17jza"
7+
data-chakra-component="CInput"
8+
data-testid="input"
9+
placeholder="input placeholder"
10+
/>
11+
</DocumentFragment>
12+
`;

0 commit comments

Comments
 (0)