125 lines
5.2 KiB
JavaScript
125 lines
5.2 KiB
JavaScript
|
|
(function(g,$) {
|
|
|
|
describe("vuHelper tests", function() {
|
|
|
|
beforeEach(function() {
|
|
JKTestUtils.loadFixtures('/base/app/views/clients/_vu_meters.html.erb');
|
|
JKTestUtils.loadFixtures('/base/spec/javascripts/fixtures/vuHelpers.htm');
|
|
});
|
|
|
|
describe("renderVU", function() {
|
|
|
|
describe("with defaults", function() {
|
|
it("should add table.vu-vertical to selector", function() {
|
|
JK.VuHelpers.renderVU('#vu');
|
|
var tableCount = $('#vu table.vu.vertical').length;
|
|
expect(tableCount).toEqual(1);
|
|
var $light = $('#vu .vulight').first();
|
|
var width = $light.attr("width");
|
|
var height = $light.attr("height");
|
|
expect(width).toEqual('3');
|
|
expect(height).toEqual('17');
|
|
});
|
|
});
|
|
|
|
describe("default red/green split", function() {
|
|
it("should split 8 green/4 red with defaults", function() {
|
|
JK.VuHelpers.renderVU('#vu');
|
|
var greenCount = $('#vu td.vulight.vu-green-off').length;
|
|
var vuHTML = $('#vu').html();
|
|
expect(greenCount).toEqual(8);
|
|
var redCount = $('#vu td.vulight.vu-red-off').length;
|
|
expect(redCount).toEqual(4);
|
|
});
|
|
});
|
|
|
|
describe("horizontal type", function() {
|
|
it("should add table.vu-horizontal to selector", function() {
|
|
JK.VuHelpers.renderVU('#vu', {vuType: "horizontal"});
|
|
var tableCount = $('#vu table.vu.horizontal').length;
|
|
expect(tableCount).toEqual(1);
|
|
});
|
|
});
|
|
|
|
|
|
describe("set lightCount to 10", function() {
|
|
it("should render 10 lights", function() {
|
|
JK.VuHelpers.renderVU('#vu', {lightCount:10});
|
|
var rowCount = $('#vu table tr').length;
|
|
expect(rowCount).toEqual(10);
|
|
});
|
|
});
|
|
|
|
describe("set lightCount to 10, horizontal", function() {
|
|
it("should render 10 lights", function() {
|
|
JK.VuHelpers.renderVU('#vu', {lightCount:10, vuType: "horizontal"});
|
|
var rowCount = $('#vu table td').length;
|
|
expect(rowCount).toEqual(10);
|
|
});
|
|
});
|
|
|
|
describe("set lightWidth to 5", function() {
|
|
it("should render 10 lights", function() {
|
|
JK.VuHelpers.renderVU('#vu', {lightCount:10});
|
|
var rowCount = $('#vu table tr').length;
|
|
expect(rowCount).toEqual(10);
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
describe("updateVU", function() {
|
|
describe("horizontal", function() {
|
|
describe("zero value", function() {
|
|
it("should light nothing", function() {
|
|
JK.VuHelpers.renderVU('#vu', {vuType: 'horizontal'});
|
|
JK.VuHelpers.updateVU('#vu', 0.0);
|
|
var $greenLightsOn = $('#vu .vu-green-on');
|
|
var $redLightsOn = $('#vu .vu-red-on');
|
|
expect($greenLightsOn.length).toEqual(0);
|
|
expect($redLightsOn.length).toEqual(0);
|
|
});
|
|
});
|
|
|
|
describe("0.5 value", function() {
|
|
it("should light six green", function() {
|
|
JK.VuHelpers.renderVU('#vu', {vuType: 'horizontal'});
|
|
JK.VuHelpers.updateVU('#vu', 0.5);
|
|
var $greenLightsOn = $('#vu .vu-green-on');
|
|
var $redLightsOn = $('#vu .vu-red-on');
|
|
expect($greenLightsOn.length).toEqual(6);
|
|
expect($redLightsOn.length).toEqual(0);
|
|
});
|
|
});
|
|
|
|
describe("1.0 value", function() {
|
|
it("should light eight green, four red", function() {
|
|
JK.VuHelpers.renderVU('#vu', {vuType:'horizontal'});
|
|
JK.VuHelpers.updateVU('#vu', 1.0);
|
|
var $greenLightsOn = $('#vu .vu-green-on');
|
|
var $redLightsOn = $('#vu .vu-red-on');
|
|
expect($greenLightsOn.length).toEqual(8);
|
|
expect($redLightsOn.length).toEqual(4);
|
|
});
|
|
});
|
|
|
|
describe("0.5 value, 6 lights", function() {
|
|
it("should light three green", function() {
|
|
JK.VuHelpers.renderVU('#vu', {vuType:'horizontal', lightCount: 6});
|
|
JK.VuHelpers.updateVU('#vu', 0.5);
|
|
var $greenLightsOn = $('#vu .vu-green-on');
|
|
var $redLightsOn = $('#vu .vu-red-on');
|
|
expect($greenLightsOn.length).toEqual(3);
|
|
expect($redLightsOn.length).toEqual(0);
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
})(window, jQuery); |