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

Commit 4903e14

Browse files
committed
Merge branch 'chore/merge-tests' of https://github.com/chakra-ui/chakra-ui-vue into chore/merge-tests
2 parents dfbddfb + 1d80cf4 commit 4903e14

File tree

16 files changed

+147
-170
lines changed

16 files changed

+147
-170
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
import CBox from './CBox'
22
export default CBox
3-
export * from './CBox'

packages/chakra-ui-core/src/CButtonGroup/tests/CButtonGroup.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CButton, CButtonGroup } from '../..'
2-
import { render } from '@/tests/test-utils'
2+
import { render, screen } from '@/tests/test-utils'
33

44
const renderComponent = (props) => {
55
const base = {
@@ -23,21 +23,21 @@ it('should render correctly', () => {
2323
})
2424

2525
it('should attach buttons when `is-attached` is passed', () => {
26-
const { asFragment, getByText } = renderComponent({
26+
const { asFragment } = renderComponent({
2727
template: `
2828
<CButtonGroup isAttached>
2929
<CButton>Button1</CButton>
3030
<CButton>Button2</CButton>
3131
</CButtonGroup>`
3232
})
3333

34-
const button = getByText('Button1')
34+
const button = screen.getByText('Button1')
3535
expect(button).toHaveStyle('border-top-right-radius: 0; border-bottom-right-radius: 0;')
3636
expect(asFragment()).toMatchSnapshot()
3737
})
3838

3939
it('should display children', () => {
40-
const { getByText } = renderComponent()
41-
expect(getByText('Button1')).toBeInTheDocument()
42-
expect(getByText('Button2')).toBeInTheDocument()
40+
renderComponent()
41+
expect(screen.getByText('Button1')).toBeInTheDocument()
42+
expect(screen.getByText('Button2')).toBeInTheDocument()
4343
})

packages/chakra-ui-core/src/CDivider/tests/CDivider.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import CDivider from '..'
2-
import { render } from '@/tests/test-utils'
2+
import { render, screen } from '@/tests/test-utils'
33

44
const renderComponent = (props) => {
55
const inlineAttrs = (props && props.inlineAttrs) || ''
@@ -26,9 +26,9 @@ it('should change orientation', () => {
2626

2727
it('should have corresponding aria-orientation attribute', () => {
2828
const inlineAttrs = 'orientation="horizontal"'
29-
const { asFragment, getByTestId } = renderComponent({ inlineAttrs })
29+
const { asFragment } = renderComponent({ inlineAttrs })
3030

31-
const divider = getByTestId('divider')
31+
const divider = screen.getByTestId('divider')
3232
expect(divider).toHaveAttribute('aria-orientation', 'horizontal')
3333
expect(asFragment()).toMatchSnapshot()
3434
})

packages/chakra-ui-core/src/CFormControl/tests/CFormControl.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CFormControl, CInput, CFormLabel } from '../..'
2-
import { render } from '@/tests/test-utils'
2+
import { render, screen } from '@/tests/test-utils'
33

44
const renderComponent = (props) => {
55
const inlineAttrs = (props && props.inlineAttrs) || ''
@@ -22,7 +22,7 @@ it('should render correctly', () => {
2222
})
2323

2424
it('should provide formcontrol state via scoped slot', () => {
25-
const { getByTestId } = renderComponent({
25+
renderComponent({
2626
template: `
2727
<CFormControl isRequired isReadOnly #default="props">
2828
<pre data-testid="pre">
@@ -31,7 +31,7 @@ it('should provide formcontrol state via scoped slot', () => {
3131
</CFormControl>`
3232
})
3333

34-
const pre = getByTestId('pre')
34+
const pre = screen.getByTestId('pre')
3535
expect(JSON.parse(pre.textContent, null, 2)).toEqual({
3636
isInvalid: false,
3737
isRequired: true,

packages/chakra-ui-core/src/CModal/tests/CModal.test.js

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import Vue from 'vue'
21
import { CInput, CButton, CModal, CModalOverlay, CModalContent, CModalHeader, CModalFooter, CModalBody, CModalCloseButton } from '../..'
3-
import { render, userEvent, fireEvent, waitMs } from '@/tests/test-utils'
2+
import { render, userEvent, fireEvent, waitMs, screen, wait } from '@/tests/test-utils'
43
import { useId, wrapEvent } from '@/packages/chakra-ui-core/src/utils'
54

65
// mocks
@@ -53,84 +52,87 @@ it('should render correctly', async () => {
5352
const inlineAttrs = 'isOpen'
5453
const { asFragment } = renderComponent({ inlineAttrs })
5554

56-
await Vue.nextTick()
55+
await waitMs() // render
5756

5857
expect(asFragment(document.body.innerHTML)).toMatchSnapshot()
5958
})
6059

6160
test('clicking the close button calls the onClose callback', async () => {
6261
const onClose = jest.fn()
6362
const inlineAttrs = 'isOpen :on-close="close"'
64-
const { getByTestId } = renderComponent({ inlineAttrs, methods: { close: onClose } })
63+
renderComponent({ inlineAttrs, methods: { close: onClose } })
6564

66-
await Vue.nextTick()
67-
userEvent.click(getByTestId('close-btn'))
65+
await wait(() => {
66+
userEvent.click(screen.getByTestId('close-btn'))
67+
})
6868

6969
expect(onClose).toHaveBeenCalled()
7070
})
7171

7272
test('pressing "esc" calls the onClose callback', async () => {
7373
const onClose = jest.fn()
7474
const inlineAttrs = ':isOpen="isOpen" :on-close="close"'
75-
const { getByTestId } = renderComponent({ inlineAttrs, data: () => ({ isOpen: true }), methods: { close: onClose } })
75+
renderComponent({ inlineAttrs, data: () => ({ isOpen: true }), methods: { close: onClose } })
7676

77-
await Vue.nextTick()
78-
const inputInside = getByTestId('inputInsideModal')
79-
80-
fireEvent.keyDown(inputInside, { key: 'Escape' })
77+
await wait(async () => {
78+
const inputInside = screen.getByTestId('inputInsideModal')
79+
await fireEvent.keyDown(inputInside, { key: 'Escape' })
80+
})
8181

8282
expect(onClose).toHaveBeenCalled()
8383
})
8484

8585
test('clicking overlay calls the onClose callback', async () => {
8686
const onClose = jest.fn()
8787
const inlineAttrs = ':isOpen="isOpen" :on-close="close"'
88-
const { getByTestId } = renderComponent({ inlineAttrs, data: () => ({ isOpen: true }), methods: { close: onClose } })
89-
90-
await Vue.nextTick()
91-
const overlay = getByTestId('overlay')
88+
renderComponent({ inlineAttrs, data: () => ({ isOpen: true }), methods: { close: onClose } })
9289

93-
userEvent.click(overlay)
90+
await wait(async () => {
91+
const overlay = screen.getByTestId('overlay')
92+
await fireEvent.click(overlay.parentElement)
93+
})
9494

9595
expect(onClose).toHaveBeenCalled()
9696
})
9797

9898
test('focuses the initial focus ref when opened - initialFocusRef', async () => {
9999
const inlineAttrs = 'isOpen :on-close="close" :initialFocusRef="()=>$refs.inputInsideModal"'
100-
const { getByTestId } = renderComponent({ inlineAttrs })
100+
renderComponent({ inlineAttrs })
101101

102-
await Vue.nextTick()
103-
const inputInside = getByTestId('inputInsideModal')
102+
await waitMs() // render
104103

105-
await waitMs()
106-
expect(inputInside).toHaveFocus()
104+
await wait(() => {
105+
expect(screen.getByTestId('inputInsideModal')).toHaveFocus()
106+
})
107107
})
108108

109109
test('returns focus when closed - finalFocusRef', async () => {
110110
const inlineAttrs = ':isOpen="isOpen" :on-close="close" :finalFocusRef="$refs.inputOutsideModal"'
111-
const { getByTestId } = renderComponent({ inlineAttrs, data: () => ({ isOpen: true }) })
111+
renderComponent({ inlineAttrs, data: () => ({ isOpen: true }) })
112+
113+
await waitMs() // render
112114

113-
await Vue.nextTick()
114-
const inputOutside = getByTestId('inputOutsideModal')
115-
const closeButton = getByTestId('close-btn')
115+
const inputOutside = screen.getByTestId('inputOutsideModal')
116+
const closeButton = screen.getByTestId('close-btn')
116117

117-
await userEvent.click(closeButton)
118-
await waitMs()
118+
await fireEvent.click(closeButton)
119119

120-
expect(inputOutside).toHaveFocus()
120+
await wait(() => {
121+
expect(inputOutside).toHaveFocus()
122+
})
121123
})
122124

123125
it('should have proper aria', async () => {
124126
useId.mockReturnValueOnce('1')
125127
const inlineAttrs = 'isOpen'
126128
renderComponent({ inlineAttrs })
127129

128-
await Vue.nextTick()
129-
const dialog = document.querySelector('section')
130-
await waitMs()
130+
await wait(() => {
131+
const dialog = screen.getByRole('dialog')
131132

132-
expect(dialog).toHaveAttribute('role', 'dialog')
133-
expect(dialog).toHaveAttribute('aria-modal', 'true')
134-
expect(dialog).toHaveAttribute('aria-labelledby', 'modal-1-header')
135-
expect(dialog).toHaveAttribute('aria-describedby', 'modal-1-body')
133+
expect(dialog).toHaveAttribute('role', 'dialog')
134+
expect(dialog).toHaveAttribute('aria-modal', 'true')
135+
expect(dialog).toHaveAttribute('aria-labelledby', 'modal-1-header')
136+
expect(dialog).toHaveAttribute('aria-describedby', 'modal-1-body')
137+
})
136138
})

packages/chakra-ui-core/src/CProgress/tests/CProgress.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CProgress, CProgressLabel } from '../..'
2-
import { render } from '@/tests/test-utils'
2+
import { render, screen } from '@/tests/test-utils'
33

44
const renderComponent = (props) => {
55
const base = {
@@ -19,31 +19,31 @@ it('should render correctly', () => {
1919
})
2020

2121
it('should have the correct width', () => {
22-
const { queryByRole } = renderComponent()
22+
renderComponent()
2323

24-
expect(queryByRole('progressbar')).toHaveStyle('width: 40%')
24+
expect(screen.queryByRole('progressbar')).toHaveStyle('width: 40%')
2525
})
2626

2727
it('should display a label', () => {
28-
const { queryByText } = renderComponent({
28+
renderComponent({
2929
template: `
3030
<CProgress :value="40">
3131
<CProgressLabel>Label</CProgressLabel>
3232
</CProgress>`
3333
})
3434

35-
expect(queryByText('Label')).toBeInTheDocument()
35+
expect(screen.queryByText('Label')).toBeInTheDocument()
3636
})
3737

3838
test('a11y - progress has a "role" set to "progressbar"', () => {
39-
const { queryByRole } = renderComponent()
40-
expect(queryByRole('progressbar')).toBeInTheDocument()
39+
renderComponent()
40+
expect(screen.queryByRole('progressbar')).toBeInTheDocument()
4141
})
4242

4343
test('a11y - progress has a "aria-valuenow" set to the percentage completion value', () => {
44-
const { queryByRole } = renderComponent()
44+
renderComponent()
4545

46-
expect(queryByRole('progressbar')).toHaveAttribute(
46+
expect(screen.queryByRole('progressbar')).toHaveAttribute(
4747
'aria-valuenow',
4848
'40'
4949
)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
import CPseudoBox from './CPseudoBox'
22
export default CPseudoBox
3-
export * from './CPseudoBox'

packages/chakra-ui-core/src/CPseudoBox/tests/CPseudoBox.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import CPseudoBox from '../'
2-
import { render, getTagName } from '@/tests/test-utils'
2+
import { render, getTagName, screen } from '@/tests/test-utils'
33

44
const renderComponent = (props) => {
55
const inlineAttrs = (props && props.inlineAttrs) || ''
@@ -21,9 +21,9 @@ it('should change the style', () => {
2121
d="flex" :w="['auto']" px="5" py="5" shadow="lg"
2222
my="5" mb="5" rounded="sm" font-family="body"
2323
background-color="blue.200" color="blue.700"`
24-
const { asFragment, getByTestId } = renderComponent({ inlineAttrs })
24+
const { asFragment } = renderComponent({ inlineAttrs })
2525

26-
const pseudobox = getByTestId('pseudobox')
26+
const pseudobox = screen.getByTestId('pseudobox')
2727

2828
expect(asFragment()).toMatchSnapshot()
2929
expect(pseudobox).toHaveStyle('display: flex')
@@ -46,8 +46,8 @@ it.each`
4646
'should display Box with type as $as',
4747
({ as }) => {
4848
const inlineAttrs = `as=${as}`
49-
const { asFragment, getByTestId } = renderComponent({ inlineAttrs })
50-
expect(getTagName(getByTestId('pseudobox'))).toEqual(as)
49+
const { asFragment } = renderComponent({ inlineAttrs })
50+
expect(getTagName(screen.getByTestId('pseudobox'))).toEqual(as)
5151
expect(asFragment()).toMatchSnapshot()
5252
}
5353
)
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import CRadio from '..'
2-
import { render, userEvent } from '@/tests/test-utils'
2+
import { render, userEvent, screen } from '@/tests/test-utils'
33

44
const renderComponent = (props) => {
55
const inlineAttrs = (props && props.inlineAttrs) || ''
@@ -18,52 +18,50 @@ it('should render correctly', () => {
1818

1919
it('should display a disabled radio', () => {
2020
const inlineAttrs = 'isDisabled'
21-
const { getByText, container } = renderComponent({ inlineAttrs })
22-
const input = container.querySelector('input')
21+
renderComponent({ inlineAttrs })
22+
const input = screen.getByLabelText('radio')
2323

2424
expect(input).toHaveAttribute('disabled')
25-
expect(getByText('radio').parentNode).toHaveStyle('cursor: not-allowed;')
25+
expect(input.parentNode).toHaveStyle('cursor: not-allowed;')
2626
})
2727

2828
it('should display a radio with a checked state', () => {
2929
const inlineAttrs = 'isChecked'
30-
const { container } = renderComponent({ inlineAttrs })
31-
const input = container.querySelector('input')
30+
renderComponent({ inlineAttrs })
31+
const input = screen.getByLabelText('radio')
3232

3333
expect(input).toBeChecked()
3434
})
3535

3636
it('should display a radio with an unchecked state', () => {
3737
const inlineAttrs = ':isChecked="false"'
38-
const { container } = renderComponent({ inlineAttrs })
39-
const input = container.querySelector('input')
38+
renderComponent({ inlineAttrs })
39+
const input = screen.getByLabelText('radio')
4040

4141
expect(input).not.toBeChecked()
4242
})
4343

4444
test('Uncontrolled - should not check if disabled', async () => {
4545
const inlineAttrs = 'isDisabled'
46-
const { container, getByText } = renderComponent({ inlineAttrs })
47-
const input = container.querySelector('input')
48-
const radio = getByText('radio')
46+
renderComponent({ inlineAttrs })
47+
const input = screen.getByLabelText('radio')
4948

5049
expect(input).toBeDisabled()
5150

52-
await userEvent.click(radio)
51+
await userEvent.click(input)
5352

5453
expect(input).not.toBeChecked()
5554
})
5655

5756
test('Uncontrolled - should be checked always', async () => {
58-
const { container, getByText } = renderComponent()
59-
const input = container.querySelector('input')
60-
const radio = getByText('radio')
57+
renderComponent()
58+
const input = screen.getByLabelText('radio')
6159

6260
// click the first time, it's checked
63-
await userEvent.click(radio)
61+
await userEvent.click(input)
6462
expect(input).toBeChecked()
6563

6664
// click the second time, it should be still checked
67-
await userEvent.click(radio)
65+
await userEvent.click(input)
6866
expect(input).toBeChecked()
6967
})

0 commit comments

Comments
 (0)