[Layout] Complete specs
Complete specs for scripts which implement the Layout view, transitioned for WTD-535.
This commit is contained in:
@@ -6,6 +6,91 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("The Layout controller", function () {
|
describe("The Layout controller", function () {
|
||||||
|
var mockScope,
|
||||||
|
testModel,
|
||||||
|
testConfiguration,
|
||||||
|
controller;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockScope = jasmine.createSpyObj(
|
||||||
|
"$scope",
|
||||||
|
[ "$watch" ]
|
||||||
|
);
|
||||||
|
|
||||||
|
testModel = {
|
||||||
|
composition: [ "a", "b", "c" ]
|
||||||
|
};
|
||||||
|
|
||||||
|
testConfiguration = {
|
||||||
|
panels: {
|
||||||
|
a: {
|
||||||
|
position: [20, 10],
|
||||||
|
dimensions: [5, 5]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
mockScope.model = testModel;
|
||||||
|
mockScope.configuration = testConfiguration;
|
||||||
|
|
||||||
|
controller = new LayoutController(mockScope);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Model changes will indicate that panel positions
|
||||||
|
// may have changed, for instance.
|
||||||
|
it("watches for changes to model", function () {
|
||||||
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||||
|
"model",
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("provides styles for frames, from configuration", function () {
|
||||||
|
mockScope.$watch.mostRecentCall.args[1](testModel);
|
||||||
|
expect(controller.getFrameStyle("a")).toEqual({
|
||||||
|
top: "320px",
|
||||||
|
left: "640px",
|
||||||
|
width: "160px",
|
||||||
|
height: "160px"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("provides default styles for frames", function () {
|
||||||
|
var styleB, styleC;
|
||||||
|
|
||||||
|
// b and c do not have configured positions
|
||||||
|
mockScope.$watch.mostRecentCall.args[1](testModel);
|
||||||
|
|
||||||
|
styleB = controller.getFrameStyle("b");
|
||||||
|
styleC = controller.getFrameStyle("c");
|
||||||
|
|
||||||
|
// Should have a position, but we don't care what
|
||||||
|
expect(styleB.left).toBeDefined();
|
||||||
|
expect(styleB.top).toBeDefined();
|
||||||
|
expect(styleC.left).toBeDefined();
|
||||||
|
expect(styleC.top).toBeDefined();
|
||||||
|
|
||||||
|
// Should have ensured some difference in position
|
||||||
|
expect(styleB).not.toEqual(styleC);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows panels to be dragged", function () {
|
||||||
|
// Populate scope
|
||||||
|
mockScope.$watch.mostRecentCall.args[1](testModel);
|
||||||
|
|
||||||
|
// Verify precondtion
|
||||||
|
expect(testConfiguration.panels.b).not.toBeDefined();
|
||||||
|
|
||||||
|
// Do a drag
|
||||||
|
controller.startDrag("b", [1, 1], [0, 0]);
|
||||||
|
controller.continueDrag([100, 100]);
|
||||||
|
controller.endDrag();
|
||||||
|
|
||||||
|
// We do not look closely at the details here;
|
||||||
|
// that is tested in LayoutDragSpec. Just make sure
|
||||||
|
// that a configuration for b has been defined.
|
||||||
|
expect(testConfiguration.panels.b).toBeDefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -6,6 +6,57 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("A Layout drag handler", function () {
|
describe("A Layout drag handler", function () {
|
||||||
|
var testPosition = {
|
||||||
|
position: [ 8, 11 ],
|
||||||
|
dimensions: [ 3, 2 ]
|
||||||
|
};
|
||||||
|
|
||||||
|
it("changes position by a supplied factor, rounding by grid size", function () {
|
||||||
|
var handler = new LayoutDrag(
|
||||||
|
testPosition,
|
||||||
|
[ 1, 1 ],
|
||||||
|
[ 0, 0 ],
|
||||||
|
[ 10, 20 ]
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(handler.getAdjustedPosition([ 37, 84 ])).toEqual({
|
||||||
|
position: [ 12, 15 ],
|
||||||
|
dimensions: [ 3, 2 ]
|
||||||
|
});
|
||||||
|
expect(handler.getAdjustedPosition([ -37, 84 ])).toEqual({
|
||||||
|
position: [ 4, 15 ],
|
||||||
|
dimensions: [ 3, 2 ]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("changes dimensions by a supplied factor, rounding by grid size", function () {
|
||||||
|
var handler = new LayoutDrag(
|
||||||
|
testPosition,
|
||||||
|
[ 0, 0 ],
|
||||||
|
[ 1, 1 ],
|
||||||
|
[ 10, 20 ]
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(handler.getAdjustedPosition([ 37, 84 ])).toEqual({
|
||||||
|
position: [ 8, 11 ],
|
||||||
|
dimensions: [ 7, 6 ]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows mixing dimension and position factors", function () {
|
||||||
|
var handler = new LayoutDrag(
|
||||||
|
testPosition,
|
||||||
|
[ 0, 1 ],
|
||||||
|
[ -1, 0 ],
|
||||||
|
[ 10, 20 ]
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(handler.getAdjustedPosition([ 11, 84 ])).toEqual({
|
||||||
|
position: [ 8, 15 ],
|
||||||
|
dimensions: [ 2, 2 ]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Reference in New Issue
Block a user