Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for function reliant on turf dependency #769

Open
cafca opened this issue Feb 9, 2021 · 3 comments · May be fixed by #956
Open

Add test for function reliant on turf dependency #769

cafca opened this issue Feb 9, 2021 · 3 comments · May be fixed by #956
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@cafca
Copy link
Collaborator

cafca commented Feb 9, 2021

We are using turf only for this single piece of code and therefore are not tracking changes in turf releases. To guard against breaking api changes in future turf releases etc. we should add a test for this function.

export function getCenterFromGeom(geometry, defaultCenter = null) {
if (geometry && geometry.coordinates) {
if (geometry.type === 'MultiLineString') {
geometry = turfLineString(
geometry.coordinates.reduce((res, coord) => res.concat(coord)),
[]
);
}
const length = turfLength(geometry);
return turfAlong(geometry, length * 0.5).geometry.coordinates;
}
return defaultCenter;
}

This is a good issue for first contributors. Please leave a message here if you would like assistance.

@cafca cafca added help wanted Extra attention is needed good first issue Good for newcomers labels Feb 9, 2021
@s-pic
Copy link
Collaborator

s-pic commented Jan 20, 2022

@tordans @cafca Can I tackle that?

@tordans
Copy link
Contributor

tordans commented Jan 20, 2022

@s-pic I will not be able to help much (not knowing this part of the code yet and not being "fluent" in unit tests, yet :)), but yes, feel free. CC @ohrie.
I see those places currently using turf:

package.json:
  42      "@material-ui/styles": "^4.11.4",
  43:     "@turf/along": "6.0.1",
  44:     "@turf/boolean-within": "^6.0.1",
  45:     "@turf/center": "^6.3.0",
  46:     "@turf/helpers": "^6.1.4",
  47:     "@turf/length": "^6.3.0",
  48      "abortcontroller-polyfill": "^1.7.3",

src/apps/Gastro/components/AreaMap.tsx:
   1: import turfCenter from '@turf/center';
   2  import MapboxGL, { LngLatLike } from 'mapbox-gl';

  43    if (showAreaPin) {
  44:     const center = turfCenter(area);
  45      new MapboxGL.Marker({ color: config.colors.interaction })

src/apps/Map/map-utils.ts:
    1: import turfAlong from '@turf/along';
    2: import { lineString as turfLineString } from '@turf/helpers';
    3: import turfLength from '@turf/length';
    4  import debug from 'debug';

  191      if (geometry.type === 'MultiLineString') {
  192:       lineString = turfLineString(
  193          geometry.coordinates.reduce((res, coord) => res.concat(coord)),

  197  
  198:     const length = turfLength(lineString);
  199:     return turfAlong(lineString, length * 0.5).geometry.coordinates;
  200    }

src/pages/Reports/state/SubmitReportState.js:
  1  /* eslint-disable  no-multi-spaces */
  2: import booleanWithin from '@turf/boolean-within';
  3  

@s-pic
Copy link
Collaborator

s-pic commented Jan 20, 2022

Nice. Will try to add proper types (get rid of the any annotation for the first function arg) as well.

s-pic added a commit that referenced this issue Jan 20, 2022
that actually tests the calculation using a simple example. Goal is to detect regressions caused by updating the turf.js version

closes #769
@s-pic s-pic linked a pull request Jan 20, 2022 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants