Skip to content

Commit

Permalink
Add rectangle component
Browse files Browse the repository at this point in the history
  • Loading branch information
sandydoo committed Jun 19, 2021
1 parent ddf7930 commit 8f8975e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions addon/components/g-map.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
canvas=Canvas
marker=(component 'g-map/marker' getContext=(fn this.getComponent))
circle=(component 'g-map/circle' getContext=(fn this.getComponent))
rectangle=(component 'g-map/rectangle' getContext=(fn this.getComponent))
polyline=(component 'g-map/polyline' getContext=(fn this.getComponent))
directions=(component 'g-map/directions' getContext=(fn this.getComponent))
control=(component 'g-map/control' getContext=(fn this.getComponent))
Expand Down
11 changes: 11 additions & 0 deletions addon/components/g-map/rectangle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import TypicalMapComponent from './typical-map-component';

export default class Rectangle extends TypicalMapComponent {
get name() {
return 'rectangles';
}

newMapComponent(options = {}) {
return new google.maps.Rectangle(options);
}
}
1 change: 1 addition & 0 deletions app/components/g-map/rectangle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-google-maps/components/g-map/rectangle';
1 change: 1 addition & 0 deletions docs/app/templates/docs/components.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<li><LinkTo @route="docs.canvas">canvas</LinkTo></li>
<li><LinkTo @route="docs.markers">marker</LinkTo></li>
<li><LinkTo @route="docs.circles">circle</LinkTo></li>
<li>rectangle</li>
<li><LinkTo @route="docs.polylines">polyline</LinkTo></li>
<li><LinkTo @route="docs.info-windows">infoWindow</LinkTo></li>
<li><LinkTo @route="docs.controls">control</LinkTo></li>
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/components/g-map/rectangle-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { setupMapTest } from 'ember-google-maps/test-support';
import { setupLocations } from 'dummy/tests/helpers/locations';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | g-map/rectangle', function (hooks) {
setupRenderingTest(hooks);
setupMapTest(hooks);
setupLocations(hooks);

test('it renders a rectangle', async function (assert) {
await render(hbs`
<GMap @lat={{this.lat}} @lng={{this.lng}} as |g|>
{{#if this.bounds}}
<g.rectangle @bounds={{this.bounds}} />
{{/if}}
</GMap>
`);

let { map } = await this.waitForMap();

this.set('bounds', map.getBounds());

let api = await this.waitForMap();
let rectangle = api.components.rectangles[0].mapComponent;

assert.ok(rectangle, 'rectangle rendered');
assert.ok(
rectangle.getBounds().equals(map.getBounds()),
"rectangle rendered with the map's bounds"
);
});
});

0 comments on commit 8f8975e

Please sign in to comment.