|
| 1 | +/* Copyright Contributors to the Open Cluster Management project */ |
| 2 | +import { SearchOperator } from '../ui-components/AcmSearchInput' |
| 3 | +import { handleStandardComparison, handleSemverOperatorComparison } from './search-utils' |
| 4 | + |
| 5 | +const stringData = { |
| 6 | + stringOne: 'Adam', |
| 7 | + stringTwo: 'Becky', |
| 8 | + stringThree: 'Charlie', |
| 9 | + stringFour: 'David', |
| 10 | + stringFive: 'Eve', |
| 11 | +} |
| 12 | +const versionData = { |
| 13 | + versionOne: '1.0.0', |
| 14 | + versionTwo: '1.5.0', |
| 15 | + versionThree: '2.0.0', |
| 16 | + versionFour: '2.5.0', |
| 17 | + versionIncomplete: '1.', |
| 18 | +} |
| 19 | + |
| 20 | +describe('search-utils basic string operator', () => { |
| 21 | + const { stringOne, stringTwo, stringThree, stringFour, stringFive } = stringData |
| 22 | + it('can determine equals', () => { |
| 23 | + expect(handleStandardComparison(stringOne, stringOne, SearchOperator.Equals)).toBeTruthy() |
| 24 | + }) |
| 25 | + it('can determine greater', () => { |
| 26 | + expect(handleStandardComparison(stringOne, stringTwo, SearchOperator.GreaterThan)).toBeTruthy() |
| 27 | + }) |
| 28 | + it('can determine less', () => { |
| 29 | + expect(handleStandardComparison(stringFour, stringThree, SearchOperator.LessThan)).toBeTruthy() |
| 30 | + }) |
| 31 | + it('can determine greater than or equal to', () => { |
| 32 | + expect(handleStandardComparison(stringOne, stringOne, SearchOperator.GreaterThanOrEqualTo)).toBeTruthy() |
| 33 | + expect(handleStandardComparison(stringOne, stringTwo, SearchOperator.GreaterThanOrEqualTo)).toBeTruthy() |
| 34 | + }) |
| 35 | + it('can determine less than or equal to', () => { |
| 36 | + expect(handleStandardComparison(stringOne, stringOne, SearchOperator.LessThanOrEqualTo)).toBeTruthy() |
| 37 | + expect(handleStandardComparison(stringFive, stringOne, SearchOperator.LessThanOrEqualTo)).toBeTruthy() |
| 38 | + }) |
| 39 | + it('can determine non-equals', () => { |
| 40 | + expect(handleStandardComparison(stringOne, stringFive, SearchOperator.Equals)).toBeFalsy() |
| 41 | + }) |
| 42 | +}) |
| 43 | + |
| 44 | +describe('search-utils sermver operator', () => { |
| 45 | + const { versionOne, versionTwo, versionThree, versionFour, versionIncomplete } = versionData |
| 46 | + it('can determine greater semver', () => { |
| 47 | + expect(handleSemverOperatorComparison(versionFour, versionThree, SearchOperator.GreaterThan)).toBeTruthy() |
| 48 | + }) |
| 49 | + it('can determine less semver', () => { |
| 50 | + expect(handleSemverOperatorComparison(versionOne, versionTwo, SearchOperator.LessThan)).toBeTruthy() |
| 51 | + }) |
| 52 | + it('can determine equals semver', () => { |
| 53 | + expect(handleSemverOperatorComparison(versionOne, versionOne, SearchOperator.Equals)).toBeTruthy() |
| 54 | + }) |
| 55 | + it('can determine greater than or equal to semver', () => { |
| 56 | + expect(handleSemverOperatorComparison(versionThree, versionThree, SearchOperator.GreaterThanOrEqualTo)).toBeTruthy() |
| 57 | + expect(handleSemverOperatorComparison(versionFour, versionThree, SearchOperator.GreaterThanOrEqualTo)).toBeTruthy() |
| 58 | + }) |
| 59 | + it('can determine less than or equal to semver', () => { |
| 60 | + expect(handleSemverOperatorComparison(versionTwo, versionTwo, SearchOperator.LessThanOrEqualTo)).toBeTruthy() |
| 61 | + expect(handleSemverOperatorComparison(versionOne, versionTwo, SearchOperator.LessThanOrEqualTo)).toBeTruthy() |
| 62 | + }) |
| 63 | + it('can determine non-equal semver', () => { |
| 64 | + expect(handleSemverOperatorComparison(versionOne, versionTwo, SearchOperator.NotEquals)).toBeTruthy() |
| 65 | + }) |
| 66 | + it('can coerce incomplete semver strings', () => { |
| 67 | + expect(handleSemverOperatorComparison(versionIncomplete, versionOne, SearchOperator.Equals)).toBeTruthy() |
| 68 | + }) |
| 69 | +}) |
0 commit comments