From 16e6d717ce349164c9c0024eeeb81b4cabf197e9 Mon Sep 17 00:00:00 2001 From: soufianeboutahlil Date: Sun, 10 Jul 2022 23:33:16 +0100 Subject: [PATCH 01/11] fix: Ignore primitive elements --- packages/mui-material/src/Select/SelectInput.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/mui-material/src/Select/SelectInput.js b/packages/mui-material/src/Select/SelectInput.js index e1d13d6502c31e..526d1275a5dedb 100644 --- a/packages/mui-material/src/Select/SelectInput.js +++ b/packages/mui-material/src/Select/SelectInput.js @@ -401,7 +401,8 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { return selected; } const firstSelectableElement = arr.find( - (item) => item.props.value !== undefined && item.props.disabled !== true, + (item) => + item && item.props && item.props.value !== undefined && item.props.disabled !== true, ); if (child === firstSelectableElement) { return true; From 6602f2bdc9614c810c178f5a32077a2f794f8c9d Mon Sep 17 00:00:00 2001 From: soufianeboutahlil Date: Mon, 11 Jul 2022 00:19:05 +0100 Subject: [PATCH 02/11] fix: Add conditional rendering test cases --- .../mui-material/src/Select/Select.test.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/mui-material/src/Select/Select.test.js b/packages/mui-material/src/Select/Select.test.js index bb00594406304f..3b1a60a88ff829 100644 --- a/packages/mui-material/src/Select/Select.test.js +++ b/packages/mui-material/src/Select/Select.test.js @@ -79,6 +79,42 @@ describe(' + {'' && One} + Two + , + ); + }); + + it('should support conditional rendering with negative number', () => { + render( + , + ); + }); + + it('should support conditional rendering with zero', () => { + render( + , + ); + }); + + it('should support conditional rendering with NaN', () => { + render( + , + ); + }); + it('should have an input with [aria-hidden] by default', () => { const { container } = render( ', () => { ); }); + it('should support conditional rendering with boolean', () => { + render( + , + ); + }); + + it('should support conditional rendering with undefined', () => { + render( + , + ); + }); + + it('should support conditional rendering with null', () => { + render( + , + ); + }); + + it('should support conditional rendering with false', () => { + render( + , + ); + }); + it('should have an input with [aria-hidden] by default', () => { const { container } = render( ', () => { ); }); + it('should ignore primitive element', () => { + render( + , + ); + }); + it('should have an input with [aria-hidden] by default', () => { const { container } = render( ', () => { it('should ignore primitive element', () => { render( , From 1e281ee79a13df6e7ba1e852576eb5704cc79115 Mon Sep 17 00:00:00 2001 From: soufianeboutahlil Date: Fri, 29 Jul 2022 22:59:28 +0100 Subject: [PATCH 07/11] Use optional chaining --- packages/mui-material/src/Select/SelectInput.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/mui-material/src/Select/SelectInput.js b/packages/mui-material/src/Select/SelectInput.js index 5f7526a9b4cde9..3235f9ddfec5d3 100644 --- a/packages/mui-material/src/Select/SelectInput.js +++ b/packages/mui-material/src/Select/SelectInput.js @@ -401,8 +401,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { return selected; } const firstSelectableElement = arr.find( - (item) => - item && item.props && item.props.value !== undefined && item.props.disabled !== true, + (item) => item?.props?.value !== undefined && item.props.disabled !== true, ); if (child === firstSelectableElement) { return true; @@ -427,8 +426,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { }, role: 'option', selected: - (arr[0] && arr[0].props && arr[0].props.value === undefined) || - (arr[0] && arr[0].props && arr[0].props.disabled === true) + arr[0]?.props?.value === undefined || arr[0]?.props?.disabled === true ? isFirstSelectableElement() : selected, value: undefined, // The value is most likely not a valid HTML attribute. From b6ff59847ee8b0c0bd193fc49a0e21c0f79386c2 Mon Sep 17 00:00:00 2001 From: soufianeboutahlil Date: Fri, 29 Jul 2022 23:28:08 +0100 Subject: [PATCH 08/11] Fix tests --- .../mui-material/src/Select/Select.test.js | 91 ++----------------- 1 file changed, 10 insertions(+), 81 deletions(-) diff --git a/packages/mui-material/src/Select/Select.test.js b/packages/mui-material/src/Select/Select.test.js index 75c44fb8ba485e..5c08f6f40d4840 100644 --- a/packages/mui-material/src/Select/Select.test.js +++ b/packages/mui-material/src/Select/Select.test.js @@ -79,87 +79,16 @@ describe(' - {'' && One} - Two - , - ); - }); - - it('should support conditional rendering with negative number', () => { - render( - , - ); - }); - - it('should support conditional rendering with zero', () => { - render( - , - ); - }); - - it('should support conditional rendering with NaN', () => { - render( - , - ); - }); - - it('should support conditional rendering with boolean', () => { - render( - , - ); - }); - - it('should support conditional rendering with undefined', () => { - render( - , - ); - }); - - it('should support conditional rendering with null', () => { - render( - , - ); - }); - - it('should support conditional rendering with false', () => { - render( - , - ); - }); - - it('should ignore primitive element', () => { - render( - , - ); - }); + ['', 0, NaN].forEach((value) => + it(`should support conditional rendering with "${value}"`, () => { + render( + , + ); + }), + ); it('should have an input with [aria-hidden] by default', () => { const { container } = render( From 42a925153cf8702573d5326c8addd43e19fffca7 Mon Sep 17 00:00:00 2001 From: soufianeboutahlil Date: Wed, 3 Aug 2022 22:50:39 +0100 Subject: [PATCH 09/11] Add missed values --- .../mui-material/src/Select/Select.test.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/mui-material/src/Select/Select.test.js b/packages/mui-material/src/Select/Select.test.js index 5c08f6f40d4840..940b2993f3e304 100644 --- a/packages/mui-material/src/Select/Select.test.js +++ b/packages/mui-material/src/Select/Select.test.js @@ -1,22 +1,22 @@ -import * as React from 'react'; +import Divider from '@mui/material/Divider'; +import InputBase from '@mui/material/InputBase'; +import InputLabel from '@mui/material/InputLabel'; +import ListSubheader from '@mui/material/ListSubheader'; +import MenuItem from '@mui/material/MenuItem'; +import OutlinedInput from '@mui/material/OutlinedInput'; +import Select from '@mui/material/Select'; +import { createTheme, ThemeProvider } from '@mui/material/styles'; import { expect } from 'chai'; +import * as React from 'react'; import { spy, stub } from 'sinon'; import { - describeConformance, - ErrorBoundary, act, createRenderer, + describeConformance, + ErrorBoundary, fireEvent, screen, } from 'test/utils'; -import { createTheme, ThemeProvider } from '@mui/material/styles'; -import MenuItem from '@mui/material/MenuItem'; -import ListSubheader from '@mui/material/ListSubheader'; -import InputBase from '@mui/material/InputBase'; -import OutlinedInput from '@mui/material/OutlinedInput'; -import InputLabel from '@mui/material/InputLabel'; -import Select from '@mui/material/Select'; -import Divider from '@mui/material/Divider'; import classes from './selectClasses'; describe('', () => { ); }); - ['', 0, NaN].forEach((value) => + ['', 0, false, undefined, NaN].forEach((value) => it(`should support conditional rendering with "${value}"`, () => { render( ', () => { From 5b7e39bf30258cf18207bdf63c88420ceb8ee34f Mon Sep 17 00:00:00 2001 From: Marija Najdova Date: Fri, 16 Dec 2022 14:45:09 +0100 Subject: [PATCH 11/11] Update packages/mui-material/src/Select/Select.test.js Signed-off-by: Marija Najdova --- packages/mui-material/src/Select/Select.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mui-material/src/Select/Select.test.js b/packages/mui-material/src/Select/Select.test.js index 60b9e606e4a9fe..6e329800ab36c9 100644 --- a/packages/mui-material/src/Select/Select.test.js +++ b/packages/mui-material/src/Select/Select.test.js @@ -2,10 +2,10 @@ import * as React from 'react'; import { expect } from 'chai'; import { spy, stub } from 'sinon'; import { - act, - createRenderer, describeConformance, ErrorBoundary, + act, + createRenderer, fireEvent, screen, } from 'test/utils';