forked from hatemhosny/racing-bars
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01a3767
commit 32c482a
Showing
6 changed files
with
342 additions
and
437 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { includes, is, validateOptions } from '../index'; | ||
|
||
test('Tests for "is" function', () => { | ||
expect(is(undefined, 'string')).toBe(false); | ||
|
||
expect(is(5, 'number')).toBe(true); | ||
expect(is('5', 'number')).toBe(false); | ||
expect(is(NaN, 'number')).toBe(false); | ||
|
||
expect(is([], 'array')).toBe(true); | ||
expect(is({}, 'array')).toBe(false); | ||
expect(is([1, 2, 3], 'array', 'number')).toBe(true); | ||
expect(is([1, '2', 3], 'array', 'number')).toBe(false); | ||
|
||
expect(is(true, 'boolean')).toBe(true); | ||
expect(is(false, 'boolean')).toBe(true); | ||
expect(is('true', 'boolean')).toBe(false); | ||
|
||
expect(is({}, 'object')).toBe(true); | ||
expect(is([], 'object')).toBe(true); | ||
|
||
expect(is('hello', 'string')).toBe(true); | ||
expect(is(5, 'string')).toBe(false); | ||
|
||
expect(is(() => 1, 'function')).toBe(true); | ||
expect(is({}, 'function')).toBe(false); | ||
}); | ||
|
||
test('Tests for "includes" function', () => { | ||
const array = [1, 2, 3, 4, 5]; | ||
|
||
expect(includes(array, 3)).toBe(true); | ||
expect(includes(array, 6)).toBe(false); | ||
}); | ||
|
||
test('should validate boolean options', () => { | ||
const options: any = { | ||
makeCumulative: true, | ||
loop: false, | ||
showIcons: true, | ||
showGroups: false, | ||
mouseControls: true, | ||
keyboardControls: false, | ||
autorun: true, | ||
injectStyles: 10, | ||
fixedScale: 10, | ||
highlightBars: 'string', | ||
selectBars: 'string', | ||
}; | ||
const validatedOptions = validateOptions(options); | ||
|
||
// Valid options | ||
expect(validatedOptions.makeCumulative).toBe(true); | ||
expect(validatedOptions.loop).toBe(false); | ||
expect(validatedOptions.showIcons).toBe(true); | ||
expect(validatedOptions.showGroups).toBe(false); | ||
expect(validatedOptions.mouseControls).toBe(true); | ||
expect(validatedOptions.keyboardControls).toBe(false); | ||
expect(validatedOptions.autorun).toBe(true); | ||
|
||
// Invalid options | ||
expect(validatedOptions.injectStyles).toBe(undefined); | ||
expect(validatedOptions.fixedScale).toBe(undefined); | ||
expect(validatedOptions.highlightBars).toBe(undefined); | ||
expect(validatedOptions.selectBars).toBe(undefined); | ||
}); | ||
|
||
test('should validate number options', () => { | ||
const options: any = { | ||
labelsWidth: 100, | ||
tickDuration: 500, | ||
topN: 5, | ||
minHeight: 'string', | ||
minWidth: true, | ||
}; | ||
const validatedOptions = validateOptions(options); | ||
|
||
// Valid options | ||
expect(validatedOptions.labelsWidth).toBe(100); | ||
expect(validatedOptions.tickDuration).toBe(500); | ||
expect(validatedOptions.topN).toBe(5); | ||
|
||
// Invalid options | ||
expect(validatedOptions.minHeight).toBe(undefined); | ||
expect(validatedOptions.minWidth).toBe(undefined); | ||
}); | ||
|
||
test('Tests to validate string options', () => { | ||
const options: any = { | ||
theme: 'dark', | ||
startDate: '2022-12-31', | ||
endDate: 90, | ||
}; | ||
const validatedOpts = validateOptions(options); | ||
|
||
// Valid options | ||
expect(validatedOpts.theme).toBe('dark'); | ||
expect(validatedOpts.startDate).toBe('2022-12-31'); | ||
|
||
// Invalid options | ||
expect(validatedOpts.endDate).toBe(undefined); | ||
}); | ||
|
||
test('Tests to validate string or number options', () => { | ||
const options: any = { | ||
colorSeed: 'seed123', | ||
inputHeight: 100, | ||
inputWidth: '200', | ||
height: true, | ||
width: () => 0, | ||
}; | ||
const validatedOpts = validateOptions(options); | ||
|
||
// Valid options | ||
expect(validatedOpts.colorSeed).toBe('seed123'); | ||
expect(validatedOpts.inputHeight).toBe(100); | ||
expect(validatedOpts.inputWidth).toBe('200'); | ||
|
||
// Invalid options | ||
expect(validatedOpts.height).toBe(undefined); | ||
expect(validatedOpts.width).toBe(undefined); | ||
}); | ||
|
||
test('Tests to validate function or string options', () => { | ||
const options: any = { | ||
title: 'Chart Title', | ||
subTitle: () => 'Sub Title', | ||
dateCounter: 90, | ||
caption: true, | ||
}; | ||
const validatedOpts = validateOptions(options); | ||
|
||
// Valid options | ||
expect(validatedOpts.title).toBe('Chart Title'); | ||
expect(typeof validatedOpts.subTitle).toBe('function'); | ||
|
||
// Invalid options | ||
expect(validatedOpts.dateCounter).toBe(undefined); | ||
expect(validatedOpts.caption).toBe(undefined); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './options.actions'; | ||
export * from './options.models'; | ||
export * from './options.reducer'; | ||
export * from './validate-options'; |
Oops, something went wrong.