Skip to content

Commit

Permalink
Merge pull request palantir#56 from blueberryapps/add-ava-tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
ondrejbartas authored Aug 4, 2016
2 parents 9df7ed3 + 11f058e commit b63b341
Show file tree
Hide file tree
Showing 30 changed files with 181 additions and 22 deletions.
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies:

test:
override:
- gulp ava
- cd example && gulp:
background: true
- sleep 10
Expand Down
9 changes: 9 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const gulp = require('gulp')
const ava = require('gulp-ava')
const packageJson = require('./package.json')
const path = require('path')

const configureSvgIcon = require('react-svg-icon-generator').default;
Expand All @@ -8,3 +11,9 @@ configureSvgIcon({
reactPureRender: true,
svgDir: path.join(__dirname, 'src', 'icons')
});

gulp.task('ava', () =>
gulp
.src(packageJson.ava.files)
.pipe(ava())
);
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"eslint-plugin-react": "^3.5.1",
"expect": "^1.12.2",
"gulp": "^3.9.1",
"gulp-ava": "^0.12.1",
"mocha": "^2.3.3",
"react-hot-loader": "^1.3.0",
"react-svg-icon-generator": "0.2.2",
Expand All @@ -80,5 +81,14 @@
"react-pure-render": ">=1",
"react-responsive": "^1.1.3",
"tosource": ">=1"
},
"ava": {
"files": [
"src/**/__test__/**/*.js"
],
"require": [
"babel-register",
"babel-polyfill"
]
}
}
2 changes: 1 addition & 1 deletion src/app/AllComponentsPreview.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Component from 'react-pure-render/component';
import headingStyles from './styles/Headings';
import {mediaQueries} from './styles/MediaQueries';
import NotFound from './atoms/NotFound.react';
import parseHighlightedMenu from '../helpers/parseHighlightedMenu';
import parseHighlightedMenu from '../libraries/parseHighlightedMenu';
import Radium from 'radium';
import React, {PropTypes as RPT} from 'react';
import ZoomContent from './atoms/ZoomContent.react';
Expand Down
2 changes: 1 addition & 1 deletion src/app/Page.react.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../helpers/BluekitEvent';
import '../libraries/BluekitEvent';
import Content from './Content.react';
import FontBold from './styles/FontBold';
import MediaQuery from 'react-responsive';
Expand Down
2 changes: 1 addition & 1 deletion src/app/Sidebar.react.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Component from 'react-pure-render/component';
import generateTree from '../helpers/generateTree';
import generateTree from '../libraries/generateTree';
import {mediaQueries} from './styles/MediaQueries';
import MenuNode from './MenuNode.react';
import NotFound from './atoms/NotFound.react';
Expand Down
6 changes: 3 additions & 3 deletions src/app/atoms/AtomPreview.react.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Component from 'react-pure-render/component';
import extendComponentProps from '../../helpers/extendComponentProps';
import filterFunctionProps from '../../helpers/filterFunctionProps';
import extendComponentProps from '../../libraries/extendComponentProps';
import filterFunctionProps from '../../libraries/filterFunctionProps';
import Radium from 'radium';
import React, {PropTypes as RPT} from 'react';
import resolveComponent from '../../helpers/resolveComponent';
import resolveComponent from '../../libraries/resolveComponent';

@Radium
export default class AtomPreview extends Component {
Expand Down
4 changes: 3 additions & 1 deletion src/app/atoms/Input.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class Input extends Component {
'inputSearch'
]),
onChange: RPT.func,
placeholder: RPT.string,
type: RPT.string.isRequired,
value: RPT.string.isRequired
}
Expand All @@ -25,12 +26,13 @@ export default class Input extends Component {
}

