Skip to content

Commit

Permalink
Update position and radius when props change to fix #51
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement Allen committed Jun 17, 2020
1 parent 5bdb9a4 commit ce3a1f9
Show file tree
Hide file tree
Showing 5 changed files with 5,287 additions and 4,418 deletions.
12 changes: 11 additions & 1 deletion __mocks__/MockLeafletPlugin.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
const setStartAngleSpy = jest.fn();
const setStopAngleSpy = jest.fn();
const setRadiusSpy = jest.fn();
const setLatLngSpy = jest.fn();
const setDirectionSpy = jest.fn();

export default jest.fn().mockImplementation(() => {
return {
setStartAngle: setStartAngleSpy,
setStopAngle: setStopAngleSpy,
setRadius: setRadiusSpy,
setLatLng: setLatLngSpy,
setDirection: setDirectionSpy,
_layerAdd: () => {}
};
});

export { setStartAngleSpy, setStopAngleSpy, setDirectionSpy };
export {
setStartAngleSpy,
setStopAngleSpy,
setRadiusSpy,
setLatLngSpy,
setDirectionSpy
};
15 changes: 15 additions & 0 deletions __tests__/AbstractComponent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import AbstractComponent from '../src/AbstractComponent';
import MockLeafletPlugin, {
setStartAngleSpy,
setStopAngleSpy,
setRadiusSpy,
setLatLngSpy,
setDirectionSpy,
} from '../__mocks__/MockLeafletPlugin';

Expand Down Expand Up @@ -36,6 +38,7 @@ describe('<AbstractComponent />', () => {
MockLeafletPlugin.mockClear();
setStartAngleSpy.mockClear();
setStopAngleSpy.mockClear();
setRadiusSpy.mockClear();
setDirectionSpy.mockClear();
testRef = createRef();
wrapper = mount(
Expand Down Expand Up @@ -65,6 +68,14 @@ describe('<AbstractComponent />', () => {
updateProps(wrapper, { stopAngle: 200 });
expect(setStopAngleSpy).toHaveBeenCalledWith(200);
});
it('should call the setRadius method if props change', () => {
updateProps(wrapper, { radius: 1000 });
expect(setRadiusSpy).toHaveBeenCalledWith(1000);
});
it('should call the setLatLng method if props change', () => {
updateProps(wrapper, { position: [51, 0] });
expect(setLatLngSpy).toHaveBeenCalledWith([51, 0]);
});
it('should not call the setStartAngle method if props do not change', () => {
updateProps(wrapper, { startAngle: 90 });
expect(setStartAngleSpy).toHaveBeenCalledTimes(0);
Expand All @@ -73,6 +84,10 @@ describe('<AbstractComponent />', () => {
updateProps(wrapper, { stopAngle: 180 });
expect(setStopAngleSpy).toHaveBeenCalledTimes(0);
});
it('should not call the setRadius method if props do not change', () => {
updateProps(wrapper, { radius: 2000 });
expect(setRadiusSpy).toHaveBeenCalledTimes(0);
});
});

describe('ref methods', () => {
Expand Down
Loading

0 comments on commit ce3a1f9

Please sign in to comment.