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

The Great Tests Crusade #98

Merged
merged 7 commits into from
Mar 19, 2015
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Brocfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ var app = new EmberAddon();
// please specify an object with the list of modules as keys
// along with the exports of each module as its value.

app.import(app.bowerDirectory + '/ember/ember-template-compiler.js');

module.exports = app.toTree();
12 changes: 12 additions & 0 deletions app/layers/bounds-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ArrayPathLayer from './array-path';
import BoundsMixin from '../mixins/bounds';

/**
`EmberLeaflet.PathBoundsLayer` is a base class that takes a list
of locations and computed the bounding box.

@class PathBoundsLayer
@namespace EmberLeaflet
@extends EmberLeaflet.ArrayPathLayer
*/
export default ArrayPathLayer.extend(BoundsMixin, {});
2 changes: 1 addition & 1 deletion app/layers/circle-path.js → app/layers/circle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ember from 'ember';
import PointPathLayer from './point-path';
import PointPathLayer from './point';
import convert from '../utils/convert';

var get = Ember.get;
Expand Down
1 change: 0 additions & 1 deletion app/layers/marker-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import MarkerLayer from './marker';
@class MarkerCollectionLayer
@namespace EmberLeaflet
@extends EmberLeaflet.CollectionLayer
@uses EmberLeaflet.BoundsMixin
*/
export default CollectionLayer.extend({
itemLayerClass: MarkerLayer
Expand Down
3 changes: 3 additions & 0 deletions app/layers/polygon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Ember from 'ember';
import PolylineLayer from './polyline';

var get = Ember.get;

export default PolylineLayer.extend({
_newLayer: function() {
return L.polygon(get(this, 'locations'), get(this, 'options'));
Expand Down
2 changes: 1 addition & 1 deletion app/layers/polyline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ember from 'ember';
import ArrayPathLayer from 'array-path';
import ArrayPathLayer from './array-path';

var get = Ember.get;

Expand Down
2 changes: 1 addition & 1 deletion app/layers/rectangle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ember from 'ember';
import ArrayPathLayer from 'array-path';
import ArrayPathLayer from './array-path';
import BoundsMixin from '../mixins/bounds';

var get = Ember.get;
Expand Down
11 changes: 5 additions & 6 deletions app/mixins/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,15 @@ export default Ember.Mixin.create({
content: get(this, 'content')
});
var self = this;
this._popupView._insertElementLater(function() {
self._popupView.$().appendTo(self._popup._contentNode);
self._popup.update();
});
this._popupView.createElement();
this._popupView.$().appendTo(self._popup._contentNode);
this._popup.update();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a delicate part.
Simple tests are passing, but I would like to know if there is a better way to do this.


// After the view has rendered, call update to ensure
// popup is visible with autoPan
Ember.run.schedule('afterRender', this, function() {
/*Ember.run.schedule('afterRender', this, function() {
self._popup.update();
});
});*/
},

_destroyPopupContent: function() {
Expand Down
8 changes: 8 additions & 0 deletions tests/helpers/locations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
nyc: L.latLng(40.713282, -74.006978),
sf: L.latLng(37.77493, -122.419415),
chicago: L.latLng(41.878114, -87.629798),
paris: L.latLng(48.856614, 2.352222),
london: L.latLng(51.511214, -0.119824),
newdelhi: L.latLng(28.635308, 77.22496)
};
15 changes: 2 additions & 13 deletions tests/unit/components/ember-leaflet-test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import Ember from 'ember';
import {
moduleForComponent,
test,
} from 'ember-qunit';
import { moduleForComponent, test } from 'ember-qunit';
import locationsEqual from '../../helpers/locations-equal';
import locations from '../../helpers/locations';

moduleForComponent('ember-leaflet', 'EmberLeafletComponent', {
// specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar']
});

var locations = {
nyc: L.latLng(40.713282, -74.006978),
sf: L.latLng(37.77493, -122.419415),
chicago: L.latLng(41.878114, -87.629798),
paris: L.latLng(48.856614, 2.352222),
london: L.latLng(51.511214, -0.119824),
newdelhi: L.latLng(28.635308, 77.22496)
};

test('it renders', function(assert) {
assert.expect(2);

Expand Down
62 changes: 62 additions & 0 deletions tests/unit/layers/bounds-path-locprop-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import Ember from 'ember';
import BoundsPathLayer from '../../../layers/bounds-path';
import { module, test } from 'qunit';

var geometry, locations;
var n = [-15.780148, -47.92917],
w = [-15.782102, -47.936869],
s = [-15.786108, -47.931933],
e = [-15.783423, -47.924638];

module('BoundsPathLayer with location property', {
beforeEach: function() {
locations = Ember.A([
Ember.Object.create({lastSeenAt: n}),
Ember.Object.create({lastSeenAt: w}),
Ember.Object.create({lastSeenAt: s}),
Ember.Object.create({lastSeenAt: null}),
Ember.Object.create({lastSeenAt: e})
]);
geometry = BoundsPathLayer.create({
content: locations,
locationProperty: 'lastSeenAt'
});
}
});

test('bounds initializes ok', function(assert) {
var bounds = geometry.get('bounds');
assert.ok(bounds, 'bounds should be initialized');
assert.equal(bounds.getSouth(), s[0]);
assert.equal(bounds.getNorth(), n[0]);
assert.equal(bounds.getWest(), w[1]);
assert.equal(bounds.getEast(), e[1]);
});

test('add an object updates bounds', function(assert) {
var e2 = [-15.782515, -47.914295]; // further east
locations.pushObject(Ember.Object.create({lastSeenAt: e2}));
assert.equal(geometry.get('bounds').getEast(), e2[1]);
});

test('remove an object updates bounds', function(assert) {
Ember.run(function() { locations.replace(3, 2); });
// now northernmost (first) point is most eastward
assert.equal(geometry.get('bounds').getEast(), n[1]);
});

test('update a location updates bound', function(assert) {
locations[1].set('lastSeenAt', e);
// Now bounds don't extend as far west
assert.equal(geometry.get('bounds').getWest(), s[1]);
});

test('clear locations empties bounds', function(assert) {
Ember.run(function() { locations.clear(); });
assert.equal(geometry.get('bounds'), null);
});

test('nullify locations empties bounds', function(assert) {
Ember.run(function() { geometry.set('locations', null); });
assert.equal(geometry.get('bounds'), null);
});
46 changes: 46 additions & 0 deletions tests/unit/layers/bounds-path-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import Ember from 'ember';
import BoundsPathLayer from '../../../layers/bounds-path';
import { module, test } from 'qunit';

var geometry, locations;
var n = [-15.780148, -47.92917],
w = [-15.782102, -47.936869],
s = [-15.786108, -47.931933],
e = [-15.783423, -47.924638];

module('BoundsPathLayer', {
beforeEach: function() {
locations = Ember.A([
L.latLng(n), L.latLng(w), L.latLng(s), null, L.latLng(e)
]);
geometry = BoundsPathLayer.create({
locations: locations
});
}
});

test('bounds initializes ok', function(assert) {
var bounds = geometry.get('bounds');
assert.ok(bounds, 'bounds should be initialized');
assert.equal(bounds.getSouth(), s[0]);
assert.equal(bounds.getNorth(), n[0]);
assert.equal(bounds.getWest(), w[1]);
assert.equal(bounds.getEast(), e[1]);
});

test('add an object updates bounds', function(assert) {
var e2 = [-15.782515, -47.914295]; // further east
locations.pushObject(L.latLng(e2));
assert.equal(geometry.get('bounds').getEast(), e2[1]);
});

test('remove an object updates bounds', function(assert) {
locations.splice(3, 2);
// now northernmost (first) point is most eastward
assert.equal(geometry.get('bounds').getEast(), n[1]);
});

test('clear locations empties bounds', function(assert) {
locations.clear();
assert.equal(geometry.get('bounds'), null);
});
90 changes: 90 additions & 0 deletions tests/unit/layers/circle-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import Ember from 'ember';
import CircleLayer from '../../../layers/circle';
import { moduleForComponent, test } from 'ember-qunit';
import locationsEqual from '../../helpers/locations-equal';
import locations from '../../helpers/locations';

var content, circle, component;

moduleForComponent('ember-leaflet', 'CircleLayer', {
beforeEach: function() {
content = Ember.Object.create({location: locations.sf, radius:10});
circle = CircleLayer.create({
content: content
});

component = this.subject();
component.set('childLayers', [circle]);
this.render();
}
});

test('circle is created', function(assert) {
assert.ok(!!circle._layer);
assert.equal(circle._layer._map, component._layer);
});

test('locations match', function(assert) {
var _layerLocation = circle._layer.getLatLng();
locationsEqual(assert, _layerLocation, locations.sf);
var locationLatLng = circle.get('location');
locationsEqual(assert, locationLatLng, locations.sf);
});

test('radius match', function(assert) {
var _layerRadius = circle._layer.getRadius();
assert.equal(_layerRadius, 10);
var locationRadius = circle.get('radius');
assert.equal(locationRadius, 10);
});

test('set location to null clears circle', function(assert) {
circle.set('location', null);
assert.equal(circle._layer, null);
assert.equal(content.get('location'), null);
});

test('move location in content moves circle', function(assert) {
content.set('location', locations.chicago);
locationsEqual(assert, circle.get('location'), locations.chicago);
locationsEqual(assert, circle._layer.getLatLng(), locations.chicago);
});

test('move location to array moves circle', function(assert) {
content.set('location', [locations.sf.lat, locations.sf.lng]);
assert.deepEqual(circle.get('location'), [locations.sf.lat, locations.sf.lng],
'location is still array');
locationsEqual(assert, circle._layer.getLatLng(), locations.sf,
'but circle center is converted to latLng before going to leatlet');
});

test('change radius in content changes circle radius', function(assert) {
content.set('radius', 20);
assert.equal(circle.get('radius'), 20);
assert.equal(circle._layer.getRadius(), 20);
});

test('nullify location in content clears circle', function(assert) {
content.set('location', null);
assert.equal(circle.get('location'), null);
assert.equal(circle._layer, null);
});

test('circle with null location should not create leaflet obj', function(assert) {
var newCircle = CircleLayer.create({
content: {location: null, radius: 10}
});
component.pushObject(newCircle);
assert.equal(newCircle._layer, null);
});

test('circle with null radius should create leaflet obj', function(assert) {
var newCircle = CircleLayer.create({
content: {location: locations.sf, radius: null}
});
Ember.run(function() {
component.pushObject(newCircle);
});
assert.ok(newCircle._layer);
assert.equal(newCircle._layer._mRadius, null);
});
Loading