render() {
const {inheritedStyles, key, kind, onChange, type, value} = this.props;
const {inheritedStyles, key, kind, onChange, placeholder, type, value} = this.props;

return (
<input
key={key}
onChange={onChange}
placeholder={placeholder}
style={[
styles.base,
styles[kind],
Expand Down
6 changes: 3 additions & 3 deletions src/app/component/Page.react.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Component from 'react-pure-render/component';
import PropsSidebar from './PropsSidebar.react';
import Preview from './Preview.react';
import extendProps from '../../helpers/extendProps';
import extendComponentProps from '../../helpers/extendComponentProps';
import extendProps from '../../libraries/extendProps';
import extendComponentProps from '../../libraries/extendComponentProps';
import {mediaQueries} from '../styles/MediaQueries';
import Radium, {StyleRoot} from 'radium';
import React, {PropTypes as RPT} from 'react';
import ReactDOM from 'react-dom';
import resolveComponent from '../../helpers/resolveComponent';
import resolveComponent from '../../libraries/resolveComponent';
import * as colors from '../styles/Colors';

@Radium
Expand Down
2 changes: 1 addition & 1 deletion src/app/component/SourceCode.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Icon from '../atoms/Icon.react';
import {mediaQueries} from '../styles/MediaQueries';
import Radium from 'radium';
import React, {PropTypes as RPT} from 'react';
import renderProp from '../../helpers/renderProp';
import renderProp from '../../libraries/renderProp';
import spaces from '../styles/Spaces';
import * as colors from '../styles/Colors';

Expand Down
2 changes: 1 addition & 1 deletion src/app/component/Variants.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Component from 'react-pure-render/component';
import headingStyles from '../styles/Headings';
import Radium from 'radium';
import React, {PropTypes as RPT} from 'react';
import renderProp from '../../helpers/renderProp';
import renderProp from '../../libraries/renderProp';
import SourceCode from './SourceCode.react';
import styles from '../styles/Sources';

Expand Down
4 changes: 2 additions & 2 deletions src/createBlueKit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import buildProps from './helpers/buildProps';
import buildProps from './libraries/buildProps';
import fs from 'fs';
import packagedGulp from 'gulp';
import normalizePath from './helpers/normalizePath';
import normalizePath from './libraries/normalizePath';
import nunjucks from 'nunjucks';
import path from 'path';
import toSource from 'tosource';
Expand Down
8 changes: 0 additions & 8 deletions src/helpers/normalizePath.js

This file was deleted.

File renamed without changes.
40 changes: 40 additions & 0 deletions src/libraries/__test__/buildProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import buildProps from '../buildProps';
import test from 'ava';

test('build props', t => {
const props = {
anyProp: {type: {name: 'any'}, required: false},
nodeProp: {type: {name: 'node'}, required: false},
stringPropDefault: {type: {name: 'string'}, required: true, defaultValue: {value: '\'text\'', computed: true}},
stringPropDefaultFalse: {type: {name: 'string'}, required: true, defaultValue: {value: '\'text\'', computed: false}},
stringProp: {type: {name: 'string'}, required: true},
boolProp: {type: {name: 'bool'}, required: false},
numberProp: {type: {name: 'number'}, required: false},
arrayProp: {type: {name: 'array'}, required: false},
objectProp: {type: {name: 'object'}, required: false},
funcProp: {type: {name: 'func'}, required: false},
enumProps: {type: {name: 'enum', value: 'asd'}, required: false},
shapeProps: {type: {name: 'shape', value: {deepValue: 'asd', Qww: 'qwert'}}, required: false},
arrayOfProp: {type: {name: 'arrayOf', value: {nextValue: 'asd', PPoo: 'pppp'}}, required: false},
}

const builtProps = buildProps(props, true)
const arrayOfProps = [
builtProps.arrayOfProp instanceof Array,
typeof builtProps.objectProp === 'object',
builtProps.nodeProp === 'NODE nodeProp',
typeof builtProps.funcProp === 'function',
typeof builtProps.numberProp === 'number' && builtProps.numberProp === 1,
builtProps.stringPropDefault === '\'text\'',
builtProps.boolProp === true || false,
typeof builtProps.enumProps === 'string',
typeof builtProps.shapeProps === 'object',
builtProps.anyProp === 'ANY anyProp',
builtProps.stringProp === 'stringProp',
builtProps.stringPropDefaultFalse === 'text',
builtProps.arrayProp instanceof Array
]
const result = arrayOfProps.reduce((acc, prop) => acc && prop, true)

t.true(result)
})
22 changes: 22 additions & 0 deletions src/libraries/__test__/filterFunctionProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import filterFunctionProps from '../filterFunctionProps';
import test from 'ava';

test('filter function props', t => {
const props = {
width: 'full',
disabled: true,
size: 6,
onClick: () => 'Test function'
}
const filteredProps = filterFunctionProps(props)
const count = Object.keys(filteredProps).length
const functionPropName = Object.keys(filteredProps)
.reduce((acc, key) => {
if (typeof filteredProps[key] === 'function')
acc.push(key)
return acc;
}, [])
.indexOf('Test function') === -1

t.true(count === 3 && functionPropName)
});
17 changes: 17 additions & 0 deletions src/libraries/__test__/generateTree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import generateTree from '../generateTree';
import {Map} from 'immutable';
import test from 'ava';

test('generate components tree', t => {
const componentsIndex = Map({
ExampleFolderButton: Map({
menu: 'Example Folder Button',
name: 'ExampleFolderButton'
})
})
const tree = generateTree(componentsIndex)
const name = tree.getIn(['Example', 'Folder', 'Button'])
const isMap = tree ? Map.isMap(tree) : false
const result = isMap && name === 'ExampleFolderButton'
t.true(result)
});
14 changes: 14 additions & 0 deletions src/libraries/__test__/normalizePath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import normalizePath from '../normalizePath';
import test from 'ava';

test('replace with \'\\\'', t => {
const text = '\\folder\\folder\\file.js'
const result = normalizePath(text, '\\')
t.true(result === '/folder/folder/file.js')
});

test('replace without \'\\\'', t => {
const text = 'folder/folder/file.js'
const result = normalizePath(text)
t.true(result === 'folder/folder/file.js')
});
7 changes: 7 additions & 0 deletions src/libraries/__test__/parseHighlightedMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import parseHighlightedMenu from '../parseHighlightedMenu';
import test from 'ava';

test('parse highlighted', t => {
const result = parseHighlightedMenu('<bstyle=\"color:red\">Text</b>')
t.true(result === '<b style=\"color:red\">Text</b>')
});
37 changes: 37 additions & 0 deletions src/libraries/__test__/renderProp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import renderProp from '../renderProp';
import test from 'ava';

test('passed func', t => {
const result = renderProp('key', 'func', 'value')
t.true(result === 'key={() => alert(\'INSERT YOUR key function\')}')
});

test('passed object', t => {
const result = renderProp('key', 'object', {object: 'objectKey'})
t.true(result === 'key={{\"object\":\"objectKey\"}}')
});

test('passed bool', t => {
const result = renderProp('key', 'bool', true)
t.true(result === 'key={true}')
});

test('passed element', t => {
const result = renderProp('key', 'element', 'value')
t.true(result === 'key={value}')
});

test('passed node', t => {
const result = renderProp('key', 'node', 'value')
t.true(result === 'key={value}')
});

test('passed number', t => {
const result = renderProp('key', 'number', 6)
t.true(result === 'key={6}')
});

test('passed everything else', t => {
const result = renderProp('key', 'number', 'value')
t.true(result === 'key=\"value\"')
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions src/libraries/normalizePath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import path from 'path';

export default function normalizePath(str, separator = path.sep) {
if (separator === '\\') {
str = str.replace(/\\/g, '/');
}
return str;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b63b341

Please sign in to comment.