Skip to content

Commit 4d7f372

Browse files
committed
init
1 parent de3a8e1 commit 4d7f372

30 files changed

+594
-318
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"lint-staged": "^4.3.0",
4545
"lodash": "4.13.1",
4646
"moment": "2.17.1",
47-
"prettier": "^1.7.4",
4847
"prop-types": "^15.6.0",
4948
"react": "15.4.1",
5049
"react-ace": "4.1.5",
@@ -100,7 +99,9 @@
10099
"nock": "^8.0.0",
101100
"node-sass": "3.7.0",
102101
"npm-run-all": "3.1.2",
102+
"prettier": "^1.7.4",
103103
"react-addons-test-utils": "15.4.1",
104+
"react-test-renderer": "15.4.1",
104105
"redux-immutable-state-invariant": "1.2.4",
105106
"redux-mock-store": "^1.0.4",
106107
"rimraf": "2.5.4",

spec/fixtures/site/page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
foo: bar
33
---
44

5-
# Test Page
5+
# Test Page

src/components/MarkdownEditor.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,19 @@ class MarkdownEditor extends Component {
5959
if (onSave) {
6060
toolbarIcons.push({
6161
name: 'save',
62-
action: () => {
63-
onSave();
64-
},
62+
action: onSave,
6563
className: 'fa fa-floppy-o',
6664
title: 'Save',
6765
});
6866
}
6967
opts['toolbar'] = toolbarIcons;
70-
this.editor = new SimpleMDE(opts);
71-
this.editor.codemirror.on('change', () => {
72-
onChange(this.editor.value());
73-
});
68+
const editor = new SimpleMDE(opts);
69+
if (editor.codemirror) {
70+
editor.codemirror.on('change', () => {
71+
onChange(editor.value());
72+
});
73+
}
74+
this.editor = editor;
7475
}
7576

