Skip to content

Commit

Permalink
恢复 isDisabled 说不定用得着,顺便看看codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo837 committed Jun 1, 2020
1 parent 89bae57 commit 345a5dd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/hooks/useKeyValueMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ import { FlattenDataNode, Key, RawValueType } from '../interface';

export type SkipType = null | 'select' | 'checkbox';

export function isDisabled(dataNode: FlattenDataNode, skipType: SkipType): boolean {
if (!dataNode) {
return true;
}

const { disabled, disableCheckbox } = dataNode.data;

switch (skipType) {
case 'select':
return disabled;
case 'checkbox':
return disabled || disableCheckbox;
}

return false;
}

export default function useKeyValueMapping(
cacheKeyMap: Map<Key, FlattenDataNode>,
cacheValueMap: Map<RawValueType, FlattenDataNode>,
Expand Down
14 changes: 10 additions & 4 deletions tests/utils.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { isValueDisabled } from '../src/utils/valueUtil';
import { isDisabled } from '../src/hooks/useKeyValueMapping';

describe('TreeSelect.util', () => {
it('isValueDisabled', () => {
const options = [
{ data: { value: 'disabled', disabled: true } },
{ data: { value: 'pass' } },
];
const options = [{ data: { value: 'disabled', disabled: true } }, { data: { value: 'pass' } }];
expect(isValueDisabled('disabled', options)).toBeTruthy();
expect(isValueDisabled('pass', options)).toBeFalsy();
expect(isValueDisabled('not-exist', options)).toBeFalsy();
});

it('isDisabled', () => {
expect(isDisabled({ data: { disabled: true } }, 'select')).toBeTruthy();
expect(isDisabled({ data: { disableCheckbox: true } }, 'select')).toBeFalsy();
expect(isDisabled({ data: { disabled: true } }, 'checkbox')).toBeTruthy();
expect(isDisabled({ data: { disableCheckbox: true } }, 'checkbox')).toBeTruthy();
expect(isDisabled({ data: { disabled: true } }, null)).toBeFalsy();
});
});

0 comments on commit 345a5dd

Please sign in to comment.