Skip to content

Commit

Permalink
Merge pull request ngageoint#511 from robertbolan-bits/os353_Track_An…
Browse files Browse the repository at this point in the history
…notations

Os353 track annotations
  • Loading branch information
welchyd authored May 2, 2019
2 parents 0fb2a3b + 243030c commit b57ba8f
Show file tree
Hide file tree
Showing 2 changed files with 266 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/plugin/file/kml/ui/placemarkedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ plugin.file.kml.ui.PlacemarkEditCtrl = function($scope, $element, $timeout) {
this['dateType'] = os.ui.datetime.AnyDateType.INSTANT;
}
}
if (!this.isFeatureDynamic()) {
var optionsListId = 'optionsList' + this['uid'];

var optionsListId = 'optionsList' + this['uid'];
os.ui.list.add(optionsListId,
'<annotationoptions options="ctrl.annotationOptions"></annotationoptions>');
os.ui.list.add(optionsListId,
'<annotationoptions options="ctrl.annotationOptions"></annotationoptions>');

if (this.options['annotation']) {
// if creating a new annotation, expand the Annotation Options section by default
this.defaultExpandedOptionsId = 'featureAnnotation' + this['uid'];
if (this.options['annotation']) {
// if creating a new annotation, expand the Annotation Options section by default
this.defaultExpandedOptionsId = 'featureAnnotation' + this['uid'];
}
}
};
goog.inherits(plugin.file.kml.ui.PlacemarkEditCtrl, os.ui.FeatureEditCtrl);
Expand Down
258 changes: 258 additions & 0 deletions test/plugin/file/kml/ui/placemarkededit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
goog.require('os.feature.DynamicFeature');
goog.require('plugin.file.kml.ui');
goog.require('plugin.file.kml.ui.PlacemarkEditCtrl');
goog.require('plugin.file.kml.ui.placemarkEditDirective');



describe('plugin.file.kml.ui.placemarkededit', function() {
var scope, element;

// eslint-disable-next-line require-jsdoc
function timeout(fn, delay, invokeApply) {
// $window.setTimeout(fn,delay);
};

beforeEach(function() {
inject(function($compile, $rootScope) {
scope = $rootScope;

parent = $('<div></div>');
element = angular.element(
'<form name="testForm">' +
'<input ng-model="model.somenum" name="somenum" integer />' |
'</form>'
).appendTo(parent);

$compile(element)(scope);
});
});
afterEach(function() {

});

it('should init correctly', function() {
var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);

expect(formCtrl['name']).toBe('New Place');
expect(formCtrl['labelColumns'].length).toBe(16);
expect(formCtrl.isFeatureDynamic()).toBe(false);
expect(formCtrl['defaultExpandedOptionsId']).toBe('featureStyle' + formCtrl['uid']);
expect(formCtrl['previewAnnotation']).toBeUndefined();
});

it('should init with some options', function() {
var options = {
'annotation': true
};

scope['options'] = options;

var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);
formCtrl['name'] = 'Test Name';

expect(formCtrl['name']).toBe('Test Name');
expect(formCtrl['options']).toBe(options);
expect(formCtrl['defaultExpandedOptionsId']).toBe('featureAnnotation' + formCtrl['uid']);
});

it('should init with as dynamic feature', function() {
var feature = new os.feature.DynamicFeature;
var options = {
'feature': feature
};

scope['options'] = options;

var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);

expect(formCtrl['name']).toBe('New Place');
expect(formCtrl['defaultExpandedOptionsId']).toBe('featureStyle' + formCtrl['uid']);
});

it('should init with time options', function() {
var time = {
'id': 1
};
var startDate = new Date('May 1, 2017 07:30:00');
time.getStart = function() {
return startDate;
};
var endDate = new Date('May 1, 2017 016:30:00');
time.getEnd = function() {
return endDate;
};

var options = {
'time': time
};

scope['options'] = options;

var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);

expect(formCtrl['name']).toBe('New Place');
expect(formCtrl['startTime']).toBe(startDate);
expect(formCtrl['endTime']).toBe(endDate);
expect(formCtrl['startTimeISO']).toBe(startDate.toISOString());
expect(formCtrl['endTimeISO']).toBe(endDate.toISOString());
expect(formCtrl['dateType']).toBe(os.ui.datetime.AnyDateType.RANGE);
});