7677
destroy() {

src/components/form/tests/inputpath.spec.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@ import moment from 'moment';
44
import InputPath from '../InputPath';
55

66
const props = {
7-
path: "test.md",
8-
type: "posts",
9-
splat: "test/some/other"
7+
path: 'test.md',
8+
type: 'posts',
9+
splat: 'test/some/other',
1010
};
1111

1212
function setup(defaultProps = props) {
1313
const actions = {
14-
onChange: jest.fn()
14+
onChange: jest.fn(),
1515
};
1616

17-
let component = mount(
18-
<InputPath {...defaultProps} {...actions}/>
19-
);
17+
let component = mount(<InputPath {...defaultProps} {...actions} />);
2018

2119
return {
2220
component: component,
2321
input: component.find('textarea'),
24-
actions
22+
actions,
2523
};
2624
}
2725

@@ -32,9 +30,7 @@ describe('Components::InputPath', () => {
3230
});
3331

3432
it('should prepend date to input value/placeholder for new post', () => {
35-
const { input } = setup(Object.assign({}, props, {
36-
type: 'posts'
37-
}));
33+
const { input } = setup({ ...props, type: 'posts' });
3834
const expectedValue = moment().format('YYYY-MM-DD') + '-your-title.md';
3935
expect(input.prop('placeholder')).toBe(expectedValue);
4036
});

src/components/metadata/tests/metaarrayitem.spec.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import MetaObjectItem from '../MetaObjectItem';
99
import MetaSimple from '../MetaSimple';
1010

1111
const FieldTypes = {
12-
'array': MetaArray,
13-
'object': MetaObject,
14-
'simple': MetaSimple
12+
array: MetaArray,
13+
object: MetaObject,
14+
simple: MetaSimple,
1515
};
1616

1717
const defaultProps = {
@@ -22,7 +22,7 @@ const defaultProps = {
2222
nameAttr: 'metadata["mentors"][1]',
2323
namePrefix: 'metadata["mentors"]',
2424
key_prefix: '',
25-
index: 0
25+
index: 0,
2626
};
2727

2828
function setup(props = defaultProps) {
@@ -32,19 +32,17 @@ function setup(props = defaultProps) {
3232
updateFieldKey: jest.fn(),
3333
updateFieldValue: jest.fn(),
3434
moveArrayItem: jest.fn(),
35-
convertField: jest.fn()
35+
convertField: jest.fn(),
3636
};
3737

38-
let component = mount(
39-
<MetaArrayItem {...props} {...actions} />
40-
);
38+
let component = mount(<MetaArrayItem {...props} {...actions} />);
4139

4240
return {
4341
component,
4442
index: component.find('.array-field-num'),
45-
metabuttons: component.find(MetaButtons) ,
43+
metabuttons: component.find(MetaButtons),
4644
actions,
47-
props
45+
props,
4846
};
4947
}
5048

@@ -53,38 +51,41 @@ describe('Components::MetaArrayItem', () => {
5351
const { component, index } = setup();
5452
let CurrentComponent = FieldTypes[component.prop('type')];
5553
expect(CurrentComponent).toEqual(MetaSimple);
56-
expect(index.text()).toBe(`${defaultProps.index+1}.`);
54+
expect(index.text()).toBe(`${defaultProps.index + 1}.`);
5755
});
56+
5857
it('should render MetaArrayItem with updated props correctly', () => {
59-
const { component } = setup(
60-
Object.assign({}, defaultProps, {
61-
type: 'object',
62-
fieldValue: {
63-
name: "Ben Balter",
64-
username: 'benbalter'
65-
}
66-
})
67-
);
58+
const { component } = setup({
59+
...defaultProps,
60+
type: 'object',
61+
fieldValue: {
62+
name: 'Ben Balter',
63+
username: 'benbalter',
64+
},
65+
});
6866
let CurrentComponent = FieldTypes[component.prop('type')];
6967
expect(CurrentComponent).toEqual(MetaObject);
7068
expect(component.find(MetaObjectItem).length).toBe(2);
7169
});
70+
7271
it('should add `showing-dropdown` class when dropdown button is focused', () => {
7372
const { component, metabuttons } = setup();
7473
let dropdownButton = metabuttons.find('.meta-button');
7574
dropdownButton.simulate('focus');
76-
expect(component.find('.array-item-wrap').hasClass('showing-dropdown')).toEqual(true);
77-
dropdownButton.simulate('blur');
7875
expect(
79-
component.find('.array-item-wrap').node.classList.length
80-
).toBe(1);
76+
component.find('.array-item-wrap').hasClass('showing-dropdown')
77+
).toEqual(true);
78+
dropdownButton.simulate('blur');
79+
expect(component.find('.array-item-wrap').node.classList.length).toBe(1);
8180
});
81+
8282
it('should call removeField when the button clicked', () => {
8383
const { metabuttons, actions } = setup();
8484
let removeFieldButton = metabuttons.find('.remove-field');
8585
removeFieldButton.simulate('mousedown');
8686
expect(actions.removeField).toHaveBeenCalled();
8787
});
88+
8889
it('should call convertField when the button clicked', () => {
8990
const { metabuttons, actions } = setup();
9091
let convertButton = metabuttons.find('.dropdown-wrap span').first();

src/components/metadata/tests/metafield.spec.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import MetaArrayItem from '../MetaArrayItem';
99
import MetaSimple from '../MetaSimple';
1010

1111
const FieldTypes = {
12-
'array': MetaArray,
13-
'object': MetaObject,
14-
'simple': MetaSimple
12+
array: MetaArray,
13+
object: MetaObject,
14+
simple: MetaSimple,
1515
};
1616

1717
const defaultProps = {
@@ -21,7 +21,7 @@ const defaultProps = {
2121
fieldValue: 'page',
2222
nameAttr: 'metadata["layout"]',
2323
namePrefix: 'metadata',
24-
key_prefix: ''
24+
key_prefix: '',
2525
};
2626

2727
function setup(props = defaultProps) {
@@ -31,19 +31,17 @@ function setup(props = defaultProps) {
3131
updateFieldKey: jest.fn(),
3232
updateFieldValue: jest.fn(),
3333
moveArrayItem: jest.fn(),
34-
convertField: jest.fn()
34+
convertField: jest.fn(),
3535
};
3636

37-
let component = mount(
38-
<MetaField {...props} {...actions} />
39-
);
37+
let component = mount(<MetaField {...props} {...actions} />);
4038

4139
return {
4240
component,
4341
keyInput: component.find('.key-field'),
4442
metabuttons: component.find(MetaButtons),
4543
actions,
46-
props
44+
props,
4745
};
4846
}
4947

@@ -54,20 +52,21 @@ describe('Components::MetaField', () => {
5452
expect(CurrentComponent).toEqual(MetaSimple);
5553
expect(keyInput.prop('defaultValue')).toBe(component.prop('fieldKey'));
5654
});
55+
5756
it('should render MetaField with updated props correctly', () => {
58-
const { component, keyInput } = setup(
59-
Object.assign({}, defaultProps, {
60-
type: 'array',
61-
fieldKey: 'students',
62-
fieldValue: ['Mert', 'Ankur'],
63-
nameAttr: 'metadata["students"]'
64-
})
65-
);
57+
const { component, keyInput } = setup({
58+
...defaultProps,
59+
type: 'array',
60+
fieldKey: 'students',
61+
fieldValue: ['Mert', 'Ankur'],
62+
nameAttr: 'metadata["students"]',
63+
});
6664
let CurrentComponent = FieldTypes[component.prop('type')];
6765
expect(CurrentComponent).toEqual(MetaArray);
6866
expect(keyInput.prop('defaultValue')).toBe(component.prop('fieldKey'));
6967
expect(component.find(MetaArrayItem).length).toBe(2);
7068
});
69+
7170
it('should call updateFieldKey when the input lose focus', () => {
7271
const { keyInput, actions } = setup();
7372
keyInput.simulate('blur');
@@ -76,16 +75,18 @@ describe('Components::MetaField', () => {
7675
keyInput.simulate('blur');
7776
expect(actions.updateFieldKey).toHaveBeenCalled();
7877
});
78+
7979
it('should add `showing-dropdown` class when dropdown button is focused', () => {
8080
const { component, metabuttons } = setup();
8181
let dropdownButton = metabuttons.find('.meta-button');
8282
dropdownButton.simulate('focus');
83-
expect(component.find('.metafield').hasClass('showing-dropdown')).toEqual(true);
83+
expect(component.find('.metafield').hasClass('showing-dropdown')).toEqual(
84+
true
85+
);
8486
dropdownButton.simulate('blur');
85-
expect(
86-
component.find('.metafield').node.classList.length
87-
).toBe(1);
87+
expect(component.find('.metafield').node.classList.length).toBe(1);
8888
});
89+
8990
it('should call removeField when the button clicked', () => {
9091
const { metabuttons, actions } = setup();
9192
let removeFieldButton = metabuttons.find('.remove-field');

src/components/metadata/tests/metaobjectitem.spec.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import MetaObjectItem from '../MetaObjectItem';
99
import MetaSimple from '../MetaSimple';
1010

1111
const FieldTypes = {
12-
'array': MetaArray,
13-
'object': MetaObject,
14-
'simple': MetaSimple
12+
array: MetaArray,
13+
object: MetaObject,
14+
simple: MetaSimple,
1515
};
1616

1717
const defaultProps = {
@@ -21,7 +21,7 @@ const defaultProps = {
2121
fieldValue: 'Mert',
2222
nameAttr: 'metadata["students"]["name"]',
2323
namePrefix: 'metadata["students"]',
24-
key_prefix: ''
24+
key_prefix: '',
2525
};
2626

2727
function setup(props = defaultProps) {
@@ -31,19 +31,17 @@ function setup(props = defaultProps) {
3131
updateFieldKey: jest.fn(),
3232
updateFieldValue: jest.fn(),
3333
moveArrayItem: jest.fn(),
34-
convertField: jest.fn()
34+
convertField: jest.fn(),
3535
};
3636

37-
let component = mount(
38-
<MetaObjectItem {...props} {...actions} />
39-
);
37+
let component = mount(<MetaObjectItem {...props} {...actions} />);
4038

4139
return {
4240
component,
4341
keyInput: component.find('.key-field'),
44-
metabuttons: component.find(MetaButtons) ,
42+
metabuttons: component.find(MetaButtons),
4543
actions,
46-
props
44+
props,
4745
};
4846
}
4947

@@ -54,20 +52,21 @@ describe('Components::MetaObjectItem', () => {
5452
expect(CurrentComponent).toEqual(MetaSimple);
5553
expect(keyInput.prop('defaultValue')).toBe(component.prop('fieldKey'));
5654
});
55+
5756
it('should render MetaObjectItem with updated props correctly', () => {
58-
const { component, keyInput } = setup(
59-
Object.assign({}, defaultProps, {
60-
type: 'array',
61-
fieldKey: 'students',
62-
fieldValue: ['Mert', 'Ankur'],
63-
nameAttr: 'metadata["students"]'
64-
})
65-
);
57+
const { component, keyInput } = setup({
58+
...defaultProps,
59+
type: 'array',
60+
fieldKey: 'students',
61+
fieldValue: ['Mert', 'Ankur'],
62+
nameAttr: 'metadata["students"]',
63+
});
6664
let CurrentComponent = FieldTypes[component.prop('type')];
6765
expect(CurrentComponent).toEqual(MetaArray);
6866
expect(keyInput.prop('defaultValue')).toBe(component.prop('fieldKey'));
6967
expect(component.find(MetaArrayItem).length).toBe(2);
7068
});
69+
7170
it('should call updateFieldKey when the input lose focus', () => {
7271
const { keyInput, actions } = setup();
7372
keyInput.simulate('blur');
@@ -76,6 +75,7 @@ describe('Components::MetaObjectItem', () => {
7675
keyInput.simulate('blur');
7776
expect(actions.updateFieldKey).toHaveBeenCalled();
7877
});
78+
7979
it('should add `showing-dropdown` class when dropdown button is focused', () => {
8080
const { component, metabuttons } = setup();
8181
let dropdownButton = metabuttons.find('.meta-button');
@@ -84,16 +84,16 @@ describe('Components::MetaObjectItem', () => {
8484
component.find('.object-item-wrap').hasClass('showing-dropdown')
8585
).toEqual(true);
8686
dropdownButton.simulate('blur');
87-
expect(
88-
component.find('.object-item-wrap').node.classList.length
89-
).toBe(1);
87+
expect(component.find('.object-item-wrap').node.classList.length).toBe(1);
9088
});
89+
9190
it('should call removeField when the button clicked', () => {
9291
const { metabuttons, actions } = setup();
9392
let removeFieldButton = metabuttons.find('.remove-field');
9493
removeFieldButton.simulate('mousedown');
9594
expect(actions.removeField).toHaveBeenCalled();
9695
});
96+
9797
it('should call convertField when the button clicked', () => {
9898
const { metabuttons, actions } = setup();
9999
let convertButton = metabuttons.find('.dropdown-wrap span').first();

0 commit comments

Comments
 (0)