-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests] move to jest instead of mocha and update npm scripts. add tes…
…ts for xy-chart chartUtils.
- Loading branch information
1 parent
7661f1c
commit 6078b3b
Showing
12 changed files
with
190 additions
and
34 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ _gh-pages | |
node_modules | ||
*.log | ||
/.eslintcache | ||
coverage |
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
"scripts": { | ||
"lint": "eslint --ignore-path=.eslintignore --ext .js,.jsx ./packages/", | ||
"publish": "npm run lint && lerna run test && lerna publish && lerna run gh-pages", | ||
"test": "lerna run test" | ||
"test": "lerna exec npm install && jest" | ||
}, | ||
"repository": "https://github.com/williaster/data-ui.git", | ||
"keywords": [ | ||
|
@@ -21,24 +21,39 @@ | |
"author": "Chris Williams <[email protected]>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"babel-jest": "^20.0.3", | ||
"babel-polyfill": "^6.23.0", | ||
"babel-register": "^6.24.1", | ||
"chai": "^3.5.0", | ||
"chai-enzyme": "^0.5.2", | ||
"enzyme": "^2.7.0", | ||
"eslint": "^3.19.0", | ||
"eslint-config-airbnb": "^14.1.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-jsx-a11y": "^4.0.0", | ||
"eslint-plugin-react": "^6.10.3", | ||
"jest": "^20.0.3", | ||
"lerna": "^2.0.0-rc.2", | ||
"mocha": "^3.2.0", | ||
"react": "~15.4.2", | ||
"react-addons-test-utils": "^15.5.1", | ||
"react-dom": "~15.4.2" | ||
}, | ||
"peerDependencies": { | ||
"lerna": "2.0.0-rc.2", | ||
"react": "~15.4.2", | ||
"react-dom": "~15.4.2" | ||
}, | ||
"jest": { | ||
"projects": [ | ||
"<rootDir>/packages/*" | ||
], | ||
"collectCoverage": true, | ||
"coverageDirectory": "<rootDir>/coverage", | ||
"coveragePathIgnorePatterns": [ | ||
"/node_modules/" | ||
], | ||
"coverageReporters": [ | ||
"text", | ||
"lcov" | ||
] | ||
} | ||
} | ||
|
||
|
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
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,7 @@ | ||
import Table from '../src/components/Table'; | ||
|
||
describe('<Table />', () => { | ||
test('it should be defined', () => { | ||
expect(Table).toBeDefined(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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
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
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,7 @@ | ||
import { XAxis } from '../src/'; | ||
|
||
describe('<XAxis />', () => { | ||
test('it should be defined', () => { | ||
expect(XAxis).toBeDefined(); | ||
}); | ||
}); |
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,133 @@ | ||
import React from 'react'; | ||
import { BarSeries, LineSeries } from '../src'; | ||
|
||
import { | ||
callOrValue, | ||
getScaleForAccessor, | ||
collectDataFromChildSeries, | ||
} from '../src/utils/chartUtils'; | ||
|
||
describe('collectDataFromChildSeries', () => { | ||
const dummyProps = { xScale: () => {}, yScale: () => {}, label: 'bogus', barWidth: 0 }; | ||
const barData = [{ x: 'bar', y: 123 }]; | ||
const lineData = [{ x: 'line', y: 123 }]; | ||
|
||
const children = [ | ||
<div />, | ||
<BarSeries data={barData} {...dummyProps} />, | ||
<LineSeries data={lineData} {...dummyProps} />, | ||
<BarSeries data={barData} {...dummyProps} />, | ||
null, | ||
]; | ||
|
||
test('should ignore non-series children', () => { | ||
expect( | ||
collectDataFromChildSeries([<span data={[]} />, <div />]).allData, | ||
).toEqual([]); | ||
}); | ||
|
||
const output = collectDataFromChildSeries(children); | ||
|
||
test('should concatenate all data', () => { | ||
expect(output.allData).toEqual([...barData, ...lineData, ...barData]); | ||
}); | ||
|
||
test('should collect data by Series type', () => { | ||
expect(output.dataBySeriesType).toEqual({ | ||
BarSeries: [...barData, ...barData], | ||
LineSeries: [...lineData], | ||
}); | ||
}); | ||
|
||
test('should collect data by child index', () => { | ||
expect(output.dataByIndex).toEqual({ | ||
1: barData, | ||
2: lineData, | ||
3: barData, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('callOrValue', () => { | ||
test('should return non-functions', () => { | ||
expect(callOrValue(123)).toEqual(123); | ||
expect(callOrValue('123')).toEqual('123'); | ||
expect(callOrValue(['hello'])).toEqual(['hello']); | ||
}); | ||
|
||
test('should call a function', () => { | ||
expect(callOrValue(() => 'abc')).toEqual('abc'); | ||
}); | ||
|
||
test('should pass args to functions', () => { | ||
expect(callOrValue((a, b, c) => `${a}${b}${c}`, 'x', 'y')).toEqual('xyundefined'); | ||
}); | ||
}); | ||
|
||
describe('getScaleForAccessor', () => { | ||
const allData = [ | ||
{ date: '2016-01-05', dirtyNum: undefined, num: 124, cat: 'a' }, | ||
{ date: '2017-01-05', dirtyNum: -15, num: 500, cat: 'b' }, | ||
{ date: '2018-01-05', dirtyNum: 7, num: 50, cat: 'c' }, | ||
{ date: '2019-01-05', dirtyNum: null, num: 501, cat: 'z' }, | ||
]; | ||
|
||
test('should compute date domains', () => { | ||
expect(getScaleForAccessor({ | ||
allData, | ||
accessor: d => new Date(d.date), | ||
type: 'time', | ||
range: [0, 100], | ||
}).domain()).toEqual([ | ||
new Date(allData[0].date), | ||
new Date(allData[allData.length - 1].date), | ||
]); | ||
}); | ||
|
||
test('should compute date strings domains', () => { | ||
expect(getScaleForAccessor({ | ||
allData, | ||
accessor: d => d.date, | ||
type: 'band', | ||
range: [0, 100], | ||
}).domain()).toEqual(['2016-01-05', '2017-01-05', '2018-01-05', '2019-01-05']); | ||
}); | ||
|
||
test('should compute categorical domains', () => { | ||
expect(getScaleForAccessor({ | ||
allData, | ||
accessor: d => d.cat, | ||
type: 'band', | ||
range: [0, 100], | ||
}).domain()).toEqual(['a', 'b', 'c', 'z']); | ||
}); | ||
|
||
test('should compute numeric domains including zero', () => { | ||
expect(getScaleForAccessor({ | ||
allData, | ||
accessor: d => d.num, | ||
type: 'linear', | ||
range: [0, 100], | ||
}).domain()).toEqual([0, 501]); | ||
}); | ||
|
||
test('should compute numeric domains excluding zero', () => { | ||
expect(getScaleForAccessor({ | ||
allData, | ||
accessor: d => d.num, | ||
type: 'linear', | ||
range: [0, 100], | ||
includeZero: false, | ||
}).domain()).toEqual([50, 501]); | ||
}); | ||
|
||
test('should compute numeric domains with missing values', () => { | ||
expect(getScaleForAccessor({ | ||
allData, | ||
accessor: d => d.dirtyNum, | ||
type: 'linear', | ||
range: [0, 100], | ||
includeZero: false, | ||
}).domain()).toEqual([-15, 7]); | ||
}); | ||
}); |