Skip to content

Commit

Permalink
Fix: Broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
omgaz committed Oct 21, 2016
1 parent 9fa3346 commit 6526857
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 101 deletions.
28 changes: 12 additions & 16 deletions dist/adslot-ui-main-ugly.js
Original file line number Diff line number Diff line change
Expand Up @@ -8762,18 +8762,10 @@ return /******/ (function(modules) { // webpackBootstrap
var selected = _ref2.selected;
var valueFormatter = _ref2.valueFormatter;


var printPathText = function printPathText(node) {
return (0, _lodash2.default)(node.path).map('label').clone().reverse().join(', ');
};
var printAncestorText = function printAncestorText(node) {
return (0, _lodash2.default)(node.ancestors).map('label').join(', ');
};

var pathElement = !(_lodash2.default.isEmpty(node.path) && _lodash2.default.isEmpty(node.ancestors)) ? _react2.default.createElement(
'span',
{ className: baseClass + '-path' },
!_lodash2.default.isEmpty(node.path) ? printPathText(node) : printAncestorText(node)
!_lodash2.default.isEmpty(node.path) ? (0, _lodash2.default)(node.path).map('label').clone().reverse().join(', ') : (0, _lodash2.default)(node.ancestors).map('label').join(', ')
) : null;

var includeNodeBound = includeNode.bind(null, node);
Expand Down Expand Up @@ -21440,9 +21432,9 @@ return /******/ (function(modules) { // webpackBootstrap

_createClass(FilePickerComponent, [{
key: 'onChange',
value: function onChange(event) {
this.setState({ fileName: event.target.files[0].name });
this.props.onSelect(event.target.files[0]);
value: function onChange(changeEvent) {
this.setState({ fileName: changeEvent.target.files[0].name });
this.props.onSelect(changeEvent.target.files[0]);
}
}, {
key: 'removeFile',
Expand All @@ -21460,6 +21452,9 @@ return /******/ (function(modules) { // webpackBootstrap
var mainClass = (0, _classnames2.default)(_defineProperty({}, baseClass + '-highlight', this.props.isHighlighted), baseClass, 'input-group');
var fileName = this.state.fileName;

var onClickHandler = function onClickHandler() {
_this2.fileInput.click();
};

return _react2.default.createElement(
'div',
Expand All @@ -21483,17 +21478,18 @@ return /******/ (function(modules) { // webpackBootstrap
) : null,
!fileName && !this.props.disabled ? _react2.default.createElement(
_Button2.default,
{ className: 'btn-inverse', onClick: function onClick() {
return _this2.refs.fileInput.click();
} },
{ className: 'btn-inverse', onClick: onClickHandler },
_react2.default.createElement(
'span',
null,
this.props.label
),
_react2.default.createElement('input', {
className: 'file-input',
ref: 'fileInput',
ref: function ref(inputElementRef) {
_this2.fileInput = inputElementRef;
},

type: 'file',
onChange: this.onChange,
accept: this.props.filter,
Expand Down
16 changes: 8 additions & 8 deletions dist/adslot-ui-main.js

Large diffs are not rendered by default.

42 changes: 2 additions & 40 deletions src/components/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,11 @@ class AppComponent extends React.Component {
}

render() {
const baseItem = {
label: 'Awesome Product',
value: 10000,
};

const valueFormatter = (value) => `$${Math.round(value) / 100}`;

const labelFormatter = (item) => `${item.givenName} ${item.surname}`;

const addonFormatter = () => (<Checkbox />);

const nodeRenderer = (value) => (<Checkbox label={value.label}/>);
const nodeRenderer = (value) => (<Checkbox label={value.label} />);

const avatarColor = () => 'cyan';

Expand Down Expand Up @@ -258,37 +251,6 @@ class AppComponent extends React.Component {
};

const emptySvgSymbol = { href: '/assets/svg-symbols.svg#checklist-incomplete' };
const svgSymbol = { href: '/assets/svg-symbols.svg#list' };

const rootTypes = [
{
label: 'Geography',
id: '0',
svgSymbol,
emptySvgSymbol,
isRequired: true,
},
{ label: 'Gender', id: '1', svgSymbol, isRequired: false },
{ label: 'Age', id: '2', svgSymbol, isRequired: false },
];

const auPath = [{ id: '10', label: 'AU' }];

const actNode =
{ id: '0', label: 'Australian Capital Territory', type: 'State', path: auPath, rootTypeId: '0' };

const ntNode = {
id: '1',
isExpandable: true,
label: 'Northern Territory',
path: auPath,
rootTypeId: '0',
type: 'State',
value: 500,
};

const qldNode =
{ id: '2', label: 'Queensland', type: 'State', path: auPath, value: 500, rootTypeId: '0', isExpandable: true };

return (
<div className="index">
Expand Down Expand Up @@ -360,7 +322,7 @@ class AppComponent extends React.Component {
</div>

<div className="btn-panel">
<a className="btn btn-inverse" href="#">Anchor</a>
<a className="btn btn-inverse" href="#top">Anchor</a>
<span className="btn btn-inverse btn-primary">Span</span>
<div className="btn btn-inverse btn-success">Div</div>
</div>
Expand Down
22 changes: 15 additions & 7 deletions src/components/adslotUi/FilePickerComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class FilePickerComponent extends React.Component {
this.removeFile = this.removeFile.bind(this);
}

onChange(event) {
this.setState({ fileName: event.target.files[0].name });
this.props.onSelect(event.target.files[0]);
onChange(changeEvent) {
this.setState({ fileName: changeEvent.target.files[0].name });
this.props.onSelect(changeEvent.target.files[0]);
}

removeFile() {
Expand All @@ -27,6 +27,9 @@ class FilePickerComponent extends React.Component {
render() {
const mainClass = classNames({ [`${baseClass}-highlight`]: this.props.isHighlighted }, baseClass, 'input-group');
const { fileName } = this.state;
const onClickHandler = () => {
this.fileInput.click();
};

return (
<div className={mainClass}>
Expand All @@ -42,18 +45,23 @@ class FilePickerComponent extends React.Component {
<div className="input-group-btn">
{fileName ? <Button className="remove-file" onClick={this.removeFile}>×</Button> : null}
{!fileName && !this.props.disabled ?
<Button className="btn-inverse" onClick={() => this.refs.fileInput.click()}>
<Button className="btn-inverse" onClick={onClickHandler}>
<span>{this.props.label}</span>
<input
className="file-input"
ref="fileInput"
ref={
(inputElementRef) => { this.fileInput = inputElementRef; }
}

type="file"
onChange={this.onChange}
accept={this.props.filter}
data-test-selector={this.props.dts}
/>
</Button> :
<Button bsStyle="primary" disabled>{this.props.label}</Button>}
</Button>
:
<Button bsStyle="primary" disabled>{this.props.label}</Button>
}
</div>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion src/components/adslotUi/ListPickerComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class ListPickerComponent extends React.Component {
<Modal.Body>
{props.modalDescription ? <p>{props.modalDescription}</p> : null}
{_.isEmpty(props.itemInfo) ?
<div className="listpicker-component-body">{listPickerPureElement}</div> :
<div className="listpicker-component-body">{listPickerPureElement}</div>
:
<div className="listpicker-component-body-split">
<SplitPane dts={_.kebabCase(props.itemInfo.label)}>
<Grid>
Expand Down
2 changes: 1 addition & 1 deletion src/components/adslotUi/PagedGridComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PagedGridComponent extends React.Component {
{totalPages > 1 ?
<div className="pagedgrid-component-pagination">
<span className="pagedgrid-component-pagination-info">
{(activePage - 1) * perPage + 1}{Math.min(activePage * perPage, items.length)} of {items.length}
{((activePage - 1) * perPage) + 1}{Math.min(activePage * perPage, items.length)} of {items.length}
</span>
<Pagination
activePage={activePage}
Expand Down
25 changes: 14 additions & 11 deletions src/components/adslotUi/TreePickerNodeComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,27 @@ const TreePickerNodeComponent = ({
selected,
valueFormatter,
}) => {

const printPathText = (node) => _(node.path).map('label').clone().reverse().join(', ');
const printAncestorText = (node) => _(node.ancestors).map('label').join(', ');

const pathElement = !(_.isEmpty(node.path) && _.isEmpty(node.ancestors)) ?
<span className={`${baseClass}-path`}>
{ !_.isEmpty(node.path) ? printPathText(node) : printAncestorText(node) }
</span> :
null;
{ !_.isEmpty(node.path) ?
_(node.path)
.map('label')
.clone()
.reverse()
.join(', ')
:
_(node.ancestors)
.map('label')
.join(', ')
}
</span> : null;

const includeNodeBound = includeNode.bind(null, node);
const removeNodeBound = removeNode.bind(null, node);

const { expandNodeBound, expanderElement } = getExpander({ expandNode, node });

const labelCellProps = expanderElement ?
{ onClick: expandNodeBound } :
{};
const labelCellProps = expanderElement ? { onClick: expandNodeBound } : {};

return (
<div className={`${baseClass}`}>
Expand Down Expand Up @@ -122,7 +125,7 @@ TreePickerNodeComponent.defaultProps = {

selected: false,
valueFormatter: (value) => value,
nodeRenderer: (node) => node.label
nodeRenderer: (node) => node.label,
};

export default TreePickerNodeComponent;
4 changes: 2 additions & 2 deletions src/examples/components/forms.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import mapDispatchToProps from '../redux/actions';
import React, { PropTypes } from 'react';
import {
Button,
Expand All @@ -12,6 +11,7 @@ import {
Select,
} from 'components/distributionEntry';
import { connect } from 'react-redux';
import mapDispatchToProps from '../redux/actions';

const selectFruit = [
{ value: 'du', label: 'Durian' },
Expand Down Expand Up @@ -100,7 +100,7 @@ const ExampleForm = ({
onChange={onChange('textarea')}
placeholder="Text area"
value={formValues.textarea}
></textarea>
/>
<p className="help-block">Help text or example.</p>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion test/components/MainTest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Radio,
RadioGroup,
Toggle,
TreePicker,
TreePickerSimplePure,
UserListPicker,
} from 'components/distributionEntry';
Expand Down
2 changes: 1 addition & 1 deletion test/components/adslotUi/AccordionComponentTest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('AccordionComponent', () => {
});

it('should pass onPanelClick down to panels', () => {
let callback = sinon.spy();
const callback = sinon.spy();
const panels = [panel1, panel2, panel3];
const component = mount(<Accordion panels={panels} onPanelClick={callback} />);
const panelElements = component.find(Panel);
Expand Down
2 changes: 1 addition & 1 deletion test/components/adslotUi/FilePickerComponentTest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('FilePickerComponent', () => {
expect(fileElement.prop('title')).to.equal('');

const selectButtonElement = component.find(Button);
const fileInput = component.instance().refs.fileInput;
const fileInput = component.instance().fileInput;
sinon.spy(fileInput, 'click');
selectButtonElement.simulate('click');
expect(fileInput.click.calledOnce).to.equal(true);
Expand Down
32 changes: 26 additions & 6 deletions test/components/adslotUi/ListPickerComponentTest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,32 @@ describe('ListPickerComponent', () => {
expect(itemInfoLabelElement.children().text()).to.equal('User Details');

const itemInfoPropertyElements = itemInfoGridElement.find(GridRow);
expect(itemInfoPropertyElements.at(1).find(GridCell).first().children().text()).to.equal('Name');
expect(itemInfoPropertyElements.at(1).find(GridCell).last().children().text()).to.equal('Jill Smith');
expect(itemInfoPropertyElements.at(1).find(GridCell).last().prop('dts')).to.equal('name');
expect(itemInfoPropertyElements.at(2).find(GridCell).first().children().text()).to.equal('Age');
expect(itemInfoPropertyElements.at(2).find(GridCell).last().children().text()).to.equal('21');
expect(itemInfoPropertyElements.at(2).find(GridCell).last().prop('dts')).to.equal('age');
expect(itemInfoPropertyElements.at(1).find(GridCell)
.first()
.children()
.text()
).to.equal('Name');
expect(itemInfoPropertyElements.at(1).find(GridCell)
.last()
.children()
.text()
).to.equal('Jill Smith');
expect(itemInfoPropertyElements.at(1).find(GridCell)
.last()
.prop('dts')).to.equal('name');
expect(itemInfoPropertyElements.at(2).find(GridCell)
.first()
.children()
.text()
).to.equal('Age');
expect(itemInfoPropertyElements.at(2).find(GridCell)
.last()
.children()
.text()
).to.equal('21');
expect(itemInfoPropertyElements.at(2).find(GridCell)
.last()
.prop('dts')).to.equal('age');

const listPickerPureElement = splitPaneElements.find(ListPickerPureComponent);
expect(listPickerPureElement.prop('selectedItems')).to.not.equal(initialSelection);
Expand Down
2 changes: 1 addition & 1 deletion test/components/adslotUi/ListPickerPureComponentTest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('ListPickerPureComponent', () => {
it('should render with defaults', () => {
const component = shallow(<ListPickerPureComponent />);
expect(component.prop('className')).to.equal('listpickerpure-component');
expect(component.prop('data-test-selector')).to.equal(`listpickerpure-component-item`);
expect(component.prop('data-test-selector')).to.equal('listpickerpure-component-item');

const gridElements = component.find(Grid);
expect(gridElements).to.have.length(1);
Expand Down
2 changes: 1 addition & 1 deletion test/components/adslotUi/PanelComponentTest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('PanelComponent', () => {
});

it('should trigger onClick when clicking header', () => {
let callback = sinon.spy();
const callback = sinon.spy();

const component = shallow(<Panel onClick={callback} {...panel3} />);
const headerElement = component.find('.panel-component-header');
Expand Down
6 changes: 3 additions & 3 deletions test/components/adslotUi/SearchBarComponentTest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('SearchBarComponent', () => {
});

it('should bind onSearchStringChange to search input change event', () => {
let callback = sinon.spy();
const callback = sinon.spy();
const component = shallow(<SearchBar {...defaultProps} onSearchStringChange={callback} />);
const inputElement = component.find('input');
inputElement.simulate('change', { target: { value: 'Granny Smith' } });
Expand All @@ -51,7 +51,7 @@ describe('SearchBarComponent', () => {
});

it('should bind onSearch to search input key press event', () => {
let callback = sinon.spy();
const callback = sinon.spy();
const component = shallow(<SearchBar {...defaultProps} onSearch={callback} />);
const inputElement = component.find('input');
const ENTER_KEY = 13;
Expand All @@ -63,7 +63,7 @@ describe('SearchBarComponent', () => {
});

it('should bind onSearch to search button click event', () => {
let callback = sinon.spy();
const callback = sinon.spy();
const component = shallow(<SearchBar {...defaultProps} onSearch={callback} />);
const buttonElement = component.find(Button);
buttonElement.simulate('click');
Expand Down
6 changes: 5 additions & 1 deletion test/components/adslotUi/TreePickerNodeComponentTest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ describe('TreePickerNodeComponent', () => {
});

it('should render node via nodeRenderer', () => {
const component = shallow(<TreePickerNodeComponent itemType={itemType} node={actNode} nodeRenderer={nodeRenderer} />);
const component = shallow(<TreePickerNodeComponent
itemType={itemType}
node={actNode}
nodeRenderer={nodeRenderer}
/>);

const rowElement = component.find(GridRow);
const cellElements = rowElement.find(GridCell);
Expand Down

0 comments on commit 6526857

Please sign in to comment.