UNPKG

extjs-gpl

Version:

GPL licensed version of Sencha Ext JS

1,206 lines (1,026 loc) 201 kB
describe("Ext.list.Tree", function() { var root, list, store, sampleData; var Model = Ext.define(null, { extend: 'Ext.data.TreeModel', fields: ['customField'] }); function makeList(cfg, noStore) { if (!store && !noStore) { store = new Ext.data.TreeStore({ model: Model, root: { expanded: true, children: sampleData } }); } list = new Ext.list.Tree(Ext.apply({ store: store, animation: false }, cfg)); list.render(Ext.getBody()); if (list.getStore()) { root = list.getStore().getRoot(); } } beforeEach(function() { sampleData = [{ id: 'i1', text: 'Item 1', children: [{ id: 'i11', text: 'Item 1.1', leaf: true }, { id: 'i12', text: 'Item 1.2', leaf: true }] }, { id: 'i2', text: 'Item 2', expandable: false }, { id: 'i3', text: 'Item 3' }, { id: 'i4', text: 'Item 4', expanded: true, children: [{ id: 'i41', text: 'Item 4.1', leaf: true }, { id: 'i42', text: 'Item 4.2' }, { id: 'i43', text: 'Item 4.3', leaf: true }] }]; }); afterEach(function() { root = sampleData = store = list = Ext.destroy(list, store); }); function byId(id) { return store.getNodeById(id); } function getItem(id) { return list.getItem(byId(id)); } describe("store", function() { function getListeners() { var listeners = {}, hasListeners = store.hasListeners, key; for (key in hasListeners) { if (key !== '_decr_' && key !== '_incr_') { listeners[key] = hasListeners[key]; } } return listeners; } describe("configuration", function() { it("should accept a store id", function() { store = new Ext.data.TreeStore({ id: 'storeWithId', model: Model }); makeList({ store: 'storeWithId' }); expect(list.getStore()).toBe(store); }); it("should accept a store config and default the type to Ext.data.TreeStore", function() { makeList({ store: { storeId: 'storeWithId', model: Model } }, true); expect(list.getStore().$className).toBe('Ext.data.TreeStore'); expect(list.getStore().getStoreId()).toBe('storeWithId'); }); it("should accept a store config with a type", function() { Ext.define('spec.CustomTreeStore', { extend: 'Ext.data.TreeStore', alias: 'store.customtree' }); makeList({ store: { type: 'customtree', storeId: 'storeWithId', model: Model } }, true); expect(list.getStore().$className).toBe('spec.CustomTreeStore'); expect(list.getStore().getStoreId()).toBe('storeWithId'); Ext.undefine('spec.CustomTreeStore'); }); it("should accept a store instance", function() { store = new Ext.data.TreeStore({ model: Model }); makeList({ store: store }); expect(list.getStore()).toBe(store); }); }); describe("setting after creation", function() { describe("with no existing store", function() { beforeEach(function() { makeList(null, true); }); it("should accept a store id", function() { store = new Ext.data.TreeStore({ id: 'storeWithId', model: Model }); list.setStore('storeWithId'); expect(list.getStore()).toBe(store); }); it("should accept a store config and default the type to Ext.data.TreeStore", function() { list.setStore({ storeId: 'storeWithId', model: Model }); expect(list.getStore().$className).toBe('Ext.data.TreeStore'); expect(list.getStore().getStoreId()).toBe('storeWithId'); }); it("should accept a store config with a type", function() { Ext.define('spec.CustomTreeStore', { extend: 'Ext.data.TreeStore', alias: 'store.customtree' }); list.setStore({ type: 'customtree', storeId: 'storeWithId', model: Model }); expect(list.getStore().$className).toBe('spec.CustomTreeStore'); expect(list.getStore().getStoreId()).toBe('storeWithId'); Ext.undefine('spec.CustomTreeStore'); }); it("should accept a store instance", function() { store = new Ext.data.TreeStore({ model: Model }); list.setStore(store); expect(list.getStore()).toBe(store); }); }); describe("with an existing store", function() { var listeners; beforeEach(function() { store = new Ext.data.TreeStore({ model: Model }); listeners = getListeners(); makeList(); }); afterEach(function() { listeners = null; }); it("should accept a store id and unbind old store listeners", function() { var newStore = new Ext.data.TreeStore({ id: 'storeWithId', model: Model }); list.setStore('storeWithId'); expect(list.getStore()).toBe(newStore); expect(getListeners()).toEqual(listeners); newStore.destroy(); }); it("should accept a store config and default the type to Ext.data.TreeStore and unbind old store listeners", function() { list.setStore({ storeId: 'storeWithId', model: Model }); expect(list.getStore().$className).toBe('Ext.data.TreeStore'); expect(list.getStore().getStoreId()).toBe('storeWithId'); expect(getListeners()).toEqual(listeners); }); it("should accept a store config with a type and unbind old store listeners", function() { Ext.define('spec.CustomTreeStore', { extend: 'Ext.data.TreeStore', alias: 'store.customtree' }); list.setStore({ type: 'customtree', storeId: 'storeWithId', model: Model }); expect(list.getStore().$className).toBe('spec.CustomTreeStore'); expect(list.getStore().getStoreId()).toBe('storeWithId'); expect(getListeners()).toEqual(listeners); Ext.undefine('spec.CustomTreeStore'); }); it("should accept a store instance and unbind old store listeners", function() { var newStore = new Ext.data.TreeStore({ model: Model }); list.setStore(newStore); expect(list.getStore()).toBe(newStore); expect(getListeners()).toEqual(listeners); newStore.destroy(); }); it("should not destroy the old store with autoDestroy: false", function() { list.setStore(null); expect(store.destroyed).toBe(false); }); it("should destroy the old store with autoDestroy: true", function() { store.setAutoDestroy(true); list.setStore(null); expect(store.destroyed).toBe(true); }); }); }); describe("destruction", function() { beforeEach(function() { store = new Ext.data.TreeStore({ model: Model }); }); it("should set the store to null", function() { makeList(); list.destroy(); expect(list._store).toBeNull(); }); it("should unbind any listeners", function() { var listeners = getListeners(); makeList(); list.destroy(); expect(getListeners()).toEqual(listeners); }); it("should not destroy the store if autoDestroy: false", function() { makeList(); list.destroy(); expect(store.destroyed).toBe(false); }); it("should destroy the store if autoDestroy: true", function() { store.setAutoDestroy(true); makeList(); list.destroy(); expect(store.destroyed).toBe(true); }); }); }); // The purpose for these tests is to test the API between the list and the item. // Because the item class is expected to be subclassed, there's not much point testing // the UI portion default class here. This is why these tests seem a little abstract. describe("items", function() { var insertSpy, removeSpy, expandSpy, collapseSpy, hasFirst; function makeCustomList(cfg, noStore) { makeList(Ext.merge({ defaults: { xtype: 'spec_treelist_customitem' } }, cfg), noStore); list.on({ iteminsert: insertSpy, itemremove: removeSpy, itemexpand: expandSpy, itemcollapse: collapseSpy }); } beforeEach(function() { insertSpy = jasmine.createSpy(); removeSpy = jasmine.createSpy(); expandSpy = jasmine.createSpy(); collapseSpy = jasmine.createSpy(); // We create this first to prevent the inconsistency with the way configs behave // when using cached: true. After the first instance, the behaviour will remain the same if (!hasFirst) { Ext.define('spec.treelist.CustomItem', { extend: 'Ext.list.AbstractTreeItem', xtype: 'spec_treelist_customitem', config: { testConfig: null, floated: false }, constructor: function(config) { this.$noClearOnDestroy = (this.$noClearOnDestroy || {}); this.$noClearOnDestroy.logs = true; this.logs = { expandable: [], expanded: [], iconCls: [], leaf: [], loading: [], text: [], onNodeCollapse: [], onNodeExpand: [], onNodeInsert: [], onNodeRemove: [], onNodeUpdate: [], insertItem: [], removeItem: [] }; this.callParent([config]); }, getToolElement: function() { if (!this.toolElement) { this.toolElement = this.element.createChild(); } return this.toolElement; }, insertItem: function(item, refItem) { this.logs.insertItem.push([item, refItem]); }, removeItem: function(item) { this.logs.removeItem.push(item); }, nodeCollapse: function(node) { this.logs.onNodeCollapse.push(node); this.callParent(arguments); }, nodeExpand: function(node) { this.logs.onNodeExpand.push(node); this.callParent(arguments); }, nodeInsert: function(node, refNode) { this.logs.onNodeInsert.push([node, refNode]); this.callParent(arguments); }, nodeRemove: function(node) { this.logs.onNodeRemove.push(node); this.callParent(arguments); }, nodeUpdate: function(node, modifiedFieldNames) { this.logs.onNodeUpdate.push([node, modifiedFieldNames]); this.callParent(arguments); }, updateExpandable: function(expandable) { this.logs.expandable.push(expandable); }, updateExpanded: function(expanded) { this.logs.expanded.push(expanded); }, updateIconCls: function(iconCls) { this.logs.iconCls.push(iconCls); }, updateLeaf: function(leaf) { this.logs.leaf.push(leaf); }, updateLoading: function(loading) { this.logs.loading.push(loading); }, updateText: function(text) { this.logs.text.push(text); } }); var temp = new spec.treelist.CustomItem(); hasFirst = true; temp.destroy(); } }); afterEach(function() { insertSpy = removeSpy = expandSpy = collapseSpy = null; }); describe("configuration of items", function() { it("should use the default item type", function() { makeList(); list.getStore().each(function(node) { expect(list.getItem(node).xtype).toBe(list.getDefaults().xtype); }); }); it("should use a specified type", function() { makeList({ defaults: { xtype: 'spec_treelist_customitem' } }); list.getStore().each(function(node) { expect(list.getItem(node).xtype).toBe('spec_treelist_customitem'); }); }); }); describe("at creation", function() { describe("top level nodes", function() { describe("expanded: false, with children", function() { it("should set expanded", function() { makeCustomList(); var item = getItem('i1'); expect(item.logs.expanded).toEqual([]); expect(item.getExpanded()).toBe(false); }); it("should set expandable", function() { makeCustomList(); var item = getItem('i1'); expect(item.logs.expandable).toEqual([true]); expect(item.getExpandable()).toBe(true); }); it("should set leaf", function() { makeCustomList(); var item = getItem('i1'); expect(item.logs.leaf).toEqual([false]); expect(item.getLeaf()).toBe(false); }); it("should set the icon if iconClsProperty is specified", function() { sampleData[0].iconCls = 'iconA'; makeCustomList(); var item = getItem('i1'); expect(item.logs.iconCls).toEqual(['iconA']); expect(item.getIconCls()).toBe('iconA'); }); it("should not set the icon if an iconClsProperty is not specified", function() { sampleData[0].iconCls = 'iconA'; makeCustomList({ defaults: { iconClsProperty: '' } }); var item = getItem('i1'); expect(item.logs.iconCls).toEqual([]); expect(item.getIconCls()).toBe(''); }); it("should set the text if a textProperty is specified", function() { makeCustomList(); var item = getItem('i1'); expect(item.logs.text).toEqual(['Item 1']); expect(item.getText()).toBe('Item 1'); }); it("should not set the text if an textProperty is not specified", function() { makeCustomList({ defaults: { textProperty: '' } }); var item = getItem('i1'); expect(item.logs.text).toEqual([]); expect(item.getText()).toBe(''); }); it("should insert the child nodes", function() { makeCustomList(); var item = getItem('i1'); expect(item.logs.insertItem).toEqual([ [getItem('i11'), null], [getItem('i12'), null] ]); }); it("should not call any template methods", function() { makeCustomList(); var item = getItem('i1'); expect(item.logs.onNodeCollapse).toEqual([]); expect(item.logs.onNodeExpand).toEqual([]); expect(item.logs.onNodeInsert).toEqual([]); expect(item.logs.onNodeRemove).toEqual([]); expect(item.logs.onNodeUpdate).toEqual([]); }); it("should not fire events", function() { expect(insertSpy).not.toHaveBeenCalled(); expect(removeSpy).not.toHaveBeenCalled(); expect(expandSpy).not.toHaveBeenCalled(); expect(collapseSpy).not.toHaveBeenCalled(); }); it("should have the node, list and parent set", function() { makeCustomList(); var item = getItem('i1'); expect(item.getNode()).toBe(byId('i1')); expect(item.getParentItem()).toBeNull(); expect(item.getOwner()).toBe(list); }); it("should have the itemConfig set", function() { makeCustomList({ defaults: { testConfig: 12 } }); var item = getItem('i1'); expect(item.getTestConfig()).toBe(12); }); }); describe("expandable: false, no children", function() { it("should set expanded", function() { makeCustomList(); var item = getItem('i2'); expect(item.logs.expanded).toEqual([]); expect(item.getExpanded()).toBe(false); }); it("should set expandable", function() { makeCustomList(); var item = getItem('i2'); expect(item.logs.expandable).toEqual([]); expect(item.getExpandable()).toBe(false); }); it("should set leaf", function() { makeCustomList(); var item = getItem('i2'); expect(item.logs.leaf).toEqual([false]); expect(item.getLeaf()).toBe(false); }); it("should set the icon if iconClsProperty is specified", function() { sampleData[1].iconCls = 'iconA'; makeCustomList(); var item = getItem('i2'); expect(item.logs.iconCls).toEqual(['iconA']); expect(item.getIconCls()).toBe('iconA'); }); it("should not set the icon if an iconClsProperty is not specified", function() { sampleData[1].iconCls = 'iconA'; makeCustomList({ defaults: { iconClsProperty: '' } }); var item = getItem('i2'); expect(item.logs.iconCls).toEqual([]); expect(item.getIconCls()).toBe(''); }); it("should set the text if a textProperty is specified", function() { makeCustomList(); var item = getItem('i2'); expect(item.logs.text).toEqual(['Item 2']); expect(item.getText()).toBe('Item 2'); }); it("should not set the text if an textProperty is not specified", function() { makeCustomList({ defaults: { textProperty: '' } }); var item = getItem('i2'); expect(item.logs.text).toEqual([]); expect(item.getText()).toBe(''); }); it("should not insert child nodes", function() { makeCustomList(); var item = getItem('i2'); expect(item.logs.insertItem).toEqual([]); }); it("should not call any template methods", function() { makeCustomList(); var item = getItem('i2'); expect(item.logs.onNodeCollapse).toEqual([]); expect(item.logs.onNodeExpand).toEqual([]); expect(item.logs.onNodeInsert).toEqual([]); expect(item.logs.onNodeRemove).toEqual([]); expect(item.logs.onNodeUpdate).toEqual([]); }); it("should not fire events", function() { expect(insertSpy).not.toHaveBeenCalled(); expect(removeSpy).not.toHaveBeenCalled(); expect(expandSpy).not.toHaveBeenCalled(); expect(collapseSpy).not.toHaveBeenCalled(); }); it("should have the node, list and parent set", function() { makeCustomList(); var item = getItem('i2'); expect(item.getNode()).toBe(byId('i2')); expect(item.getParentItem()).toBeNull(); expect(item.getOwner()).toBe(list); }); it("should have the itemConfig set", function() { makeCustomList({ defaults: { testConfig: 12 } }); var item = getItem('i2'); expect(item.getTestConfig()).toBe(12); }); }); describe("leaf: true", function() { beforeEach(function() { sampleData[2].leaf = true; }); it("should set expanded", function() { makeCustomList(); var item = getItem('i3'); expect(item.logs.expanded).toEqual([]); expect(item.getExpanded()).toBe(false); }); it("should set expandable", function() { makeCustomList(); var item = getItem('i3'); expect(item.logs.expandable).toEqual([]); expect(item.getExpandable()).toBe(false); }); it("should set leaf", function() { makeCustomList(); var item = getItem('i3'); expect(item.logs.leaf).toEqual([]); expect(item.getLeaf()).toBe(true); }); it("should set the icon if iconClsProperty is specified", function() { sampleData[2].iconCls = 'iconA'; makeCustomList(); var item = getItem('i3'); expect(item.logs.iconCls).toEqual(['iconA']); expect(item.getIconCls()).toBe('iconA'); }); it("should not set the icon if an iconClsProperty is not specified", function() { sampleData[2].iconCls = 'iconA'; makeCustomList({ defaults: { iconClsProperty: '' } }); var item = getItem('i3'); expect(item.logs.iconCls).toEqual([]); expect(item.getIconCls()).toBe(''); }); it("should set the text if a textProperty is specified", function() { makeCustomList(); var item = getItem('i3'); expect(item.logs.text).toEqual(['Item 3']); expect(item.getText()).toBe('Item 3'); }); it("should not set the text if an textProperty is not specified", function() { makeCustomList({ defaults: { textProperty: '' } }); var item = getItem('i3'); expect(item.logs.text).toEqual([]); expect(item.getText()).toBe(''); }); it("should not insert child nodes", function() { makeCustomList(); var item = getItem('i3'); expect(item.logs.insertItem).toEqual([]); }); it("should not call any template methods", function() { makeCustomList(); var item = getItem('i3'); expect(item.logs.onNodeCollapse).toEqual([]); expect(item.logs.onNodeExpand).toEqual([]); expect(item.logs.onNodeInsert).toEqual([]); expect(item.logs.onNodeRemove).toEqual([]); expect(item.logs.onNodeUpdate).toEqual([]); }); it("should not fire events", function() { expect(insertSpy).not.toHaveBeenCalled(); expect(removeSpy).not.toHaveBeenCalled(); expect(expandSpy).not.toHaveBeenCalled(); expect(collapseSpy).not.toHaveBeenCalled(); }); it("should have the node, list and parent set", function() { makeCustomList(); var item = getItem('i3'); expect(item.getNode()).toBe(byId('i3')); expect(item.getParentItem()).toBeNull(); expect(item.getOwner()).toBe(list); }); it("should have the itemConfig set", function() { makeCustomList({ defaults: { testConfig: 12 } }); var item = getItem('i3'); expect(item.getTestConfig()).toBe(12); }); }); describe("expanded: true, with children", function() { it("should set expanded", function() { makeCustomList(); var item = getItem('i4'); expect(item.logs.expanded).toEqual([true]); expect(item.getExpanded()).toBe(true); }); it("should set expandable", function() { makeCustomList(); var item = getItem('i4'); expect(item.logs.expandable).toEqual([true]); expect(item.getExpandable()).toBe(true); }); it("should set leaf", function() { makeCustomList(); var item = getItem('i4'); expect(item.logs.leaf).toEqual([false]); expect(item.getLeaf()).toBe(false); }); it("should set the icon if iconClsProperty is specified", function() { sampleData[3].iconCls = 'iconA'; makeCustomList(); var item = getItem('i4'); expect(item.logs.iconCls).toEqual(['iconA']); expect(item.getIconCls()).toBe('iconA'); }); it("should not set the icon if an iconClsProperty is not specified", function() { sampleData[3].iconCls = 'iconA'; makeCustomList({ defaults: { iconClsProperty: '' } }); var item = getItem('i4'); expect(item.logs.iconCls).toEqual([]); expect(item.getIconCls()).toBe(''); }); it("should set the text if a textProperty is specified", function() { makeCustomList(); var item = getItem('i4'); expect(item.logs.text).toEqual(['Item 4']); expect(item.getText()).toBe('Item 4'); }); it("should not set the text if an textProperty is not specified", function() { makeCustomList({ defaults: { textProperty: '' } }); var item = getItem('i4'); expect(item.logs.text).toEqual([]); expect(item.getText()).toBe(''); }); it("should insert the child nodes", function() { makeCustomList(); var item = getItem('i4'); expect(item.logs.insertItem).toEqual([ [getItem('i41'), null], [getItem('i42'), null], [getItem('i43'), null] ]); }); it("should not call any template methods", function() { makeCustomList(); var item = getItem('i4'); expect(item.logs.onNodeCollapse).toEqual([]); expect(item.logs.onNodeExpand).toEqual([]); expect(item.logs.onNodeInsert).toEqual([]); expect(item.logs.onNodeRemove).toEqual([]); expect(item.logs.onNodeUpdate).toEqual([]); }); it("should not fire events", function() { expect(insertSpy).not.toHaveBeenCalled(); expect(removeSpy).not.toHaveBeenCalled(); expect(expandSpy).not.toHaveBeenCalled(); expect(collapseSpy).not.toHaveBeenCalled(); }); it("should have the node, list and parent set", function() { makeCustomList(); var item = getItem('i4'); expect(item.getNode()).toBe(byId('i4')); expect(item.getParentItem()).toBeNull(); expect(item.getOwner()).toBe(list); }); it("should have the itemConfig set", function() { makeCustomList({ defaults: { testConfig: 12 } }); var item = getItem('i4'); expect(item.getTestConfig()).toBe(12); }); }); }); describe("child level nodes", function() { describe("parent expanded: false", function() { it("should set expanded", function() { makeCustomList(); var item1 = getItem('i11'), item2 = getItem('i12'); expect(item1.logs.expanded).toEqual([]); expect(item2.logs.expanded).toEqual([]); expect(item1.getExpanded()).toBe(false); expect(item2.getExpanded()).toBe(false); }); it("should set expandable", function() { makeCustomList(); var item1 = getItem('i11'), item2 = getItem('i12'); expect(item1.logs.expandable).toEqual([]); expect(item2.logs.expandable).toEqual([]); expect(item1.getExpandable()).toBe(false); expect(item2.getExpanded()).toBe(false); }); it("should set leaf", function() { makeCustomList(); var item1 = getItem('i11'), item2 = getItem('i12'); expect(item1.logs.leaf).toEqual([]); expect(item2.logs.leaf).toEqual([]); expect(item1.getLeaf()).toBe(true); expect(item2.getLeaf()).toBe(true); }); it("should set the icon if iconClsProperty is specified", function() { sampleData[0].children[0].iconCls = 'iconA'; sampleData[0].children[1].iconCls = 'iconB'; makeCustomList(); var item1 = getItem('i11'), item2 = getItem('i12'); expect(item1.logs.iconCls).toEqual(['iconA']); expect(item2.logs.iconCls).toEqual(['iconB']); expect(item1.getIconCls()).toBe('iconA'); expect(item2.getIconCls()).toBe('iconB'); }); it("should not set the icon if an iconClsProperty is not specified", function() { sampleData[0].children[0].iconCls = 'iconA'; sampleData[0].children[1].iconCls = 'iconB'; makeCustomList({ defaults: { iconClsProperty: '' } }); var item1 = getItem('i11'), item2 = getItem('i12'); expect(item1.logs.iconCls).toEqual([]); expect(item2.logs.iconCls).toEqual([]); expect(item1.getIconCls()).toBe(''); expect(item2.getIconCls()).toBe(''); }); it("should set the text if a textProperty is specified", function() { makeCustomList(); var item1 = getItem('i11'), item2 = getItem('i12'); expect(item1.logs.text).toEqual(['Item 1.1']); expect(item2.logs.text).toEqual(['Item 1.2']); expect(item1.getText()).toBe('Item 1.1'); expect(item2.getText()).toBe('Item 1.2'); }); it("should not set the text if an textProperty is not specified", function() { makeCustomList({ defaults: { textProperty: '' } }); var item1 = getItem('i11'), item2 = getItem('i12'); expect(item1.logs.text).toEqual([]); expect(item2.logs.text).toEqual([]); expect(item1.getText()).toBe(''); expect(item2.getText()).toBe(''); }); it("should not call any template methods", function() { makeCustomList(); var item1 = getItem('i11'), item2 = getItem('i12'); expect(item1.logs.onNodeCollapse).toEqual([]); expect(item1.logs.onNodeExpand).toEqual([]); expect(item1.logs.onNodeInsert).toEqual([]); expect(item1.logs.onNodeRemove).toEqual([]); expect(item1.logs.onNodeUpdate).toEqual([]); expect(item2.logs.onNodeCollapse).toEqual([]); expect(item2.logs.onNodeExpand).toEqual([]); expect(item2.logs.onNodeInsert).toEqual([]); expect(item2.logs.onNodeRemove).toEqual([]); expect(item2.logs.onNodeUpdate).toEqual([]); }); it("should not fire events", function() { expect(insertSpy).not.toHaveBeenCalled(); expect(removeSpy).not.toHaveBeenCalled(); expect(expandSpy).not.toHaveBeenCalled(); expect(collapseSpy).not.toHaveBeenCalled(); }); it("should have the node, list and parent set", function() { makeCustomList(); var item1 = getItem('i11'), item2 = getItem('i12'); expect(item1.getNode()).toBe(byId('i11')); expect(item1.getParentItem()).toBe(getItem('i1')); expect(item1.getOwner()).toBe(list); expect(item2.getNode()).toBe(byId('i12')); expect(item2.getParentItem()).toBe(getItem('i1')); expect(item2.getOwner()).toBe(list); }); it("should have the itemConfig set", function() { makeCustomList({ defaults: { testConfig: 12 } }); var item1 = getItem('i11'), item2 = getItem('i12'); expect(item1.getTestConfig()).toBe(12); expect(item2.getTestConfig()).toBe(12); }); }); describe("parent expanded: true", function() { it("should set expanded", function() { makeCustomList(); var item1 = getItem('i41'), item2 = getItem('i42'), item3 = getItem('i43'); expect(item1.logs.expanded).toEqual([]); expect(item2.logs.expanded).toEqual([]); expect(item3.logs.expanded).toEqual([]); expect(item1.getExpanded()).toBe(false); expect(item2.getExpanded()).toBe(false); expect(item3.getExpanded()).toBe(false); }); it("should set expandable", function() { makeCustomList(); var item1 = getItem('i41'), item2 = getItem('i42'), item3 = getItem('i43'); expect(item1.logs.expandable).toEqual([]); expect(item2.logs.expandable).toEqual([true]); expect(item3.logs.expandable).toEqual([]); expect(item1.getExpandable()).toBe(false); expect(item2.getExpandable()).toBe(true); expect(item3.getExpandable()).toBe(false); }); it("should set leaf", function() { makeCustomList(); var item1 = getItem('i41'), item2 = getItem('i42'), item3 = getItem('i43'); expect(item1.logs.leaf).toEqual([]); expect(item2.logs.leaf).toEqual([false]); expect(item3.logs.leaf).toEqual([]); expect(item1.getLeaf()).toBe(true); expect(item2.getLeaf()).toBe(false); expect(item3.getLeaf()).toBe(true); }); it("should set the icon if iconClsProperty is specified", function() { sampleData[3].children[0].iconCls = 'iconA'; sampleData[3].children[1].iconCls = 'iconB'; sampleData[3].children[2].iconCls = 'iconC'; makeCustomList(); var item1 = getItem('i41'), item2 = getItem('i42'), item3 = getItem('i43'); expect(item1.logs.iconCls).toEqual(['iconA']); expect(item2.logs.iconCls).toEqual(['iconB']); expect(item3.logs.iconCls).toEqual(['iconC']); expect(item1.getIconCls()).toBe('iconA'); expect(item2.getIconCls()).toBe('iconB'); expect(item3.getIconCls()).toBe('iconC'); }); it("should not set the icon if an iconClsProperty is not specified", function() { sampleData[3].children[0].iconCls = 'iconA'; sampleData[3].children[1].iconCls = 'iconB'; sampleData[3].children[2].iconCls = 'iconC'; makeCustomList({ defaults: { iconClsProperty: '' } }); var item1 = getItem('i41'), item2 = getItem('i42'), item3 = getItem('i43'); expect(item1.logs.iconCls).toEqual([]); expect(item2.logs.iconCls).toEqual([]); expect(item3.logs.iconCls).toEqual([]); expect(item1.getIconCls()).toBe(''); expect(item2.getIconCls()).toBe(''); expect(item3.getIconCls()).toBe(''); }); it("should set the text if a textProperty is specified", function() { makeCustomList(); var item1 = getItem('i41'), item2 = getItem('i42'), item3 = getItem('i43'); expect(item1.logs.text).toEqual(['Item 4.1']); expect(item2.logs.text).toEqual(['Item 4.2']); expect(item3.logs.text).toEqual(['Item 4.3']); expect(item1.getText()).toBe('Item 4.1'); expect(item2.getText()).toBe('Item 4.2'); expect(item3.getText()).toBe('Item 4.3'); }); it("should not set the text if an textProperty is not specified", function() { makeCustomList({ defaults: { textProperty: '' } }); var item1 = getItem('i41'), item2 = getItem('i42'), item3 = getItem('i43'); expect(item1.logs.text).toEqual([]); expect(item2.logs.text).toEqual([]); expect(item3.logs.text).toEqual([]); expect(item1.getText()).toBe(''); expect(item2.getText()).toBe(''); expect(item3.getText()).toBe(''); }); it("should not call any template methods", function() { makeCustomList(); var item1 = getItem('i41'), item2 = getItem('i42'), item3 = getItem('i43'); expect(item1.logs.onNodeCollapse).toEqual([]); expect(item1.logs.onNodeExpand).toEqual([]); expect(item1.logs.onNodeInsert).toEqual([]); expect(item1.logs.onNodeRemove).toEqual([]); expect(item1.logs.onNodeUpdate).toEqual([]); expect(item2.logs.onNodeCollapse).toEqual([]); expect(item2.logs.onNodeExpand).toEqual([]); expect(item2.logs.onNodeInsert).toEqual([]); expect(item2.logs.onNodeRemove).toEqual([]); expect(item2.logs.onNodeUpdate).toEqual([]); expect(item3.logs.onNodeCollapse).toEqual([]); expect(item3.logs.onNodeExpand).toEqual([]); expect(item3.logs.onNodeInsert).toEqual([]); expect(item3.logs.onNodeRemove).toEqual([]); expect(item3.logs.onNodeUpdate).toEqual([]); }); it("should not fire events", function() { expect(insertSpy).not.toHaveBeenCalled(); expect(removeSpy).not.toHaveBeenCalled(); expect(expandSpy).not.toHaveBeenCalled(); expect(collapseSpy).not.toHaveBeenCalled(); }); it("should have the node, list and parent set", function() { makeCustomList(); var item1 = getItem('i41'), item2 = getItem('i42'), item3 = getItem('i43'); ex