"use strict"; var expect = require("chai").expect; var Layer = require("../../src/layer/Layer"); module.exports = function() { describe("DojiChart.core.Layer", function() { const CLASS_NAME = "component"; const COMP_WIDTH = 50; const COMP_HEIGHT = 50; //var HTMLElement_class = (window.document.createElement("div")).constructor; // a workaround to avoid jshint HTMLElement is undefined var test_area, canvas, dummy_comp; before(function() { test_area = window.document.getElementById("test-area"); test_area.innerHTML = ""; canvas = window.document.createElement("canvas"); canvas.className = CLASS_NAME; canvas.setAttribute("width", COMP_WIDTH); canvas.setAttribute("height", COMP_HEIGHT); test_area.appendChild(canvas); dummy_comp = { getEl: function() { return canvas; }, getWidth: function() { return COMP_WIDTH; }, getDrawingWidth: function() { return COMP_WIDTH; }, getHeight: function() { return COMP_HEIGHT; } }; }); describe("canvas (fixture)", function() { it("exist", function() { expect(canvas).to.exist; }); it("has correct width", function() { expect(canvas.width).to.equal(COMP_WIDTH); }); it("has correct height", function() { expect(canvas.height).to.equal(COMP_HEIGHT); }); }); // end of fixtures describe("properties", function() { var layer; beforeEach(function() { layer = new Layer(); layer.setParentComponent(dummy_comp); }); afterEach(function() { layer = undefined; }); describe(".elements property", function() { it("should be empty array", function() { expect(layer.elements).to.be.an("array"); expect(layer.elements).to.have.lengthOf(0); }); }); describe("._parent_component property", function() { it("should equal parent component instance", function() { expect(layer._parent_component).to.equal(dummy_comp); }); }); }); // end of properties describe("methods", function() { var layer; beforeEach(function() { layer = new Layer(); layer.setParentComponent(dummy_comp); }); afterEach(function() { layer = undefined; }); describe("getParentComponent()", function() { it("should exist", function() { expect(layer.getParentComponent).to.exist; }); it("should return correct value", function() { expect(layer.getParentComponent()).to.equal(dummy_comp); }); }); describe("setParentComponent()", function() { it("should exist", function() { expect(layer.setParentComponent).to.exist; }); it("should set parent component property", function() { layer.setParentComponent(dummy_comp); expect(layer._parent_component).to.equal(dummy_comp); }); }); describe("getWidth()", function() { it("should exist", function() { expect(layer.getWidth).to.exist; }); it("should return correct value (" + COMP_WIDTH + ")", function() { expect(layer.getWidth()).to.equal(COMP_WIDTH); }); }); describe("getDrawingWidth()", function() { it("should exist", function() { expect(layer.getDrawingWidth).to.exist; }); it("should return correct value (" + COMP_WIDTH + ")", function() { expect(layer.getDrawingWidth()).to.equal(COMP_WIDTH); }); }); describe("getHeight()", function() { it("should exist", function() { expect(layer.getHeight).to.exist; }); it("should return correct value (" + COMP_HEIGHT + ")", function() { expect(layer.getHeight()).to.equal(COMP_HEIGHT); }); }); }); // end of methods }); };