agroptima-design-system 0.32.3-beta.0 → 0.32.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import { render, screen } from '@testing-library/react'
|
|
|
2
2
|
import userEvent from '@testing-library/user-event'
|
|
3
3
|
import React from 'react'
|
|
4
4
|
import { Multiselect } from '../src/atoms/Multiselect'
|
|
5
|
-
import type
|
|
5
|
+
import { type Option, Select } from '../src/atoms/Select'
|
|
6
6
|
|
|
7
7
|
const zelda = {
|
|
8
8
|
id: '1',
|
|
@@ -112,7 +112,7 @@ describe('Multiselect', () => {
|
|
|
112
112
|
/>,
|
|
113
113
|
)
|
|
114
114
|
|
|
115
|
-
await user.click(screen.getByRole('button', { name: /
|
|
115
|
+
await user.click(screen.getByRole('button', { name: /clear/i }))
|
|
116
116
|
|
|
117
117
|
expect(getByText(placeholder)).toBeInTheDocument()
|
|
118
118
|
expect(mockChange).toHaveBeenCalledWith([])
|
|
@@ -143,4 +143,46 @@ describe('Multiselect', () => {
|
|
|
143
143
|
expect(queryByText('Spyro the Dragon')).not.toBeInTheDocument()
|
|
144
144
|
expect(queryByText('Halo')).not.toBeInTheDocument()
|
|
145
145
|
})
|
|
146
|
+
|
|
147
|
+
it('deselects when click on deselect button', async () => {
|
|
148
|
+
const user = userEvent.setup()
|
|
149
|
+
const placeholder = 'Select your favourite gaming system...'
|
|
150
|
+
const handleSubmit = jest.fn()
|
|
151
|
+
|
|
152
|
+
render(
|
|
153
|
+
<form onSubmit={handleSubmit}>
|
|
154
|
+
<Multiselect
|
|
155
|
+
label="Videogames"
|
|
156
|
+
name="select-videogames"
|
|
157
|
+
placeholder="Select your favourite gaming system..."
|
|
158
|
+
defaultValue={[zelda.id]}
|
|
159
|
+
options={OPTIONS}
|
|
160
|
+
/>
|
|
161
|
+
</form>,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
await user.click(screen.getByLabelText(/clear/i))
|
|
165
|
+
|
|
166
|
+
expect(screen.getByLabelText('Videogames')).toHaveTextContent(placeholder)
|
|
167
|
+
expect(handleSubmit).toHaveBeenCalledTimes(0)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('disables deselect button when is disabled', async () => {
|
|
171
|
+
const user = userEvent.setup()
|
|
172
|
+
render(
|
|
173
|
+
<Multiselect
|
|
174
|
+
disabled
|
|
175
|
+
label="Videogames"
|
|
176
|
+
name="select-videogames"
|
|
177
|
+
defaultValue={[zelda.id]}
|
|
178
|
+
options={OPTIONS}
|
|
179
|
+
/>,
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
await user.click(screen.getByLabelText(/clear/i))
|
|
183
|
+
|
|
184
|
+
expect(screen.getByLabelText('Videogames')).toHaveTextContent(
|
|
185
|
+
/1 items selected/i,
|
|
186
|
+
)
|
|
187
|
+
})
|
|
146
188
|
})
|
package/tests/Select.spec.tsx
CHANGED
|
@@ -100,7 +100,7 @@ describe('Select', () => {
|
|
|
100
100
|
/>,
|
|
101
101
|
)
|
|
102
102
|
|
|
103
|
-
await user.click(screen.getByRole('button', { name: /
|
|
103
|
+
await user.click(screen.getByRole('button', { name: /clear/i }))
|
|
104
104
|
|
|
105
105
|
expect(getByText(placeholder)).toBeInTheDocument()
|
|
106
106
|
expect(mockChange).toHaveBeenCalledWith('')
|
|
@@ -124,4 +124,46 @@ describe('Select', () => {
|
|
|
124
124
|
expect(queryByText('Nintendo Switch')).not.toBeInTheDocument()
|
|
125
125
|
expect(queryByText('Xbox Series S/X')).not.toBeInTheDocument()
|
|
126
126
|
})
|
|
127
|
+
it('deselects when click on deselect button', async () => {
|
|
128
|
+
const user = userEvent.setup()
|
|
129
|
+
const placeholder = 'Select your favourite gaming system...'
|
|
130
|
+
const handleSubmit = jest.fn()
|
|
131
|
+
|
|
132
|
+
render(
|
|
133
|
+
<form onSubmit={handleSubmit}>
|
|
134
|
+
<Select
|
|
135
|
+
label="Videogames"
|
|
136
|
+
name="select-videogames"
|
|
137
|
+
isSearchable
|
|
138
|
+
placeholder={placeholder}
|
|
139
|
+
defaultValue={playstation5.id}
|
|
140
|
+
options={OPTIONS}
|
|
141
|
+
/>
|
|
142
|
+
</form>,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
await user.click(screen.getByLabelText(/clear/i))
|
|
146
|
+
|
|
147
|
+
expect(screen.getByLabelText('Videogames')).toHaveTextContent(placeholder)
|
|
148
|
+
expect(handleSubmit).toHaveBeenCalledTimes(0)
|
|
149
|
+
})
|
|
150
|
+
it('disables deselect button when is disabled', async () => {
|
|
151
|
+
const user = userEvent.setup()
|
|
152
|
+
render(
|
|
153
|
+
<Select
|
|
154
|
+
label="Videogames"
|
|
155
|
+
name="select-videogames"
|
|
156
|
+
isSearchable
|
|
157
|
+
disabled
|
|
158
|
+
defaultValue={playstation5.id}
|
|
159
|
+
options={OPTIONS}
|
|
160
|
+
/>,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
await user.click(screen.getByLabelText(/clear/i))
|
|
164
|
+
|
|
165
|
+
expect(screen.getByLabelText('Videogames')).toHaveTextContent(
|
|
166
|
+
playstation5.label,
|
|
167
|
+
)
|
|
168
|
+
})
|
|
127
169
|
})
|