Skip to content

Commit a9c2833

Browse files
committedJan 19, 2021
Add more tests
1 parent d1a7c75 commit a9c2833

6 files changed

+309
-1
lines changed
 

‎packages/ra-ui-materialui/src/input/AutocompleteArrayInput.spec.tsx

+61
Original file line numberDiff line numberDiff line change
@@ -665,4 +665,65 @@ describe('<AutocompleteArrayInput />', () => {
665665
fireEvent.focus(input);
666666
expect(queryAllByRole('option')).toHaveLength(1);
667667
});
668+
669+
// TODO: restore once master has been merged back to next
670+
it.skip('should not render a LinearProgress if loading is true and a second has not passed yet', () => {
671+
const { queryByRole } = render(
672+
<Form
673+
validateOnBlur
674+
onSubmit={jest.fn()}
675+
render={() => (
676+
<AutocompleteArrayInput
677+
{...{
678+
...defaultProps,
679+
loaded: true,
680+
loading: true,
681+
}}
682+
/>
683+
)}
684+
/>
685+
);
686+
687+
expect(queryByRole('progressbar')).toBeNull();
688+
});
689+
690+
it('should render a LinearProgress if loading is true and a second has passed', async () => {
691+
const { queryByRole } = render(
692+
<Form
693+
validateOnBlur
694+
onSubmit={jest.fn()}
695+
render={() => (
696+
<AutocompleteArrayInput
697+
{...{
698+
...defaultProps,
699+
loaded: true,
700+
loading: true,
701+
}}
702+
/>
703+
)}
704+
/>
705+
);
706+
707+
await new Promise(resolve => setTimeout(resolve, 1001));
708+
709+
expect(queryByRole('progressbar')).not.toBeNull();
710+
});
711+
712+
it('should not render a LinearProgress if loading is false', () => {
713+
const { queryByRole } = render(
714+
<Form
715+
validateOnBlur
716+
onSubmit={jest.fn()}
717+
render={() => (
718+
<AutocompleteArrayInput
719+
{...{
720+
...defaultProps,
721+
}}
722+
/>
723+
)}
724+
/>
725+
);
726+
727+
expect(queryByRole('progressbar')).toBeNull();
728+
});
668729
});

‎packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx

+61
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,65 @@ describe('<AutocompleteInput />', () => {
639639
expect(queryByDisplayValue('foo')).not.toBeNull();
640640
});
641641
});
642+
643+
// TODO: restore once master has been merged back to next
644+
it.skip('should not render a LinearProgress if loading is true and a second has not passed yet', () => {
645+
const { queryByRole } = render(
646+
<Form
647+
validateOnBlur
648+
onSubmit={jest.fn()}
649+
render={() => (
650+
<AutocompleteInput
651+
{...{
652+
...defaultProps,
653+
loaded: true,
654+
loading: true,
655+
}}
656+
/>
657+
)}
658+
/>
659+
);
660+
661+
expect(queryByRole('progressbar')).toBeNull();
662+
});
663+
664+
it('should render a LinearProgress if loading is true and a second has passed', async () => {
665+
const { queryByRole } = render(
666+
<Form
667+
validateOnBlur
668+
onSubmit={jest.fn()}
669+
render={() => (
670+
<AutocompleteInput
671+
{...{
672+
...defaultProps,
673+
loaded: true,
674+
loading: true,
675+
}}
676+
/>
677+
)}
678+
/>
679+
);
680+
681+
await new Promise(resolve => setTimeout(resolve, 1001));
682+
683+
expect(queryByRole('progressbar')).not.toBeNull();
684+
});
685+
686+
it('should not render a LinearProgress if loading is false', () => {
687+
const { queryByRole } = render(
688+
<Form
689+
validateOnBlur
690+
onSubmit={jest.fn()}
691+
render={() => (
692+
<AutocompleteInput
693+
{...{
694+
...defaultProps,
695+
}}
696+
/>
697+
)}
698+
/>
699+
);
700+
701+
expect(queryByRole('progressbar')).toBeNull();
702+
});
642703
});

‎packages/ra-ui-materialui/src/input/CheckboxGroupInput.spec.tsx

+61
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,65 @@ describe('<CheckboxGroupInput />', () => {
267267
expect(error.classList.contains('Mui-error')).toEqual(true);
268268
});
269269
});
270+
271+
// TODO: restore once master has been merged back to next
272+
it.skip('should not render a LinearProgress if loading is true and a second has not passed yet', () => {
273+
const { queryByRole } = render(
274+
<Form
275+
validateOnBlur
276+
onSubmit={jest.fn()}
277+
render={() => (
278+
<CheckboxGroupInput
279+
{...{
280+
...defaultProps,
281+
loaded: true,
282+
loading: true,
283+
}}
284+
/>
285+
)}
286+
/>
287+
);
288+
289+
expect(queryByRole('progressbar')).toBeNull();
290+
});
291+
292+
it('should render a LinearProgress if loading is true and a second has passed', async () => {
293+
const { queryByRole } = render(
294+
<Form
295+
validateOnBlur
296+
onSubmit={jest.fn()}
297+
render={() => (
298+
<CheckboxGroupInput
299+
{...{
300+
...defaultProps,
301+
loaded: true,
302+
loading: true,
303+
}}
304+
/>
305+
)}
306+
/>
307+
);
308+
309+
await new Promise(resolve => setTimeout(resolve, 1001));
310+
311+
expect(queryByRole('progressbar')).not.toBeNull();
312+
});
313+
314+
it('should not render a LinearProgress if loading is false', () => {
315+
const { queryByRole } = render(
316+
<Form
317+
validateOnBlur
318+
onSubmit={jest.fn()}
319+
render={() => (
320+
<CheckboxGroupInput
321+
{...{
322+
...defaultProps,
323+
}}
324+
/>
325+
)}
326+
/>
327+
);
328+
329+
expect(queryByRole('progressbar')).toBeNull();
330+
});
270331
});

