-
- {$ item.title() $}
+
diff --git a/merlin/test/js/filtersSpec.js b/merlin/test/js/filtersSpec.js
index a6ab45f..91102f9 100644
--- a/merlin/test/js/filtersSpec.js
+++ b/merlin/test/js/filtersSpec.js
@@ -159,27 +159,46 @@ describe('merlin filters', function() {
});
it('are given a separate panel for each MutableObject entry', function() {
+ var panels;
topLevelObj.set('key2', {
'id1': {'name': 'String1'},
'id2': {'name': 'String2'}
});
- var panels = extractPanels(topLevelObj);
+ panels = extractPanels(topLevelObj);
+
expect(panels.length).toBe(2);
});
- it('have their title exposed via .title() which mirrors their id', function() {
+ describe('', function() {
var panels;
- topLevelObj.set('key2', {'id1': {'name': 'some name'}});
- panels = extractPanels(topLevelObj);
- expect(panels[0].title()).toBe('id1');
- });
- it('are removable (thus are not permanent)', function() {
- var panels;
- topLevelObj.set('key2', {'id1': {'name': 'String1'}});
- panels = extractPanels(topLevelObj);
+ beforeEach(function() {
+ topLevelObj.set('key2', {'id1': {'name': 'some name'}});
+ panels = extractPanels(topLevelObj);
+ });
+
+ it('have their title exposed via .title() which mirrors their id', function() {
+ expect(panels[0].title()).toBe('id1');
+ });
+
+ it("panel's title() acts also as a setter of the underlying object id", function() {
+ panels[0].title('id2');
+
+ expect(panels[0].title()).toBe('id2');
+ expect(topLevelObj.get('key2').getByID('id2')).toBeDefined();
+ });
+
+ it('are removable (thus are not permanent)', function() {
+ expect(panels[0].removable).toBe(true);
+ });
+
+ it('remove() function actually removes a panel', function() {
+ panels[0].remove();
+ panels = extractPanels(topLevelObj);
+
+ expect(panels.length).toBe(0);
+ });
- expect(panels[0].removable).toBe(true);
});
});
@@ -360,7 +379,7 @@ describe('merlin filters', function() {
immutableObj.set('key2', {'id_1': {key1: 'String_1'}});
panels1 = extractPanels(immutableObj);
- immutableObj.get('key2').remove('id_1');
+ immutableObj.get('key2').removeItem('id_1');
immutableObj.set('key2', {'id_1': {key1: 'String_1'}});
panels2 = extractPanels(immutableObj);
@@ -645,7 +664,7 @@ describe('merlin filters', function() {
rows1 = extractRows(mutableObj),
rows2;
- mutableObj.remove('id1');
+ mutableObj.removeItem('id1');
mutableObj.push('string1', {id: 'id1'});
rows2 = extractRows(mutableObj);
diff --git a/merlin/test/js/modelsSpec.js b/merlin/test/js/modelsSpec.js
new file mode 100644
index 0000000..cd0cbc0
--- /dev/null
+++ b/merlin/test/js/modelsSpec.js
@@ -0,0 +1,144 @@
+
+ /* Copyright (c) 2015 Mirantis, Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may
+ not use this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations
+ under the License.
+*/
+describe('merlin models:', function() {
+ 'use strict';
+
+ var fields;
+
+ beforeEach(function() {
+ module('merlin');
+
+ inject(function($injector) {
+ fields = $injector.get('merlin.field.models');
+ })
+ });
+
+ describe('dictionary field', function() {
+ var dictObj;
+
+ beforeEach(function() {
+ dictObj = fields.dictionary.extend({}, {
+ '?': {
+ '@class': fields.string
+ }
+ }).create({'id1': 'string1', 'id2': 'string2'});
+ });
+
+ function getValueFromCache(id) {
+ var value = undefined;
+ dictObj.getValues().forEach(function(item) {
+ if ( item.getID() === id ) {
+ value = item;
+ }
+ });
+ return value;
+ }
+
+ function getCacheIDs() {
+ return dictObj.getValues().map(function(item) {
+ return item.getID();
+ });
+ }
+
+ describe('getValues() method', function() {
+ it('caching works from the very beginning', function() {
+ expect(getCacheIDs()).toEqual(['id1', 'id2']);
+ });
+
+ it('keyValue() getter/setter can be used from the start', function() {
+ var value = getValueFromCache('id1');
+
+ expect(value.keyValue()).toBe('id1');
+
+ value.keyValue('id3');
+ expect(value.keyValue()).toBe('id3');
+ expect(dictObj.getByID('id3')).toBeDefined();
+ });
+ });
+
+ describe('add() method', function() {
+ it('adds an empty value with given key', function() {
+ dictObj.add('id3');
+
+ expect(dictObj.getByID('id3').get()).toBe('');
+ expect(getCacheIDs()).toEqual(['id1', 'id2', 'id3']);
+ });
+
+ it('keyValue() getter/setter can be used for added values', function() {
+ var value;
+
+ dictObj.add('id3');
+ value = getValueFromCache('id3');
+
+ expect(value.keyValue()).toBe('id3');
+
+ value.keyValue('id4');
+ expect(value.keyValue()).toBe('id4');
+ expect(dictObj.getByID('id4')).toBeDefined();
+ });
+
+ it('updates name automatically if baseName and baseKey are provided', function() {
+ var nestedDictObj = fields.dictionary.extend({}, {
+ '?': {
+ '@class': fields.frozendict.extend({}, {
+ 'name': {
+ '@class': fields.string
+ },
+ '@meta': {
+ 'baseName': 'Action ',
+ 'baseKey': 'action'
+ }
+ })
+ }
+ }).create({'action1': {'name': "Action 1"}});
+
+ nestedDictObj.add('action2');
+
+ expect(nestedDictObj.getByID('action2').get('name').get()).toEqual('Action 2');
+ })
+ });
+
+ describe('empty() method', function() {
+ it('removes all entries in model and in cache', function() {
+ dictObj.empty();
+
+ expect(dictObj.getIDs().length).toBe(0);
+ expect(dictObj.getValues().length).toBe(0);
+ })
+ });
+
+ describe('resetKeys() method', function() {
+ it('re-sets dictionary contents to given keys, cache included', function() {
+ dictObj.resetKeys(['key1', 'key2']);
+
+ expect(dictObj.getIDs()).toEqual(['key1', 'key2']);
+ expect(dictObj.getByID('key1').get()).toBe('');
+ expect(dictObj.getByID('key2').get()).toBe('');
+ expect(getCacheIDs()).toEqual(['key1', 'key2']);
+ })
+ });
+
+ describe('removeItem() method', function() {
+ it('removes dictionary entry by key from model and cache', function() {
+ dictObj.removeItem('id1');
+
+ expect(dictObj.getByID('id1')).toBeUndefined();
+ expect(getCacheIDs()).toEqual(['id2']);
+ })
+ });
+
+ });
+});
\ No newline at end of file