Skip to content

Commit

Permalink
feat: not_contain
Browse files Browse the repository at this point in the history
  • Loading branch information
Liberty-liu committed May 8, 2023
1 parent 822f48b commit f961a08
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/hooks/use-logic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const contains = (logicValue, value, filedType) => {
return !!_.intersection(logicValue, value).length
}
}
const notContains = (...e) => {
return !contains(...e)
}
export const validator = (logic, value, filed) => {
let result = false
// console.log(filed)
Expand All @@ -76,13 +79,14 @@ export const validator = (logic, value, filed) => {
result = notEqual(logic.value, value, filed.type)
break
case 'contains':
console.log(logic.value)
console.log(`操作符的值:${logic.value} type: ${typeof logic.value}`)
console.log(value)
console.log(`field的值:${value} type: ${typeof value}`)
// console.log(logic.value)
// console.log(`操作符的值:${logic.value} type: ${typeof logic.value}`)
// console.log(value)
// console.log(`field的值:${value} type: ${typeof value}`)
result = contains(logic.value, value, filed.type)
break
case 'not_contain':
result = notContains(logic.value, value, filed.type)
break
case 'empty':
break
Expand Down
125 changes: 125 additions & 0 deletions test/logic/logic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ describe('validator', () => {
},
'123',
filed)).toBeTruthy()
expect(
validator({
operator: 'not_contain',
value: [
'123'
]
},
'123',
filed)).toBeFalsy()
expect(
validator({
operator: 'not_contain',
value: [
'123'
]
},
'456',
filed)).toBeTruthy()
})
test('Cellphone', () => {
const filed = { type: 'input', label: 'Cellphone', icon: 'cellphone', key: 'input_feokPGo0uqPDPGvcbbkrB', id: 'feokPGo0uqPDPGvcbbkrB', options: { clearable: true, renderType: 4, disabled: false, showPassword: false, defaultValue: '', placeholder: 'Please enter', labelWidth: 100, isShowLabel: true, required: false }, style: { width: { pc: '100%', mobile: '100%' } } }
Expand All @@ -52,6 +70,15 @@ describe('validator', () => {
},
'123',
filed)).toBeTruthy()
expect(
validator({
operator: 'not_contain',
value: [
'123'
]
},
'123',
filed)).toBeFalsy()
})
test('URL', () => {
const filed = { type: 'input', label: 'URL', icon: 'url', key: 'input_8Des6TBcAhe5zmEl7x83q', id: '8Des6TBcAhe5zmEl7x83q', options: { clearable: true, renderType: 5, disabled: false, showPassword: false, defaultValue: '', placeholder: 'Please enter', labelWidth: 100, isShowLabel: true, required: false }, style: { width: { pc: '100%', mobile: '100%' } } }
Expand All @@ -78,6 +105,15 @@ describe('validator', () => {
},
'https://everright.site/',
filed)).toBeTruthy()
expect(
validator({
operator: 'not_contain',
value: [
'https://everright.site/'
]
},
'https://everright.site/',
filed)).toBeFalsy()
})
// test('Region', () => {
// const filed = { type: 'region', label: 'Region', icon: 'location', key: 'region_Yqz1snVkubaX2WG8xCEFs', id: 'Yqz1snVkubaX2WG8xCEFs', options: { placeholder: 'Please select', required: false, isShowLabel: true, labelWidth: 100, defaultValue: '', selectType: 3, filterable: true }, style: { width: { pc: '100%', mobile: '100%' } } }
Expand Down Expand Up @@ -125,6 +161,15 @@ describe('validator', () => {
},
'123',
filed)).toBeTruthy()
expect(
validator({
operator: 'not_contain',
value: [
'123'
]
},
'123',
filed)).toBeFalsy()
})
test('Input', () => {
const filed = { type: 'input', label: 'Input', icon: 'input', key: 'input_D7ijHbzIJUJ8THOhHqGXK', id: 'D7ijHbzIJUJ8THOhHqGXK', options: { clearable: true, isShowWordLimit: false, renderType: 1, disabled: false, showPassword: false, defaultValue: '', placeholder: 'Please enter', labelWidth: 100, isShowLabel: true, required: false, min: null, max: null }, style: { width: { pc: '100%', mobile: '100%' } } }
Expand All @@ -151,6 +196,15 @@ describe('validator', () => {
},
'123',
filed)).toBeTruthy()
expect(
validator({
operator: 'not_contain',
value: [
'123'
]
},
'123',
filed)).toBeFalsy()
})
test('Textarea', () => {
const filed = { type: 'textarea', label: 'Textarea', icon: 'textarea', key: 'textarea_ZPRzSVZkMHOMYgWZBmrvR', id: 'ZPRzSVZkMHOMYgWZBmrvR', options: { clearable: true, isShowWordLimit: false, rows: 6, defaultValue: '', placeholder: 'Please enter', disabled: false, labelWidth: 100, isShowLabel: true, required: false, min: null, max: null }, style: { width: { pc: '100%', mobile: '100%' } } }
Expand All @@ -177,6 +231,15 @@ describe('validator', () => {
},
'123',
filed)).toBeTruthy()
expect(
validator({
operator: 'not_contain',
value: [
'123'
]
},
'123',
filed)).toBeFalsy()
})
test('Number', () => {
const filed = { type: 'number', label: 'Number', icon: 'numbers', key: 'number_3bdLUMFSVB7_YujfBJhBB', id: '3bdLUMFSVB7_YujfBJhBB', options: { min: 0, max: null, step: 1, precision: 0, disabled: false, controls: true, controlsPosition: true, defaultValue: null, labelWidth: 100, isShowLabel: true, required: false, minlength: null, maxlength: null }, style: { width: { pc: '100%', mobile: '100%' } } }
Expand Down Expand Up @@ -218,6 +281,13 @@ describe('validator', () => {
},
'CrvWR4TVdNRxvxty5iAT2',
filed)).toBeTruthy()
expect(
validator({
operator: 'toBeFalsy',
value: ['CrvWR4TVdNRxvxty5iAT2']
},
'CrvWR4TVdNRxvxty5iAT2',
filed)).toBeFalsy()
})
test('Checkbox', () => {
const filed = { type: 'checkbox', label: 'Checkbox', icon: 'checkbox', key: 'checkbox_qE0oMb42msqQ1M4N35F6P', id: 'qE0oMb42msqQ1M4N35F6P', options: { dataKey: 'qE0oMb42msqQ1M4N35F6P', displayStyle: 'block', defaultValue: [], labelWidth: 100, isShowLabel: true, required: false, disabled: false }, style: { width: { pc: '100%', mobile: '100%' } } }
Expand Down Expand Up @@ -291,6 +361,30 @@ describe('validator', () => {
'0bZN9TQ0bePdjOewythuj1'
],
filed)).toBeFalsy()
expect(
validator({
operator: 'not_contain',
value: [
'0bZN9TQ0bePdjOewythuj',
'OzUgt2_0be-2f97bPu0yJ'
]
},
[
'0bZN9TQ0bePdjOewythuj'
],
filed)).toBeFalsy()
expect(
validator({
operator: 'not_contain',
value: [
'0bZN9TQ0bePdjOewythuj',
'OzUgt2_0be-2f97bPu0yJ'
]
},
[
'0bZN9TQ0bePdjOewythuj1'
],
filed)).toBeTruthy()
})
test('Select', () => {
const filed = { type: 'select', label: 'Select', icon: 'dropdown0', key: 'select_lLyhZ6ThDBd2_O5JKOjzN', id: 'lLyhZ6ThDBd2_O5JKOjzN', options: { dataKey: 'lLyhZ6ThDBd2_O5JKOjzN', filterable: true, multiple: false, defaultValue: [], placeholder: 'Please select', labelWidth: 100, isShowLabel: true, disabled: false, clearable: true, required: false }, style: { width: { pc: '100%', mobile: '100%' } } }
Expand Down Expand Up @@ -379,6 +473,28 @@ describe('validator', () => {
'0bZN9TQ0bePdjOewythuj'
],
filed)).toBeTruthy()
filed.options.multiple = false
expect(
validator({
operator: 'not_contain',
value: [
'0bZN9TQ0bePdjOewythuj'
]
},
'0bZN9TQ0bePdjOewythuj',
filed)).toBeFalsy()
filed.options.multiple = true
expect(
validator({
operator: 'not_contain',
value: [
'0bZN9TQ0bePdjOewythuj'
]
},
[
'0bZN9TQ0bePdjOewythuj'
],
filed)).toBeFalsy()
})
test('Time', () => {
const filed = { type: 'time', label: 'Time', icon: 'time', key: 'time_JfeEFqHMQbVI424FbFEHw', id: 'JfeEFqHMQbVI424FbFEHw', options: { clearable: true, format: 'HH时mm分ss秒', defaultValue: null, placeholder: 'Please select', labelWidth: 100, isShowLabel: true, required: false, disabled: false }, style: { width: { pc: '100%', mobile: '100%' } } }
Expand Down Expand Up @@ -514,6 +630,15 @@ describe('validator', () => {
},
'<p>123</p>',
filed)).toBeTruthy()
expect(
validator({
operator: 'not_contain',
value: [
'<p>123</p>'
]
},
'<p>123</p>',
filed)).toBeFalsy()
})
test('Cascader', () => {
const filed = { type: 'cascader', label: 'Cascader', icon: 'cascader', key: 'cascader_KFrOTULCQ0EAcMcIQTd_v', id: 'KFrOTULCQ0EAcMcIQTd_v', options: { filterable: true, multiple: false, checkStrictly: true, defaultValue: [], placeholder: 'Please select', labelWidth: 100, isShowLabel: true, required: false, disabled: false, clearable: true, dataKey: 'KFrOTULCQ0EAcMcIQTd_v' }, style: { width: { pc: '100%', mobile: '100%' } } }
Expand Down

0 comments on commit f961a08

Please sign in to comment.