aboutsummaryrefslogtreecommitdiffstats
path: root/moon_dashboard/moon/static/moon/js/util.service.spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'moon_dashboard/moon/static/moon/js/util.service.spec.js')
-rwxr-xr-xmoon_dashboard/moon/static/moon/js/util.service.spec.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/moon_dashboard/moon/static/moon/js/util.service.spec.js b/moon_dashboard/moon/static/moon/js/util.service.spec.js
new file mode 100755
index 00000000..d8e3ed31
--- /dev/null
+++ b/moon_dashboard/moon/static/moon/js/util.service.spec.js
@@ -0,0 +1,86 @@
+(function () {
+ 'use strict';
+
+ describe('moon.util.service', function () {
+ var service;
+
+ beforeEach(module('horizon.app.core'));
+ beforeEach(module('horizon.framework'));
+ beforeEach(module('moon'));
+
+ beforeEach(inject(function ($injector) {
+ service = $injector.get('moon.util.service');
+ }));
+
+ it('should push all', function () {
+ var a1 = [0, 1, 2];
+ var a2 = [3, 4];
+ service.pushAll(a1, a2)
+
+ expect(a1.length).toBe(5);
+ expect(a1).toEqual([0, 1, 2, 3, 4]);
+ });
+
+ it('should index of', function () {
+ var a = [{ name: 'n0' }, { name: 'n1' }, { name: 'n2' }];
+ var result = service.indexOf(a, 'name', 'n1');
+
+ expect(result).toBe(1);
+ });
+
+ it('should map to array', function () {
+ var map = { "a": { name: "a" }, "b": { name: "b" } };
+ var result = service.mapToArray(map);
+
+ expect(result.length).toBe(2);
+ });
+
+ it('should map ID to item', function () {
+ var map = { "a": { name: "a" }, "b": { name: "b" } };
+ var array = ["a", "b"];
+ service.mapIdToItem(array, map);
+
+ expect(array.length).toBe(2);
+ expect(array[0].name).toBe("a");
+ expect(array[1].name).toBe("b");
+ });
+
+ it('should map item to ID', function () {
+ var array = [{ id: "a" }, { id: "b" }];
+ service.mapItemToId(array);
+
+ expect(array.length).toBe(2);
+ expect(array[0]).toBe("a");
+ expect(array[1]).toBe("b");
+ });
+
+ it('should add to map', function () {
+ var map = { "a": { name: "a" }, "b": { name: "b" } };
+ var array = [{ id: "c" }];
+ service.addToMap(array, map);
+
+ expect(map.c).toEqual({ id: "c" });
+ });
+
+ it('should update object', function () {
+ var object = { a: 1, b: "test" };
+ var update = { a: 2, c: "test2" };
+ service.updateObject(object, update);
+
+ expect(object.a).toBe(2);
+ expect(object.b).toBe("test");
+ expect(object.c).toBe("test2");
+ });
+
+ it('should clean object', function () {
+ var object = { a: 1, b: "test" };
+ service.cleanObject(object);
+
+ expect(object.a).not.toBeDefined();
+ expect(object.b).not.toBeDefined();
+ expect(object).toEqual({});
+ });
+ });
+
+
+})(); \ No newline at end of file