-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix c125_75 Aeronautical Coordinate issues
- Loading branch information
1 parent
09b42c5
commit eb6ef4c
Showing
8 changed files
with
155 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...omponents/mapcontrols/annotations/editors/__tests__/AeronauticalCoordinateEditor-test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const React = require('react'); | ||
const ReactDOM = require('react-dom'); | ||
const ReactTestUtils = require('react-dom/test-utils'); | ||
const expect = require('expect'); | ||
const AeronauticalCoordinateEditor = require('../AeronauticalCoordinateEditor'); | ||
|
||
describe('AeronauticalCoordinateEditor enhancer', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('AeronauticalCoordinateEditor rendering with defaults', () => { | ||
ReactDOM.render(<AeronauticalCoordinateEditor />, document.getElementById("container")); | ||
const container = document.getElementById('container'); | ||
const elements = container.querySelectorAll('input'); | ||
expect(elements.length).toBe(3); | ||
}); | ||
it('AeronauticalCoordinateEditor rendering with 13.3333333333', () => { | ||
ReactDOM.render(<AeronauticalCoordinateEditor value={13.3333333333} />, document.getElementById("container")); | ||
const container = document.getElementById('container'); | ||
const elements = container.querySelectorAll('input'); | ||
expect(elements.length).toBe(3); | ||
expect(elements[0].value).toBe('13'); | ||
expect(elements[1].value).toBe('20'); | ||
expect(elements[2].value).toBe('0'); | ||
}); | ||
it('Test AeronauticalCoordinateEditor onChange', () => { | ||
const actions = { | ||
onChange: () => {} | ||
}; | ||
const spyonChange = expect.spyOn(actions, 'onChange'); | ||
ReactDOM.render(<AeronauticalCoordinateEditor value={19} onChange={actions.onChange} />, document.getElementById("container")); | ||
const container = document.getElementById('container'); | ||
|
||
const elements = container.querySelectorAll('input'); | ||
expect(elements.length).toBe(3); | ||
expect(elements[0].value).toBe('19'); | ||
expect(elements[1].value).toBe('0'); | ||
expect(elements[2].value).toBe('0'); | ||
ReactTestUtils.Simulate.change(elements[0], { target: { value: "20" } }); | ||
expect(spyonChange).toHaveBeenCalled(); | ||
expect(parseFloat(spyonChange.calls[0].arguments[0])).toBe(20); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
web/client/components/mapcontrols/annotations/enhancers/__tests__/no90Lat-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const React = require('react'); | ||
const ReactDOM = require('react-dom'); | ||
const {createSink} = require('recompose'); | ||
const expect = require('expect'); | ||
const no90Lat = require('../no90Lat'); | ||
|
||
describe('no90Lat enhancer', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('no90Lat rendering with defaults', (done) => { | ||
const onChange = (v) => { | ||
expect(parseFloat(v)).toBeLessThan(90); | ||
}; | ||
const Sink = no90Lat(createSink( props => { | ||
expect(props).toExist(); | ||
props.onChange("90"); | ||
done(); | ||
})); | ||
ReactDOM.render(<Sink coordinate="lat" onChange={onChange} />, document.getElementById("container")); | ||
}); | ||
it('no90Lat rendering with negative value', (done) => { | ||
const onChange = (v) => { | ||
expect(parseFloat(v)).toBeMoreThan(-90); | ||
}; | ||
const Sink = no90Lat(createSink(props => { | ||
expect(props).toExist(); | ||
props.onChange("-90"); | ||
done(); | ||
})); | ||
ReactDOM.render(<Sink coordinate="lat" onChange={onChange} />, document.getElementById("container")); | ||
}); | ||
it('no90Lat rendering with lon', (done) => { | ||
const onChange = (v) => { | ||
expect(parseFloat(v)).toBe(90); | ||
}; | ||
const Sink = no90Lat(createSink(props => { | ||
expect(props).toExist(); | ||
props.onChange("90"); | ||
done(); | ||
})); | ||
ReactDOM.render(<Sink coordinate="lon" onChange={onChange} />, document.getElementById("container")); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
web/client/components/mapcontrols/annotations/enhancers/no90Lat.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const {compose, withHandlers} = require('recompose'); | ||
|
||
/** | ||
* This workaround issues with annotations at 90 degrees lat. | ||
* This avoid wrong input from user breaks the draw support | ||
* // TODO: remove this in favor of some more general enhancer or some check inside draw support | ||
*/ | ||
module.exports = compose( | ||
withHandlers({ | ||
onChange: ({ onChange = () => { }, maxLatitude = 89.9997222222, coordinate}) => v => | ||
onChange( | ||
Math.abs(parseFloat(v)) > maxLatitude && coordinate === "lat" | ||
? Math.sign(v) * maxLatitude | ||
: v | ||
) | ||
}) | ||
); |
File renamed without changes.