Skip to content

Commit db35bee

Browse files
committed
Fix coordinate editor exceed maxDegrees issue
1 parent 147f731 commit db35bee

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

web/client/components/misc/coordinateeditors/editors/AeronauticalCoordinateEditor.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class AeronauticalCoordinateEditor extends React.Component {
5959
let direction = newValues.direction;
6060
seconds = this.roundToNextSexagesimalStep(seconds);
6161
minutes = this.roundToNextSexagesimalStep(minutes);
62+
if (degrees === this.props.maxDegrees) {
63+
minutes = 0;
64+
seconds = 0;
65+
}
6266
direction = degrees < 0
6367
? (direction === this.props.directions[0] ? this.props.directions[1] : this.props.directions[0])
6468
: direction;

web/client/components/misc/coordinateeditors/editors/__tests__/AeronauticalCoordinateEditor-test.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,26 @@ describe('AeronauticalCoordinateEditor enhancer', () => {
4646
expect(spyonChange).toHaveBeenCalled();
4747
expect(parseFloat(spyonChange.calls[0].arguments[0])).toBe(20);
4848
});
49+
it('Test AeronauticalCoordinateEditor onChange not exceed maxDegrees', () => {
50+
const actions = {
51+
onChange: () => { }
52+
};
53+
const spyonChange = expect.spyOn(actions, 'onChange');
54+
ReactDOM.render(<AeronauticalCoordinateEditor
55+
coordinate="lon"
56+
value={180}
57+
onChange={actions.onChange} />, document.getElementById("container"));
58+
const container = document.getElementById('container');
59+
const elements = container.querySelectorAll('input');
60+
expect(elements.length).toBe(3);
61+
expect(elements[0].value).toBe('180');
62+
expect(elements[1].value).toBe('0');
63+
expect(elements[2].value).toBe('0');
64+
ReactTestUtils.Simulate.change(elements[1], { target: { value: "20" } });
65+
expect(spyonChange).toHaveBeenCalled();
66+
expect(parseFloat(spyonChange.calls[0].arguments[0])).toBe(180);
67+
expect(elements[0].value).toBe('180');
68+
expect(elements[1].value).toBe('0');
69+
expect(elements[2].value).toBe('0');
70+
});
4971
});

0 commit comments

Comments
 (0)