Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
PRETTIER ALL THE THINGS!
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Jul 14, 2017
1 parent 05ace63 commit 4c90f52
Show file tree
Hide file tree
Showing 56 changed files with 855 additions and 923 deletions.
67 changes: 40 additions & 27 deletions app/components/Annotation/__tests__/Annotation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Annotation from '../';
import Line from '../Line';

describe('<Annotation />', () => {

const label = {
name: 'Exon',
color: '#334854',
Expand Down Expand Up @@ -42,7 +41,9 @@ describe('<Annotation />', () => {
annotation={annotation}
label={label}
labelId={labelId}
getAnnotationSegments={() => { return segments; }}
getAnnotationSegments={() => {
return segments;
}}
isSelected={false}
onClick={() => {}}
positionFrom={0}
Expand All @@ -64,7 +65,9 @@ describe('<Annotation />', () => {
annotation={annotation}
label={label}
labelId={labelId}
getAnnotationSegments={() => { return segments; }}
getAnnotationSegments={() => {
return segments;
}}
isSelected={false}
onClick={() => {}}
positionFrom={0}
Expand All @@ -76,16 +79,16 @@ describe('<Annotation />', () => {

it('renders segments on mount', () => {
const labelId = 0;
const segments = [
{ x1: 0, y1: 0, x2: 5, y2: 0 },
];
const segments = [{ x1: 0, y1: 0, x2: 5, y2: 0 }];

const wrapper = shallow(
<Annotation
annotation={annotation}
label={label}
labelId={labelId}
getAnnotationSegments={() => { return segments; }}
getAnnotationSegments={() => {
return segments;
}}
isSelected={false}
onClick={() => {}}
positionFrom={0}
Expand All @@ -98,16 +101,16 @@ describe('<Annotation />', () => {

it('renders segments when new props are received', () => {
const labelId = 0;
const segments = [
{ x1: 0, y1: 0, x2: 5, y2: 0 },
];
const segments = [{ x1: 0, y1: 0, x2: 5, y2: 0 }];

const wrapper = shallow(
<Annotation
annotation={annotation}
label={label}
labelId={labelId}
getAnnotationSegments={() => { return []; }}
getAnnotationSegments={() => {
return [];
}}
isSelected={false}
onClick={() => {}}
positionFrom={0}
Expand All @@ -118,23 +121,27 @@ describe('<Annotation />', () => {
expect(wrapper.find(Line)).to.have.length(0);

// test starts here
wrapper.setProps({ getAnnotationSegments: () => { return segments; } });
wrapper.setProps({
getAnnotationSegments: () => {
return segments;
},
});

expect(wrapper.find(Line)).to.have.length(1);
});

it('dispatches an action on click', () => {
const labelId = 0;
const segments = [
{ x1: 0, y1: 0, x2: 5, y2: 0 },
];
const segments = [{ x1: 0, y1: 0, x2: 5, y2: 0 }];

const wrapper = shallow(
<Annotation
annotation={annotation}
label={label}
labelId={labelId}
getAnnotationSegments={() => { return segments; }}
getAnnotationSegments={() => {
return segments;
}}
isSelected={false}
onClick={() => {}}
positionFrom={0}
Expand All @@ -146,9 +153,7 @@ describe('<Annotation />', () => {

it('should NOT render the tick if annotation is a unit (dimension == 1)', () => {
const labelId = 0;
const segments = [
{ x1: 0, y1: 0, x2: 0, y2: 5 },
];
const segments = [{ x1: 0, y1: 0, x2: 0, y2: 5 }];

// force same positions
const annotation = Object.assign({}, label.annotations.first(), {
Expand All @@ -161,7 +166,9 @@ describe('<Annotation />', () => {
annotation={annotation}
label={label}
labelId={labelId}
getAnnotationSegments={() => { return segments; }}
getAnnotationSegments={() => {
return segments;
}}
isSelected={false}
onClick={() => {}}
positionFrom={0}
Expand All @@ -175,16 +182,16 @@ describe('<Annotation />', () => {

it('should render a tick', () => {
const labelId = 0;
const segments = [
{ x1: 0, y1: 1, x2: 0, y2: 5 },
];
const segments = [{ x1: 0, y1: 1, x2: 0, y2: 5 }];

const wrapper = mount(
<Annotation
annotation={annotation}
label={label}
labelId={labelId}
getAnnotationSegments={() => { return segments; }}
getAnnotationSegments={() => {
return segments;
}}
isSelected={false}
onClick={() => {}}
positionFrom={0}
Expand All @@ -209,7 +216,9 @@ describe('<Annotation />', () => {
annotation={annotation}
label={label}
labelId={labelId}
getAnnotationSegments={() => { return segments; }}
getAnnotationSegments={() => {
return segments;
}}
isSelected={false}
onClick={() => {}}
positionFrom={0}
Expand Down Expand Up @@ -239,7 +248,9 @@ describe('<Annotation />', () => {
annotation={annotation}
label={label}
labelId={labelId}
getAnnotationSegments={() => { return segments; }}
getAnnotationSegments={() => {
return segments;
}}
isSelected={false}
onClick={() => {}}
positionFrom={0}
Expand Down Expand Up @@ -267,7 +278,9 @@ describe('<Annotation />', () => {
annotation={annotation}
label={label}
labelId={labelId}
getAnnotationSegments={() => { return segments; }}
getAnnotationSegments={() => {
return segments;
}}
isSelected={false}
onClick={() => {}}
positionFrom={0}
Expand Down
12 changes: 1 addition & 11 deletions app/components/Annotation/__tests__/Line-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const { describe, it } = global;

import Line from '../Line';


describe('<Line />', () => {

it('renders itself', () => {
const wrapper = shallow(
<Line
Expand Down Expand Up @@ -49,15 +47,7 @@ describe('<Line />', () => {

it('can render a tick for a reverse annotation', () => {
const wrapper = shallow(
<Line
x1={0}
y1={0}
x2={1}
y2={1}
color={'#fff'}
hasTick
isReverse
/>
<Line x1={0} y1={0} x2={1} y2={1} color={'#fff'} hasTick isReverse />
);

expect(wrapper.find('g')).to.have.length(1);
Expand Down
37 changes: 20 additions & 17 deletions app/components/AnnotationForm/__tests__/AnnotationForm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('<AnnotationForm />', () => {
});

it('updates annotation form with selection', () => {
const selections = [{from: 2, to: 4}];
const selections = [{ from: 2, to: 4 }];
const wrapper = mount(
<AnnotationForm
sequence={sequence}
Expand All @@ -54,12 +54,14 @@ describe('<AnnotationForm />', () => {

wrapper.setProps({ selections });

expect(wrapper.find(InputNumberWithInlineButton).get(0).props.value).to.equal(2);
expect(
wrapper.find(InputNumberWithInlineButton).get(0).props.value
).to.equal(2);
expect(wrapper.find(InputNumber).get(0).props.value).to.equal(4);
});

it('updates annotation form with partial selection', () => {
const selections = [{from: 2, to: undefined}];
const selections = [{ from: 2, to: undefined }];
const wrapper = mount(
<AnnotationForm
sequence={sequence}
Expand All @@ -76,8 +78,12 @@ describe('<AnnotationForm />', () => {

wrapper.setProps({ selections });

expect(wrapper.find(InputNumberWithInlineButton).get(0).props.value).to.equal(2);
expect(wrapper.find({placeholder:"To", type:"number", value:''})).to.have.length(1);
expect(
wrapper.find(InputNumberWithInlineButton).get(0).props.value
).to.equal(2);
expect(
wrapper.find({ placeholder: 'To', type: 'number', value: '' })
).to.have.length(1);
});

it('does not show remove button if no annotation is under edition', () => {
Expand Down Expand Up @@ -120,7 +126,7 @@ describe('<AnnotationForm />', () => {
});

it('disables position fields if more than one selection', () => {
const selections = [{ from: 1, to: 2}, { from: 1, to: 2 }];
const selections = [{ from: 1, to: 2 }, { from: 1, to: 2 }];
const wrapper = mount(
<AnnotationForm
sequence={sequence}
Expand All @@ -141,7 +147,7 @@ describe('<AnnotationForm />', () => {
});

it('shows remove button if an annotation is under edition', () => {
const selections = [{from: 10, to: 20}];
const selections = [{ from: 10, to: 20 }];
const current = {
labelId: 123,
annotationId: 456,
Expand All @@ -150,7 +156,7 @@ describe('<AnnotationForm />', () => {
positionTo: 20,
comment: '',
displayTick: true,
}
},
};

const wrapper = mount(
Expand All @@ -169,14 +175,14 @@ describe('<AnnotationForm />', () => {

wrapper.setProps({
current,
selections
selections,
});

expect(wrapper.find('.remove')).to.have.length(1);
});

it('displays the Remove component on "remove" button click', () => {
const selections = [{from: 10, to: 20}];
const selections = [{ from: 10, to: 20 }];
const current = {
labelId: 123,
annotationId: 456,
Expand All @@ -185,7 +191,7 @@ describe('<AnnotationForm />', () => {
positionTo: 20,
comment: '',
displayTick: true,
}
},
};

const wrapper = mount(
Expand All @@ -204,7 +210,7 @@ describe('<AnnotationForm />', () => {

wrapper.setProps({
current,
selections
selections,
});

expect(wrapper.find('.remove')).to.have.length(1);
Expand All @@ -216,10 +222,7 @@ describe('<AnnotationForm />', () => {
});

it('should call onSubmit N times, but onSubmitDone once', () => {
const selections = [
{from: 1, to: 2},
{from: 10, to: 20},
];
const selections = [{ from: 1, to: 2 }, { from: 10, to: 20 }];
const spyOnSubmit = sinon.spy();
const spyOnSubmitDone = sinon.spy();

Expand All @@ -239,7 +242,7 @@ describe('<AnnotationForm />', () => {

wrapper.setProps({
current: null,
selections
selections,
});

const e = { preventDefault: () => {} };
Expand Down
4 changes: 2 additions & 2 deletions app/components/AnnotationForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ function mapDispatchToProps(dispatch) {
onSubmitDone: () => {
dispatch(clearAll());
},
updateSelectionFrom: (positionFrom) => {
updateSelectionFrom: positionFrom => {
dispatch(updateSelectionFrom(positionFrom));
},
updateSelectionTo: (positionTo) => {
updateSelectionTo: positionTo => {
dispatch(updateSelectionTo(positionTo));
},
onRemove: (labelId, annotationId) => {
Expand Down
16 changes: 2 additions & 14 deletions app/components/Exons/__tests__/Exon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ const { describe, it } = global;
import Exon from '../Exon';
import ExonEdit from '../ExonEdit';


describe('<Exon />', () => {

const exon = {
name: 'exon 1',
positionFrom: 10,
Expand Down Expand Up @@ -71,12 +69,7 @@ describe('<Exon />', () => {
it('can be edited', () => {
const spy = sinon.spy();
const wrapper = mount(
<Exon
exon={exon}
onEditExon={spy}
onRemoveExon={() => {}}
index={1}
/>
<Exon exon={exon} onEditExon={spy} onRemoveExon={() => {}} index={1} />
);

wrapper.find('.properties').simulate('click');
Expand Down Expand Up @@ -121,12 +114,7 @@ describe('<Exon />', () => {
it('can be deleted', () => {
const spy = sinon.spy();
const wrapper = mount(
<Exon
exon={exon}
onEditExon={() => {}}
onRemoveExon={spy}
index={1}
/>
<Exon exon={exon} onEditExon={() => {}} onRemoveExon={spy} index={1} />
);

wrapper.find('.properties').simulate('click');
Expand Down
Loading

0 comments on commit 4c90f52

Please sign in to comment.