From ff4ba91bf25614474a792ccb9c9e80e9630a8cb2 Mon Sep 17 00:00:00 2001 From: solarjoker Date: Sun, 19 Jan 2020 19:56:55 +0800 Subject: [PATCH 1/2] refactor: selectDropdown code --- components/select/SelectDropdown.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/select/SelectDropdown.js b/components/select/SelectDropdown.js index 8ff7117de..bc6d31495 100644 --- a/components/select/SelectDropdown.js +++ b/components/select/SelectDropdown.js @@ -15,11 +15,11 @@ class SelectDropdown extends Component { } } static getDerivedStateFromProps (nextProps, prevState) { - if (nextProps.selectedItems.length > 0 && prevState.searchbarValue.length === 0 && nextProps.mode === 'single' && nextProps.isOnSearch) { - return { filterItems: prevState.cachedropdownItems, searchbarValue: nextProps.show ? prevState.searchbarValue : '' } - } else { - return { filterItems: nextProps.dropdownItems, searchbarValue: nextProps.show ? prevState.searchbarValue : '' } - } + const {selectedItems, mode, isOnSearch, dropdownItems, show} = nextProps + const {searchbarValue, cachedropdownItems} = prevState + const _filterItems = selectedItems.length > 0 && searchbarValue.length === 0 && mode === 'single' && isOnSearch ? cachedropdownItems : dropdownItems + const _searchbarValue = show ? searchbarValue : '' + return {filterItems: _filterItems, searchbarValue: _searchbarValue} } componentDidMount () { this.props.searchable && this.searchbar.focus() From 5228c57b6dba589ff7038e4a2382684457606185 Mon Sep 17 00:00:00 2001 From: solarjoker Date: Sun, 19 Jan 2020 20:00:11 +0800 Subject: [PATCH 2/2] chore: update jest config --- jest.config.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/jest.config.js b/jest.config.js index e5a2c87ae..c9e4ec4f6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -15,25 +15,25 @@ module.exports = { coverageReporters: ['json-summary', 'text', 'lcov'], // An array of glob patterns indicating a set of files for which coverage information should be collected - // collectCoverageFrom: [ - // '/components/**/*', - // '!/components/table/**/*', - // '!/components/nav-menu/**/*', - // '!/components/**/style/**/*', - // '!/components/**/__test__/**/*', - // '!/components/**/(*-legacy)/**/*' - // ], - // 本地单测使用 - // 1. 修改范围 /components/[组件名称]/**/* - // 2. 运行单测命令 npx jest components/date-picker/__tests__/index.test.js --coverage 即可看到当前文件夹的覆盖率 collectCoverageFrom: [ - '/components/select/**/*', + '/components/**/*', '!/components/table/**/*', '!/components/nav-menu/**/*', '!/components/**/style/**/*', '!/components/**/__test__/**/*', '!/components/**/(*-legacy)/**/*' ], + // 本地单测使用 + // 1. 修改范围 /components/[组件名称]/**/* + // 2. 运行单测命令 npx jest components/date-picker/__tests__/index.test.js --coverage 即可看到当前文件夹的覆盖率 + // collectCoverageFrom: [ + // '/components/select/**/*', + // '!/components/table/**/*', + // '!/components/nav-menu/**/*', + // '!/components/**/style/**/*', + // '!/components/**/__test__/**/*', + // '!/components/**/(*-legacy)/**/*' + // ], // The test environment that will be used for testing testEnvironment: 'jest-environment-jsdom-global',