UNPKG

@fusioncharts/core

Version:

JavaScript Data Visualisation Library

1 lines 7.79 kB
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _smartRenderer=_interopRequireDefault(require("./smart-renderer"));var _fusionEventWrapper=_interopRequireDefault(require("../fusion-events-wrapper/fusion-event-wrapper"));var _testableSmartrendererComponent=_interopRequireDefault(require("./testable-smartrenderer-component"));var component,setup=function setup(){component=new _smartRenderer.default};describe("testing getName function",(function(){it("name to be generic",(function(){setup();expect(component.getName()).toBe("generic")}))}));describe("testing getType function",(function(){it("type should be generic",(function(){setup();expect(component.getType()).toBe("generic")}))}));describe("testing getId function",(function(){it("setId function should be called",(function(){var spy=component;setup();component._id=0;spyOn(spy,"setId");spy.getId();expect(spy.setId).toHaveBeenCalled()}));it("id value should be 1",(function(){setup();component._id=1;expect(component.getId()).toBe(1)}))}));describe("testing setId function",(function(){it("id value undefined should be set to generic_generic_1 when called for the first time",(function(){setup();component.setId(undefined);expect(component._id).toBe("generic_generic_1")}));it("id value undefined should be set to generic_generic_2 when called for the second time",(function(){setup();component.setId(undefined);expect(component._id).toBe("generic_generic_2")}))}));describe("testing iteratecomponents function",(function(){it("mapchild function should be called",(function(){var spy=component;setup();spyOn(spy,"_mapChildren");spy.iterateComponents();expect(spy._mapChildren).toHaveBeenCalled()}))}));describe("testing getFromEnv function",(function(){it("env should return an empty object when called first time",(function(){setup();component.getFromEnv("");expect(component._env).toEqual({})}))}));describe("testing addToEnv function",(function(){setup();it("added env row value with 2",(function(){component.addToEnv("row",2);expect(component._env.row).toBe(2)}));it("env should return 2 after calling addToEnv function",(function(){component.getFromEnv("row");expect(component._env.row).toBe(2)}))}));describe("testing deleteFromEnv function",(function(){it("env is now undefined after deleting row env by calling deleteFromEnv",(function(){component.deleteFromEnv("row");expect(component._env.row).toBe(undefined)}))}));describe("testing removeAllJobs function",(function(){it("jobList should return undefined after removing all the jobs present in the list",(function(){setup();component.removeAllJobs();expect(component._jobList).toEqual({})}))}));describe("testing asyncDraw function",(function(){it("addJob function is called",(function(){var spy=component;setup();spyOn(spy,"addJob");spy.asyncDraw();expect(spy.addJob).toHaveBeenCalled()}))}));describe("testing syncDraw function",(function(){it("fireEvent function is called",(function(){var spy=component;setup();spyOn(spy,"fireEvent");spy.syncDraw();expect(spy.fireEvent).toHaveBeenCalled()}));it("removeJob function is called",(function(){var spy=component;setup();spyOn(spy,"removeJob");spy.syncDraw();expect(spy.removeJob).toHaveBeenCalled()}));it("jobList should be empty after deletion of Job",(function(){setup();component.syncDraw();expect(component._jobList.draw).toEqual(undefined)}))}));describe("testing childrenSyncDraw function",(function(){it("mapChildren function to be called",(function(){var spy=component;setup();spyOn(spy,"_mapChildren");spyOn(spy,"_removeUnusedChildren");spy.childrenSyncDraw();expect(spy._mapChildren).toHaveBeenCalled();expect(spy._removeUnusedChildren).toHaveBeenCalled()}))}));describe("testing setData function",(function(){it("asynDraw function to be called",(function(){var spy=component;setup();spyOn(spy,"asyncDraw");spy.setData();expect(spy.asyncDraw).toHaveBeenCalled()}))}));describe("Type checking",(function(){it("should return type of component",(function(){setup();expect(component.getType()).toBe("generic")}))}));describe("state checking",(function(){it("should return state of component",(function(){setup();component.setState("id",1);expect(component.getState("id")).toBe(1)}))}));describe("getLinkedItem function testing",(function(){it("should return linked items of component",(function(){var obj2=new _smartRenderer.default;setup();component.setLinkedItem("linkedElement1",obj2);expect(component.getLinkedItem("linkedElement1")).toEqual(obj2)}));it("should return linked items of component",(function(){var obj2=new _smartRenderer.default;setup();obj2.setLinkedItem("linkedElement2",component);expect(obj2.getLinkedItem("linkedElement2")).toEqual(component)}))}));describe("getLinkedParent function testing",(function(){it("should return linked parent of component obj2",(function(){var obj2=new _smartRenderer.default;setup();obj2._setLinkedParent(component);expect(obj2.getLinkedParent()).toEqual(component)}));it("should return linked parent of component obj3",(function(){var obj3,obj2=new _smartRenderer.default;setup();obj3=new _smartRenderer.default;obj2._setLinkedParent(component);obj3._setLinkedParent(obj2);expect(obj3.getLinkedParent().getLinkedParent()).toEqual(component)}))}));describe("attachChild testing",(function(){it("should return attched child of a component",(function(){var ret;setup();ret=component.attachChild(_smartRenderer.default,"random");expect(ret instanceof _smartRenderer.default).toBe(true)}))}));describe("getChild function test",(function(){it("should return child of a component obj",(function(){setup();component.attachChild(_smartRenderer.default,"random","test-id");expect(component.getChild("test-id").getId()).toBe("test-id")}))}));describe("getLinkedParent testing",(function(){it("should return parent of components",(function(){var obj1=new _smartRenderer.default,obj2=new _smartRenderer.default,obj3=new _smartRenderer.default;obj2._setLinkedParent(obj1);obj3._setLinkedParent(obj1);expect(obj3.getLinkedParent()).toBe(obj1)}))}));describe("Child configure and remove test",(function(){setup();it("componentStore test",(function(){var child=component.attachChild(_smartRenderer.default,"child","child");expect(component._componentStore.child).toBeDefined();component.configure();child.remove();child.syncDraw();child.addEventListener("visualupdated",(function(done){expect(child.getId()).toBeUndefined();expect(component._componentStore.child).toBeUndefined();done()}))}))}));describe("Child count on setData test",(function(){it("Set data calls configure and syncDraw",(function(done){var parent=new _testableSmartrendererComponent.default,spy=parent;spyOn(spy,"configure");spyOn(spy,"syncDraw");spy.setData({childCount:0},true);spy.addEventListener("visualupdated",(function(){expect(spy.configure).toHaveBeenCalled();expect(spy.syncDraw).toHaveBeenCalled();done()}))}));it("No children test",(function(done){var parent=new _testableSmartrendererComponent.default;parent.setData({childCount:0},true);parent.addEventListener("visualupdated",(function(){setup();expect(parent.getChildren().childcomponent).toBeUndefined();done()}))}));it("Has children test",(function(done){var parent=new _testableSmartrendererComponent.default;parent.setData({childCount:2},true);parent.addEventListener("visualupdated",(function(){expect(parent.getChildren().childcomponent).toBeDefined();done()}))}))}));describe("Fusion event wrapper test",(function(){var testableComponent=new _testableSmartrendererComponent.default,eventWrapper=new _fusionEventWrapper.default,testHandler=function testHandler(){return false};it("Event added to component throught fusion-event-wraper",(function(done){eventWrapper.on(testableComponent,"testevent",testHandler);expect(testableComponent._evtListeners.testevent).toBeDefined();done()}))}));