Skip to content

Commit

Permalink
Add tests to cover modifications to $.getCssMatrix()
Browse files Browse the repository at this point in the history
  • Loading branch information
townxelliot committed Aug 27, 2013
1 parent 197def2 commit afe48d6
Showing 1 changed file with 70 additions and 12 deletions.
82 changes: 70 additions & 12 deletions test/getCssMatrix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,91 @@ var domHelper = require("./dom.helper");
describe("getCssMatrix", function () {
var stubMatrix = { a: 1, b: 1, c: 1, d: 1, e: 1, f: 1 };

// matrix for 90deg rotate
var stubWebkitCssMatrix = "matrix(0, 1, -1, 0, 0, 0)";

// matrix for 180deg rotate
var stubMsCssMatrix = "matrix(-1, 0, 0, -1, 0, 0)";

// matrix for 270deg rotate
var stubFooCssMatrix = "matrix(0, -1, 1, 0, 0, 0)";

beforeEach(function () {
domHelper(
"<div id=\"moo\"></div>"
);

window.WebKitCSSMatrix = null;
window.MSCSSMatrix = null;
});

it("should return a default matrix if no element argument passed", function () {
it("should return a default matrix if no element argument passed and no matrix function", function () {
var matrix = $.getCssMatrix();
var expected = { a: 0, b: 0, c: 0, d: 0, e: 0, f: 0 };
matrix.should.eql(expected);
});

it("should return a default matrix for an element if an exception occurs", function () {
var stub = sinon.stub(window, "getComputedStyle").throws();
it("should return a matrix from a *Matrix function if present and no element", function () {
window.WebKitCSSMatrix = function () {
return stubMatrix;
};

var matrix = $.getCssMatrix();

matrix.should.eql(stubMatrix);
});

it("should use the WebKitCSSMatrix function if present", function () {
var elt = document.getElementById("moo");

var stubStyle = {
webkitTransform: "matrix(0, 1, -1, 0, 0, 0)"
};

var stub = sinon.stub(window, "getComputedStyle").returns(stubStyle);

window.WebKitCSSMatrix = function () {
return stubMatrix;
};

var matrix = $.getCssMatrix(elt);
matrix.should.eql(stubMatrix);
stub.restore();
});

it("should use the MSCSSMatrix function if present", function () {
var elt = document.getElementById("moo");

var stubStyle = {
transform: "matrix(-1, 0, 0, -1, 0, 0)"
};

var stub = sinon.stub(window, "getComputedStyle").returns(stubStyle);

window.MSCSSMatrix = function () {
return stubMatrix;
};

var matrix = $.getCssMatrix(elt);
matrix.should.eql(stubMatrix);
stub.restore();
});

it("should manually parse CSS matrix if no *Matrix function", function () {
var elt = document.getElementById("moo");

$.feat.cssPrefix = "foo";

var stubStyle = {
fooTransform: "matrix(0, -1, 1, 0, 0, 0)"
};

var stub = sinon.stub(window, "getComputedStyle").returns(stubStyle);

var expected = { a: 0, b: -1, c: 1, d: 0, e: 0, f: 0 };
var matrix = $.getCssMatrix(elt);
matrix.should.eql(expected);
stub.restore();
});

it("should return a default matrix for an element if it has no transform property", function () {
var stub = sinon.stub(window, "getComputedStyle").returns({});
var expected = { a: 0, b: 0, c: 0, d: 0, e: 0, f: 0 };
var elt = document.getElementById("moo");
var matrix = $.getCssMatrix(elt);
matrix.should.eql(expected);
stub.restore();
});

});

0 comments on commit afe48d6

Please sign in to comment.