{"action":"created","comment":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls/comments/68992018","id":68992018,"diff_hunk":"@@ -1,169 +1,364 @@\n /* eslint no-shadow:[0] */\n import test from 'tape';\n-import mapboxgl from 'mapbox-gl-js-mock';\n+import spy from 'sinon/lib/sinon/spy'; // avoid babel-register-related error by importing only spy\n import GLDraw from '../';\n import createMap from './utils/create_map';\n import getGeoJSON from './utils/get_geojson';\n import AfterNextRender from './utils/after_next_render';\n \n-var feature = getGeoJSON('point');\n+var map = createMap();\n+var afterNextRender = AfterNextRender(map);\n+var Draw = GLDraw();\n+map.addControl(Draw);\n+const addSpy = spy(Draw, 'add');\n+const deleteSpy = spy(Draw, 'delete');\n \n-test('API test', t => {\n-\n-  var map = createMap();\n-  var afterNextRender = AfterNextRender(map);\n-  var Draw = GLDraw();\n-  map.addControl(Draw);\n-\n-  test('init map', t => {\n-    if(map.loaded()) {\n-      t.end();\n-    }\n-    else {\n-      map.once('load', () => t.end());\n-    }\n-  });\n-\n-  t.test('Draw.getFeatureIdsAt', t => {\n-    var id = Draw.add(feature)[0];\n-    afterNextRender(() => {\n-      // These tests require the the pixel space\n-      // and lat/lng space are equal (1px = 1deg)\n-      var featureIds = Draw.getFeatureIdsAt({\n-        x: feature.geometry.coordinates[0],\n-        y: feature.geometry.coordinates[1],\n-      });\n-\n-      t.equals(featureIds.length, 1, 'should have selected the feature');\n-      t.equals(featureIds[0], id, 'selected feature should match desired feature');\n-      Draw.deleteAll();\n-      t.end();\n+test('Draw.getFeatureIdsAt', t => {\n+  var feature = getGeoJSON('point');\n+  var [id] = Draw.add(feature);\n+  afterNextRender(() => {\n+    // These tests require the the pixel space\n+    // and lat/lng space are equal (1px = 1deg)\n+    var featureIds = Draw.getFeatureIdsAt({\n+      x: feature.geometry.coordinates[0],\n+      y: feature.geometry.coordinates[1]\n     });\n-  });\n \n-  t.test('Draw.deleteAll', t => {\n-    Draw.add(getGeoJSON('point'));\n+    t.equals(featureIds.length, 1, 'should return the added feature');\n+    t.equals(featureIds[0], id, 'selected feature should match desired feature');\n     Draw.deleteAll();\n-    t.equals(Draw.getAll().features.length, 0, 'Draw.deleteAll removes all geometries');\n     t.end();\n   });\n+});\n \n-  t.test('Draw.changeMode', t => {\n+test('Draw.getSelectedIds', t => {\n+  const [lineId] = Draw.add(getGeoJSON('line'));\n+  const [pointId] = Draw.add(getGeoJSON('point'));\n+  const [polygonId] = Draw.add(getGeoJSON('polygon'));\n+  Draw.changeMode('simple_select', { featureIds: [lineId, pointId] });\n+  const selected = Draw.getSelectedIds();\n+  t.equal(selected.length, 2,\n+    'returns correct number of ids');\n+  t.notEqual(selected.indexOf(lineId), -1,\n+    'result contains line');\n+  t.notEqual(selected.indexOf(pointId), -1,\n+    'result contains point');\n+  Draw.changeMode('simple_select', { featureIds: [polygonId] });\n+  const nextSelected = Draw.getSelectedIds();\n+  t.equal(nextSelected.length, 1,\n+    'updates length');\n+  t.equal(nextSelected[0], polygonId,\n+    'updates content');\n+  t.end();\n+});\n \n-    Draw.changeMode('draw_'+Draw.types.POLYGON);\n-    var featureCollection = Draw.getAll();\n-    t.equals(featureCollection.features[0].geometry.type, 'Polygon', 'Polygon');\n+test('Draw.set', t => {\n+  const point = getGeoJSON('point');\n+  const line = getGeoJSON('line');\n+  const polygon = getGeoJSON('polygon');\n \n-    Draw.changeMode('draw_'+Draw.types.POINT);\n-    var featureCollection = Draw.getAll();\n-    t.equals(featureCollection.features[0].geometry.type, 'Point', 'Point');\n+  // First set it to one collection\n+  const collection = {\n+    type: 'FeatureCollection',\n+    features: [point, line, polygon]\n+  };\n+  const returnValue = Draw.set(collection);\n+  t.equal(returnValue.length, 3,\n+    'return value is correct length');\n+  const pointId = returnValue[0];\n+  const lineId = returnValue[1];\n+  const polygonId = returnValue[2];\n+  t.equal(Draw.get(pointId).geometry.type, 'Point',\n+    'point id returned');\n+  t.equal(Draw.get(lineId).geometry.type, 'LineString',\n+    'line id returned');\n+  t.equal(Draw.get(polygonId).geometry.type, 'Polygon',\n+    'polygon id returned');\n+  t.equal(Draw.getAll().features.length, 3,\n+    'all features loaded');\n \n-    Draw.changeMode('draw_'+Draw.types.LINE);\n-    var featureCollection = Draw.getAll();\n-    t.equals(featureCollection.features[0].geometry.type, 'LineString', 'Line');\n-    Draw.deleteAll();\n+  // Then set to another\n+  addSpy.reset();\n+  deleteSpy.reset();\n+  const nextCollection = {\n+    type: 'FeatureCollection',\n+    features: [polygon]\n+  };\n+  const nextReturnValue = Draw.set(nextCollection);","path":"test/api.test.js","position":134,"original_position":134,"commit_id":"391a63fb54c93b55d94eb0fd3404f99ef8b7daa2","original_commit_id":"391a63fb54c93b55d94eb0fd3404f99ef8b7daa2","user":{"login":"mcwhittemore","id":1551510,"avatar_url":"https://avatars.githubusercontent.com/u/1551510?v=3","gravatar_id":"","url":"https://api.github.com/users/mcwhittemore","html_url":"https://github.com/mcwhittemore","followers_url":"https://api.github.com/users/mcwhittemore/followers","following_url":"https://api.github.com/users/mcwhittemore/following{/other_user}","gists_url":"https://api.github.com/users/mcwhittemore/gists{/gist_id}","starred_url":"https://api.github.com/users/mcwhittemore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcwhittemore/subscriptions","organizations_url":"https://api.github.com/users/mcwhittemore/orgs","repos_url":"https://api.github.com/users/mcwhittemore/repos","events_url":"https://api.github.com/users/mcwhittemore/events{/privacy}","received_events_url":"https://api.github.com/users/mcwhittemore/received_events","type":"User","site_admin":false},"body":"Here as well.","created_at":"2016-06-29T17:35:42Z","updated_at":"2016-06-29T17:35:42Z","html_url":"https://github.com/mapbox/mapbox-gl-draw/pull/434#discussion_r68992018","pull_request_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls/434","_links":{"self":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls/comments/68992018"},"html":{"href":"https://github.com/mapbox/mapbox-gl-draw/pull/434#discussion_r68992018"},"pull_request":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls/434"}}},"pull_request":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls/434","id":75555847,"html_url":"https://github.com/mapbox/mapbox-gl-draw/pull/434","diff_url":"https://github.com/mapbox/mapbox-gl-draw/pull/434.diff","patch_url":"https://github.com/mapbox/mapbox-gl-draw/pull/434.patch","issue_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/434","number":434,"state":"open","locked":false,"title":"Cleanup and extend API tests","user":{"login":"davidtheclark","id":628431,"avatar_url":"https://avatars.githubusercontent.com/u/628431?v=3","gravatar_id":"","url":"https://api.github.com/users/davidtheclark","html_url":"https://github.com/davidtheclark","followers_url":"https://api.github.com/users/davidtheclark/followers","following_url":"https://api.github.com/users/davidtheclark/following{/other_user}","gists_url":"https://api.github.com/users/davidtheclark/gists{/gist_id}","starred_url":"https://api.github.com/users/davidtheclark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidtheclark/subscriptions","organizations_url":"https://api.github.com/users/davidtheclark/orgs","repos_url":"https://api.github.com/users/davidtheclark/repos","events_url":"https://api.github.com/users/davidtheclark/events{/privacy}","received_events_url":"https://api.github.com/users/davidtheclark/received_events","type":"User","site_admin":false},"body":"@mcwhittemore:\r\n\r\nAlmost all of the changes in `api.js` are just indent changing, because I created the `api` object before the methods so it was easy to return without worrying about `this` context.\r\n\r\nI have one test set failing because of `map.queryRenderedFeatures()` ...","created_at":"2016-06-28T21:44:04Z","updated_at":"2016-06-29T17:35:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"91b7fd43d591aa1c25e7741d937e22194456e49b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls/434/commits","review_comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls/434/comments","review_comment_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/434/comments","statuses_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/statuses/391a63fb54c93b55d94eb0fd3404f99ef8b7daa2","head":{"label":"mapbox:more-unit-tests","ref":"more-unit-tests","sha":"391a63fb54c93b55d94eb0fd3404f99ef8b7daa2","user":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"repo":{"id":29943859,"name":"mapbox-gl-draw","full_name":"mapbox/mapbox-gl-draw","owner":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapbox/mapbox-gl-draw","description":"Draw tools for mapbox-gl-js","fork":false,"url":"https://api.github.com/repos/mapbox/mapbox-gl-draw","forks_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/forks","keys_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/teams","hooks_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/hooks","issue_events_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/events{/number}","events_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/events","assignees_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/assignees{/user}","branches_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/branches{/branch}","tags_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/tags","blobs_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/statuses/{sha}","languages_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/languages","stargazers_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/stargazers","contributors_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/contributors","subscribers_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/subscribers","subscription_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/subscription","commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/contents/{+path}","compare_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/merges","archive_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/downloads","issues_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues{/number}","pulls_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls{/number}","milestones_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/milestones{/number}","notifications_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/labels{/name}","releases_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/releases{/id}","deployments_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/deployments","created_at":"2015-01-28T01:12:21Z","updated_at":"2016-06-27T23:57:27Z","pushed_at":"2016-06-29T17:28:53Z","git_url":"git://github.com/mapbox/mapbox-gl-draw.git","ssh_url":"git@github.com:mapbox/mapbox-gl-draw.git","clone_url":"https://github.com/mapbox/mapbox-gl-draw.git","svn_url":"https://github.com/mapbox/mapbox-gl-draw","homepage":"","size":4243,"stargazers_count":57,"watchers_count":57,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":26,"forks":19,"open_issues":26,"watchers":57,"default_branch":"master"}},"base":{"label":"mapbox:master","ref":"master","sha":"74cdafc9c2971ec00bab21af360020886d9261c9","user":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"repo":{"id":29943859,"name":"mapbox-gl-draw","full_name":"mapbox/mapbox-gl-draw","owner":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapbox/mapbox-gl-draw","description":"Draw tools for mapbox-gl-js","fork":false,"url":"https://api.github.com/repos/mapbox/mapbox-gl-draw","forks_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/forks","keys_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/teams","hooks_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/hooks","issue_events_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/events{/number}","events_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/events","assignees_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/assignees{/user}","branches_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/branches{/branch}","tags_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/tags","blobs_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/statuses/{sha}","languages_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/languages","stargazers_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/stargazers","contributors_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/contributors","subscribers_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/subscribers","subscription_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/subscription","commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/contents/{+path}","compare_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/merges","archive_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/downloads","issues_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues{/number}","pulls_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls{/number}","milestones_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/milestones{/number}","notifications_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/labels{/name}","releases_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/releases{/id}","deployments_url":"https://api.github.com/repos/mapbox/mapbox-gl-draw/deployments","created_at":"2015-01-28T01:12:21Z","updated_at":"2016-06-27T23:57:27Z","pushed_at":"2016-06-29T17:28:53Z","git_url":"git://github.com/mapbox/mapbox-gl-draw.git","ssh_url":"git@github.com:mapbox/mapbox-gl-draw.git","clone_url":"https://github.com/mapbox/mapbox-gl-draw.git","svn_url":"https://github.com/mapbox/mapbox-gl-draw","homepage":"","size":4243,"stargazers_count":57,"watchers_count":57,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":26,"forks":19,"open_issues":26,"watchers":57,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls/434"},"html":{"href":"https://github.com/mapbox/mapbox-gl-draw/pull/434"},"issue":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/434"},"comments":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-draw/issues/434/comments"},"review_comments":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls/434/comments"},"review_comment":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-draw/pulls/434/commits"},"statuses":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-draw/statuses/391a63fb54c93b55d94eb0fd3404f99ef8b7daa2"}}}}
{"actor":{"display_login":"mcwhittemore"}}