‎packages/ra-ui-materialui/src/input/RadioButtonGroupInput.spec.tsx

+61
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,65 @@ describe('<RadioButtonGroupInput />', () => {
375375
expect(queryByText('Can I help you?')).toBeNull();
376376
});
377377
});
378+
379+
// TODO: restore once master has been merged back to next
380+
it.skip('should not render a LinearProgress if loading is true and a second has not passed yet', () => {
381+
const { queryByRole } = render(
382+
<Form
383+
validateOnBlur
384+
onSubmit={jest.fn()}
385+
render={() => (
386+
<RadioButtonGroupInput
387+
{...{
388+
...defaultProps,
389+
loaded: true,
390+
loading: true,
391+
}}
392+
/>
393+
)}
394+
/>
395+
);
396+
397+
expect(queryByRole('progressbar')).toBeNull();
398+
});
399+
400+
it('should render a LinearProgress if loading is true and a second has passed', async () => {
401+
const { queryByRole } = render(
402+
<Form
403+
validateOnBlur
404+
onSubmit={jest.fn()}
405+
render={() => (
406+
<RadioButtonGroupInput
407+
{...{
408+
...defaultProps,
409+
loaded: true,
410+
loading: true,
411+
}}
412+
/>
413+
)}
414+
/>
415+
);
416+
417+
await new Promise(resolve => setTimeout(resolve, 1001));
418+
419+
expect(queryByRole('progressbar')).not.toBeNull();
420+
});
421+
422+
it('should not render a LinearProgress if loading is false', () => {
423+
const { queryByRole } = render(
424+
<Form
425+
validateOnBlur
426+
onSubmit={jest.fn()}
427+
render={() => (
428+
<RadioButtonGroupInput
429+
{...{
430+
...defaultProps,
431+
}}
432+
/>
433+
)}
434+
/>
435+
);
436+
437+
expect(queryByRole('progressbar')).toBeNull();
438+
});
378439
});

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

+61
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,66 @@ describe('<SelectArrayInput />', () => {
232232
);
233233
expect(queryByText('Required field.')).toBeDefined();
234234
});
235+
236+
// TODO: restore once master has been merged back to next
237+
it.skip('should not render a LinearProgress if loading is true and a second has not passed yet', () => {
238+
const { queryByRole } = render(
239+
<Form
240+
validateOnBlur
241+
onSubmit={jest.fn()}
242+
render={() => (
243+
<SelectArrayInput
244+
{...{
245+
...defaultProps,
246+
loaded: true,
247+
loading: true,
248+
}}
249+
/>
250+
)}
251+
/>
252+
);
253+
254+
expect(queryByRole('progressbar')).toBeNull();
255+
});
256+
257+
it('should render a LinearProgress if loading is true and a second has passed', async () => {
258+
const { queryByRole } = render(
259+
<Form
260+
validateOnBlur
261+
onSubmit={jest.fn()}
262+
render={() => (
263+
<SelectArrayInput
264+
{...{
265+
...defaultProps,
266+
loaded: true,
267+
loading: true,
268+
}}
269+
/>
270+
)}
271+
/>
272+
);
273+
274+
await new Promise(resolve => setTimeout(resolve, 1001));
275+
276+
expect(queryByRole('progressbar')).not.toBeNull();
277+
});
278+
279+
it('should not render a LinearProgress if loading is false', () => {
280+
const { queryByRole } = render(
281+
<Form
282+
validateOnBlur
283+
onSubmit={jest.fn()}
284+
render={() => (
285+
<SelectArrayInput
286+
{...{
287+
...defaultProps,
288+
}}
289+
/>
290+
)}
291+
/>
292+
);
293+
294+
expect(queryByRole('progressbar')).toBeNull();
295+
});
235296
});
236297
});

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ const SelectArrayInput: FunctionComponent<SelectArrayInputProps> = props => {
167167
const inputLabel = useRef(null);
168168
const [labelWidth, setLabelWidth] = useState(0);
169169
useEffect(() => {
170-
setLabelWidth(inputLabel.current.offsetWidth);
170+
// Will be null while loading and we don't need this fix in that case
171+
if (inputLabel.current) {
172+
setLabelWidth(inputLabel.current.offsetWidth);
173+
}
171174
}, []);
172175

173176
const { getChoiceText, getChoiceValue } = useChoices({

0 commit comments

Comments
 (0)
Please sign in to comment.