Fix linting issues

This commit is contained in:
Damian Mooyman 2016-10-11 16:49:24 +13:00
parent 5a5d62fa27
commit 72fd3b949e
10 changed files with 48 additions and 76 deletions

View File

@ -2137,7 +2137,7 @@ function t(e){r(this,t)
var n=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e)) var n=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e))
return n.handleChange=n.handleChange.bind(n),n}return a(t,e),s(t,[{key:"handleChange",value:function n(e){"function"==typeof this.props.onChange?this.props.onChange(e,{id:this.props.id,value:e.target.checked?1:0 return n.handleChange=n.handleChange.bind(n),n}return a(t,e),s(t,[{key:"handleChange",value:function n(e){"function"==typeof this.props.onChange?this.props.onChange(e,{id:this.props.id,value:e.target.checked?1:0
}):"function"==typeof this.props.onClick&&this.props.onClick(e,{id:this.props.id,value:e.target.checked?1:0})}},{key:"getInputProps",value:function i(){return{id:this.props.id,name:this.props.name,disabled:this.props.disabled, }):"function"==typeof this.props.onClick&&this.props.onClick(e,{id:this.props.id,value:e.target.checked?1:0})}},{key:"getInputProps",value:function i(){return{id:this.props.id,name:this.props.name,disabled:this.props.disabled,
readOnly:this.props.readOnly,className:this.props.className+" "+this.props.extraClass,onChange:this.handleChange,checked:!!this.props.value,value:1}}},{key:"render",value:function l(){var e=null!==this.props.leftTitle?this.props.leftTitle:this.props.title,t=void 0 readOnly:this.props.readOnly,className:this.props.className+" "+this.props.extraClass,onChange:this.handleChange,checked:!!this.props.value,value:1}}},{key:"render",value:function l(){var e=null!==this.props.leftTitle?this.props.leftTitle:this.props.title,t=null
switch(this.props.type){case"checkbox":t=h.Checkbox switch(this.props.type){case"checkbox":t=h.Checkbox

View File

@ -5,7 +5,7 @@ jest.unmock('react-addons-test-utils');
jest.unmock('../CheckboxSetField'); jest.unmock('../CheckboxSetField');
import React from 'react'; import React from 'react';
import ReactTestUtils from'react-addons-test-utils'; import ReactTestUtils from 'react-addons-test-utils';
// get non-default because it uses FieldHolder by default // get non-default because it uses FieldHolder by default
import { CheckboxSetField } from '../CheckboxSetField'; import { CheckboxSetField } from '../CheckboxSetField';
@ -68,7 +68,7 @@ describe('CheckboxSetField', () => {
}); });
it('should generate a key for field', () => { it('should generate a key for field', () => {
const key = checkboxSetField.getItemKey({value: 'two'}); const key = checkboxSetField.getItemKey({ value: 'two' });
expect(key).toEqual('checkbox-two'); expect(key).toEqual('checkbox-two');
}); });
@ -87,7 +87,7 @@ describe('CheckboxSetField', () => {
it('should add the selected value', () => { it('should add the selected value', () => {
const event = new Event('click'); const event = new Event('click');
checkboxSetField.handleChange(event, {id: 'checkbox-two', value: 1}); checkboxSetField.handleChange(event, { id: 'checkbox-two', value: 1 });
expect(checkboxSetField.props.onChange).toBeCalledWith( expect(checkboxSetField.props.onChange).toBeCalledWith(
event, event,
@ -98,7 +98,7 @@ describe('CheckboxSetField', () => {
it('should remove the unselected value', () => { it('should remove the unselected value', () => {
const event = new Event('click'); const event = new Event('click');
checkboxSetField.handleChange(event, {id: 'checkbox-one', value: 0}); checkboxSetField.handleChange(event, { id: 'checkbox-one', value: 0 });
expect(checkboxSetField.props.onChange).toBeCalledWith( expect(checkboxSetField.props.onChange).toBeCalledWith(
event, event,

View File

@ -14,9 +14,8 @@ class CompositeField extends SilverStripeComponent {
'legend', 'legend',
this.props.data.legend this.props.data.legend
); );
} else {
return null;
} }
return null;
} }
render() { render() {

View File

@ -17,11 +17,11 @@ class LookupField extends SilverStripeComponent {
* @returns {string} csv * @returns {string} csv
*/ */
getValueCSV() { getValueCSV() {
let values = this.props.value; const values = this.props.value;
if (!Array.isArray(values) && if (!Array.isArray(values) &&
(values || typeof values === 'string' || typeof values === 'number')) { (values || typeof values === 'string' || typeof values === 'number')) {
const item = this.props.source.find((item) => item.value === values); const item = this.props.source.find((next) => next.value === values);
if (item) { if (item) {
return item.title; return item.title;
} }
@ -33,7 +33,7 @@ class LookupField extends SilverStripeComponent {
} }
return values return values
.map((value) => { .map((value) => {
const item = this.props.source.find((item) => item.value === value); const item = this.props.source.find((next) => next.value === value);
return item && item.title; return item && item.title;
}) })
.filter((value) => `${value}`.length) .filter((value) => `${value}`.length)
@ -46,7 +46,6 @@ class LookupField extends SilverStripeComponent {
* @returns {object} properties * @returns {object} properties
*/ */
getFieldProps() { getFieldProps() {
return { return {
id: this.props.id, id: this.props.id,
name: this.props.name, name: this.props.name,

View File

@ -55,7 +55,7 @@ class OptionField extends SilverStripeComponent {
: this.props.title; : this.props.title;
// default and fallback to a Radio button // default and fallback to a Radio button
let Option; let Option = null;
switch (this.props.type) { switch (this.props.type) {
case 'checkbox': case 'checkbox':

View File

@ -34,7 +34,7 @@ describe('OptionsetField', () => {
describe('getItemKey()', () => { describe('getItemKey()', () => {
it('should generate a key for field', () => { it('should generate a key for field', () => {
const key = setField.getItemKey({value: 'two'}); const key = setField.getItemKey({ value: 'two' });
expect(key).toEqual('set-two'); expect(key).toEqual('set-two');
}); });
@ -44,7 +44,7 @@ describe('OptionsetField', () => {
it('should set the selected value', () => { it('should set the selected value', () => {
const event = new Event('click'); const event = new Event('click');
setField.handleChange(event, {id: 'set-one', value: 1}); setField.handleChange(event, { id: 'set-one', value: 1 });
expect(setField.props.onChange).toBeCalledWith( expect(setField.props.onChange).toBeCalledWith(
event, event,

View File

@ -151,7 +151,9 @@ class CampaignAdminList extends SilverStripeComponent {
return ( return (
<div className="fill-width campaigns"> <div className="fill-width campaigns">
<div className="fill-height campaign-items cms-content__left cms-campaigns" aria-expanded="true"> <div className="fill-height campaign-items cms-content__left cms-campaigns"
aria-expanded="true"
>
<Toolbar showBackButton handleBackButtonClick={this.props.handleBackButtonClick}> <Toolbar showBackButton handleBackButtonClick={this.props.handleBackButtonClick}>
<BreadcrumbComponent multiline crumbs={this.props.breadcrumbs} /> <BreadcrumbComponent multiline crumbs={this.props.breadcrumbs} />
</Toolbar> </Toolbar>

View File

@ -8,6 +8,15 @@ jest.unmock('merge');
import backend from '../Backend'; import backend from '../Backend';
/**
* Return a mock function that returns a promise
*/
function getMockPromise(data) {
const mock = jest.genMockFunction();
mock.mockImplementation(() => Promise.resolve(data));
return mock;
}
// Mock out the get/post/put/delete methods in the backend // Mock out the get/post/put/delete methods in the backend
// So that we can isolate our test to the behaviour of createEndpointFetcher() // So that we can isolate our test to the behaviour of createEndpointFetcher()
// The mocked getters will pass returnValue to the resulting promise's then() call // The mocked getters will pass returnValue to the resulting promise's then() call
@ -20,15 +29,6 @@ function getBackendMock(returnValue) {
}); });
} }
/**
* Return a mock function that returns a promise
*/
function getMockPromise(data) {
const mock = jest.genMockFunction();
mock.mockImplementation(() => Promise.resolve(data));
return mock;
}
describe('Backend', () => { describe('Backend', () => {
beforeEach(() => { beforeEach(() => {
backend.fetch = getMockPromise({ backend.fetch = getMockPromise({
@ -151,13 +151,10 @@ describe('Backend', () => {
const promise = endpoint({ id: 1, values: { a: 'aye', b: 'bee' } }); const promise = endpoint({ id: 1, values: { a: 'aye', b: 'bee' } });
expect(mock.get) expect(mock.get)
.toBeCalledWith( .toBeCalledWith('http://example.org?id=1&values%5Ba%5D=aye&values%5Bb%5D=bee', {
'http://example.org?id=1&values%5Ba%5D=aye&values%5Bb%5D=bee', Accept: 'application/json',
{ 'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json', });
'Content-Type': 'application/x-www-form-urlencoded',
}
);
return promise return promise
.catch((e) => expect(e).toBeFalsy()) .catch((e) => expect(e).toBeFalsy())
@ -177,8 +174,7 @@ describe('Backend', () => {
expect(mock.post) expect(mock.post)
.toBeCalledWith( .toBeCalledWith(
'http://example.org', 'http://example.org',
'{"id":1,"values":{"a":"aye","b":"bee"}}', '{"id":1,"values":{"a":"aye","b":"bee"}}', {
{
Accept: 'application/json', Accept: 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
} }
@ -207,8 +203,7 @@ describe('Backend', () => {
expect(mock.post) expect(mock.post)
.toBeCalledWith( .toBeCalledWith(
'http://example.com/1/2/?foo=bar', 'http://example.com/1/2/?foo=bar',
'two=2&three=3', 'two=2&three=3', {
{
Accept: 'application/json', Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
} }
@ -239,8 +234,7 @@ describe('Backend', () => {
expect(mock.post) expect(mock.post)
.toBeCalledWith( .toBeCalledWith(
'http://example.com/1/2/?foo=bar&three=3', 'http://example.com/1/2/?foo=bar&three=3',
'{"two":2}', '{"two":2}', {
{
Accept: 'application/json', Accept: 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
} }
@ -268,13 +262,10 @@ describe('Backend', () => {
}); });
expect(mock.get) expect(mock.get)
.toBeCalledWith( .toBeCalledWith('http://example.com/1/2/?foo=bar&two=2&three=3', {
'http://example.com/1/2/?foo=bar&two=2&three=3', Accept: 'application/json',
{ 'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json', });
'Content-Type': 'application/x-www-form-urlencoded',
}
);
return promise return promise
.catch((e) => expect(e).toBeFalsy()) .catch((e) => expect(e).toBeFalsy())
@ -302,8 +293,7 @@ describe('Backend', () => {
two: 'updated', two: 'updated',
four: { fourOne: true, fourTwo: true }, four: { fourOne: true, fourTwo: true },
three: 3, three: 3,
}), }), {
{
Accept: 'application/json', Accept: 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
} }

View File

@ -4,46 +4,25 @@ jest.unmock('react');
jest.unmock('react-addons-test-utils'); jest.unmock('react-addons-test-utils');
jest.unmock('../castStringToElement'); jest.unmock('../castStringToElement');
import React from 'react';
import castStringToElement from '../castStringToElement'; import castStringToElement from '../castStringToElement';
import CompositeField from 'components/CompositeField/CompositeField'; import CompositeField from 'components/CompositeField/CompositeField';
describe('castStringToElement', () => { describe('castStringToElement', () => {
let props = null;
beforeEach(() => {
props = {
id: '',
title: '',
name: '',
};
});
it('should render a simple div with string', () => { it('should render a simple div with string', () => {
const Element = castStringToElement( const Element = castStringToElement('div', 'My div');
'div',
'My div',
);
expect(Element.type).toEqual('div'); expect(Element.type).toEqual('div');
expect(Element.props.children).toEqual('My div'); expect(Element.props.children).toEqual('My div');
}); });
it('should render a simple div with string given an object', () => { it('should render a simple div with string given an object', () => {
const Element = castStringToElement( const Element = castStringToElement('div', { text: 'My div in an object' });
'div',
{ text: 'My div in an object' },
);
expect(Element.type).toEqual('div'); expect(Element.type).toEqual('div');
expect(Element.props.children).toEqual('My div in an object'); expect(Element.props.children).toEqual('My div in an object');
}); });
it('should render a CompositeField with string', () => { it('should render a CompositeField with string', () => {
const Element = castStringToElement( const Element = castStringToElement(CompositeField, 'My string content');
CompositeField,
'My string content',
);
expect(Element.type.name).toEqual('CompositeField'); expect(Element.type.name).toEqual('CompositeField');
expect(Element.props.children).toEqual('My string content'); expect(Element.props.children).toEqual('My string content');
@ -52,7 +31,7 @@ describe('castStringToElement', () => {
it('should render a CompositeField with setInnerHtml given an object', () => { it('should render a CompositeField with setInnerHtml given an object', () => {
const Element = castStringToElement( const Element = castStringToElement(
CompositeField, CompositeField,
{ html: '<div>My div content in something</div>' }, { html: '<div>My div content in something</div>' }
); );
expect(Element.type.name).toEqual('CompositeField'); expect(Element.type.name).toEqual('CompositeField');

View File

@ -140,13 +140,16 @@
// Reference https://css-tricks.com/boxes-fill-height-dont-squish/ // Reference https://css-tricks.com/boxes-fill-height-dont-squish/
// Reference http://codepen.io/clarkepaul/pen/qaNWAY // Reference http://codepen.io/clarkepaul/pen/qaNWAY
*, *:before, *:after { *,
-moz-box-sizing: border-box; *:before,
-webkit-box-sizing: border-box; *:after {
box-sizing: border-box; -moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
} }
html, body { html,
body {
width: 100%; width: 100%;
height: 100%; height: 100%;
margin: 0; margin: 0;