Skip to content

Commit 2cd797b

Browse files
committed
Add test and story for SelectArrayInput
1 parent 8644e32 commit 2cd797b

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

packages/ra-ui-materialui/src/input/SelectArrayInput.spec.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ describe('<SelectArrayInput />', () => {
228228
expect(screen.queryByText('Programming')).not.toBeNull();
229229
});
230230

231-
it('should render disable choices marked so', () => {
231+
it('should render disable choices marked as so', () => {
232232
render(
233233
<AdminContext dataProvider={testDataProvider()}>
234234
<ResourceContextProvider value="posts">
@@ -254,6 +254,37 @@ describe('<SelectArrayInput />', () => {
254254
expect(option2.getAttribute('aria-disabled')).toEqual('true');
255255
});
256256

257+
it('should render disabled choices marked as so by disableValue prop', () => {
258+
render(
259+
<AdminContext dataProvider={testDataProvider()}>
260+
<ResourceContextProvider value="posts">
261+
<SimpleForm onSubmit={jest.fn()}>
262+
<SelectArrayInput
263+
{...defaultProps}
264+
choices={[
265+
{ id: 'ang', name: 'Angular' },
266+
{
267+
id: 'rea',
268+
name: 'React',
269+
not_available: true,
270+
},
271+
]}
272+
disableValue="not_available"
273+
/>
274+
</SimpleForm>
275+
</ResourceContextProvider>
276+
</AdminContext>
277+
);
278+
fireEvent.mouseDown(
279+
screen.getByLabelText('resources.posts.fields.categories')
280+
);
281+
const option1 = screen.getByText('Angular');
282+
expect(option1.getAttribute('aria-disabled')).toBeNull();
283+
284+
const option2 = screen.getByText('React');
285+
expect(option2.getAttribute('aria-disabled')).toEqual('true');
286+
});
287+
257288
describe('translateChoice', () => {
258289
it('should translate the choices by default', async () => {
259290
render(<TranslateChoice />);

packages/ra-ui-materialui/src/input/SelectArrayInput.stories.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { ReferenceArrayInput } from './ReferenceArrayInput';
2626
import { SelectArrayInput } from './SelectArrayInput';
2727
import { TextInput } from './TextInput';
2828
import { useCreateSuggestionContext } from './useSupportCreateSuggestion';
29+
import { SelectInput } from './SelectInput';
2930

3031
export default { title: 'ra-ui-materialui/input/SelectArrayInput' };
3132

@@ -167,6 +168,20 @@ export const Disabled = () => (
167168
</AdminContext>
168169
);
169170

171+
export const DisabledChoice = () => (
172+
<Wrapper>
173+
<SelectArrayInput
174+
source="roles"
175+
choices={[
176+
{ id: 'admin', name: 'Admin' },
177+
{ id: 'u001', name: 'Editor' },
178+
{ id: 'u002', name: 'Moderator', disabled: true },
179+
{ id: 'u003', name: 'Reviewer' },
180+
]}
181+
/>
182+
</Wrapper>
183+
);
184+
170185
export const ReadOnly = () => (
171186
<AdminContext i18nProvider={i18nProvider}>
172187
<Create

0 commit comments

Comments
 (0)