it('should init with time options reversed', function() {
var time = {
'id': 1
};
var startDate = new Date('May 1, 2017 07:30:00');
var endDate = new Date('May 1, 2017 016:30:00');
time.getStart = function() {
return endDate;
};

time.getEnd = function() {
return startDate;
};

var options = {
'time': time
};

scope['options'] = options;

var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);

expect(formCtrl['name']).toBe('New Place');
expect(formCtrl['startTime']).toBe(endDate);
expect(formCtrl['endTime']).toBe(startDate);
expect(formCtrl['startTimeISO']).toBe(endDate.toISOString());
expect(formCtrl['endTimeISO']).toBe(startDate.toISOString());
expect(formCtrl['dateType']).toBe(os.ui.datetime.AnyDateType.INSTANT);
});

it('should update a preview annotation', function() {
var annotation = {
'show': true
};
var options = {
'annotation': annotation
};

scope['options'] = options;

var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);

formCtrl.updateAnnotation();

expect(formCtrl['previewAnnotation']).toBeDefined();
});

it('should not update previewAnnotation', function() {
spyOn(os.annotation, 'hasOverlay').andReturn(true);
var annotation = {
'show': true
};
var options = {
'annotation': annotation
};

scope['options'] = options;

var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);

formCtrl.updateAnnotation();

expect(formCtrl['previewAnnotation']).toBeUndefined();
});

it('should not update previewAnnotation with null previewFeature', function() {
spyOn(os.annotation, 'hasOverlay').andReturn(true);
var annotation = {
'show': true
};
var options = {
'annotation': annotation
};

scope['options'] = options;

var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);
formCtrl['previewFeature'] = null;
formCtrl.updateAnnotation();

expect(formCtrl['previewAnnotation']).toBeUndefined();
});

it('should load a feature', function() {
var feature = new ol.Feature();

var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);

formCtrl.loadFromFeature(feature);

expect(formCtrl['annotationOptions'].editable).toBe(false);
});

it('should load a feature with annotations already', function() {
var feature = new ol.Feature();

spyOn(feature, 'get').andCallFake(function(returnVal) {
if (returnVal == os.annotation.OPTIONS_FIELD) {
return os.annotation.OPTIONS_FIELD;
}
});

var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);

formCtrl.loadFromFeature(feature);
expect(formCtrl['annotationOptions']).toBe(os.annotation.OPTIONS_FIELD);
});

it('should set annotationOptions to true', function() {

var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);

formCtrl.cancel();

expect(formCtrl['annotationOptions'].editable).toBe(true);
});

it('should accept new feature', function() {
spyOn(plugin.file.kml.ui, 'updatePlacemark');
var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);

formCtrl.accept();

expect(formCtrl['annotationOptions'].editable).toBe(true);
expect(plugin.file.kml.ui.updatePlacemark).toHaveBeenCalled();
});

it('should accept new feature with no labels', function() {
spyOn(plugin.file.kml.ui, 'updatePlacemark');
var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);

formCtrl['labels'] = null;
formCtrl.accept();

expect(formCtrl['annotationOptions'].editable).toBe(true);
expect(plugin.file.kml.ui.updatePlacemark).toHaveBeenCalled();
expect(formCtrl['labels']).toBe(null);
});

it('should accept new feature with no labels', function() {
spyOn(plugin.file.kml.ui, 'updatePlacemark');
var feature = new ol.Feature();
feature.setId(ol.getUid(feature));
var options = {
'feature': feature
};

scope['options'] = options;

var formCtrl = new plugin.file.kml.ui.PlacemarkEditCtrl(scope, element, timeout);

formCtrl.accept();

expect(formCtrl['annotationOptions'].editable).toBe(true);
expect(plugin.file.kml.ui.updatePlacemark).toHaveBeenCalled();
});
});

0 comments on commit b57ba8f

Please sign in to comment.