[Common UI] Add mct-split-pane test cases
...sufficient for full line coverage. WTD-1400
This commit is contained in:
@@ -30,13 +30,16 @@ define(
|
|||||||
'on',
|
'on',
|
||||||
'addClass',
|
'addClass',
|
||||||
'children',
|
'children',
|
||||||
'eq'
|
'eq',
|
||||||
|
'toggleClass',
|
||||||
|
'css'
|
||||||
];
|
];
|
||||||
|
|
||||||
describe("The mct-split-pane directive", function () {
|
describe("The mct-split-pane directive", function () {
|
||||||
var mockParse,
|
var mockParse,
|
||||||
mockLog,
|
mockLog,
|
||||||
mockInterval,
|
mockInterval,
|
||||||
|
mockParsed,
|
||||||
mctSplitPane;
|
mctSplitPane;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -45,6 +48,11 @@ define(
|
|||||||
jasmine.createSpyObj('$log', ['warn', 'info', 'debug']);
|
jasmine.createSpyObj('$log', ['warn', 'info', 'debug']);
|
||||||
mockInterval = jasmine.createSpy('$interval');
|
mockInterval = jasmine.createSpy('$interval');
|
||||||
mockInterval.cancel = jasmine.createSpy('mockCancel');
|
mockInterval.cancel = jasmine.createSpy('mockCancel');
|
||||||
|
mockParsed = jasmine.createSpy('parsed');
|
||||||
|
mockParsed.assign = jasmine.createSpy('assign');
|
||||||
|
|
||||||
|
mockParse.andReturn(mockParsed);
|
||||||
|
|
||||||
mctSplitPane = new MCTSplitPane(
|
mctSplitPane = new MCTSplitPane(
|
||||||
mockParse,
|
mockParse,
|
||||||
mockLog,
|
mockLog,
|
||||||
@@ -61,8 +69,19 @@ define(
|
|||||||
mockElement,
|
mockElement,
|
||||||
testAttrs,
|
testAttrs,
|
||||||
mockChildren,
|
mockChildren,
|
||||||
|
mockFirstPane,
|
||||||
|
mockSplitter,
|
||||||
|
mockSecondPane,
|
||||||
controller;
|
controller;
|
||||||
|
|
||||||
|
function fireOn(eventType) {
|
||||||
|
mockScope.$on.calls.forEach(function (call) {
|
||||||
|
if (call.args[0] === eventType) {
|
||||||
|
call.args[1]();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockScope =
|
mockScope =
|
||||||
jasmine.createSpyObj('$scope', ['$apply', '$watch', '$on']);
|
jasmine.createSpyObj('$scope', ['$apply', '$watch', '$on']);
|
||||||
@@ -71,10 +90,33 @@ define(
|
|||||||
testAttrs = {};
|
testAttrs = {};
|
||||||
mockChildren =
|
mockChildren =
|
||||||
jasmine.createSpyObj('children', JQLITE_METHODS);
|
jasmine.createSpyObj('children', JQLITE_METHODS);
|
||||||
|
mockFirstPane =
|
||||||
|
jasmine.createSpyObj('firstPane', JQLITE_METHODS);
|
||||||
|
mockSplitter =
|
||||||
|
jasmine.createSpyObj('splitter', JQLITE_METHODS);
|
||||||
|
mockSecondPane =
|
||||||
|
jasmine.createSpyObj('secondPane', JQLITE_METHODS);
|
||||||
|
|
||||||
mockElement.children.andReturn(mockChildren);
|
mockElement.children.andReturn(mockChildren);
|
||||||
mockChildren.eq.andReturn(mockChildren);
|
mockElement[0] = {
|
||||||
mockChildren[0] = {};
|
offsetWidth: 12321,
|
||||||
|
offsetHeight: 45654
|
||||||
|
};
|
||||||
|
mockChildren.eq.andCallFake(function (i) {
|
||||||
|
return [mockFirstPane, mockSplitter, mockSecondPane][i];
|
||||||
|
});
|
||||||
|
mockFirstPane[0] = { offsetWidth: 123, offsetHeight: 456 };
|
||||||
|
mockSplitter[0] = {
|
||||||
|
nodeName: 'mct-splitter',
|
||||||
|
offsetWidth: 10,
|
||||||
|
offsetHeight: 456
|
||||||
|
};
|
||||||
|
mockSecondPane[0] = { offsetWidth: 10, offsetHeight: 456 };
|
||||||
|
|
||||||
|
mockChildren[0] = mockFirstPane[0];
|
||||||
|
mockChildren[1] = mockSplitter[0];
|
||||||
|
mockChildren[3] = mockSecondPane[0];
|
||||||
|
mockChildren.length = 3;
|
||||||
|
|
||||||
controller = mctSplitPane.controller[3](
|
controller = mctSplitPane.controller[3](
|
||||||
mockScope,
|
mockScope,
|
||||||
@@ -87,6 +129,77 @@ define(
|
|||||||
expect(mockInterval.mostRecentCall.args[3]).toBe(false);
|
expect(mockInterval.mostRecentCall.args[3]).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("exposes its splitter's initial position", function () {
|
||||||
|
expect(controller.position()).toEqual(
|
||||||
|
mockFirstPane[0].offsetWidth + mockSplitter[0].offsetWidth
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes the current anchoring mode", function () {
|
||||||
|
expect(controller.anchor()).toEqual({
|
||||||
|
edge : 'left',
|
||||||
|
opposite : 'right',
|
||||||
|
dimension : 'width',
|
||||||
|
orientation : 'vertical'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows classes to be toggled on contained elements", function () {
|
||||||
|
controller.toggleClass('resizing');
|
||||||
|
expect(mockChildren.toggleClass)
|
||||||
|
.toHaveBeenCalledWith('resizing');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows positions to be set", function () {
|
||||||
|
var testValue = mockChildren[0].offsetWidth + 50;
|
||||||
|
controller.position(testValue);
|
||||||
|
expect(mockFirstPane.css).toHaveBeenCalledWith(
|
||||||
|
'width',
|
||||||
|
(testValue - mockSplitter[0].offsetWidth) + 'px'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("issues no warnings under nominal usage", function () {
|
||||||
|
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("warns if no mct-splitter is present", function () {
|
||||||
|
mockSplitter[0].nodeName = "not-mct-splitter";
|
||||||
|
controller = mctSplitPane.controller[3](
|
||||||
|
mockScope,
|
||||||
|
mockElement,
|
||||||
|
testAttrs
|
||||||
|
);
|
||||||
|
expect(mockLog.warn).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("warns if an unknown anchor key is given", function () {
|
||||||
|
testAttrs.anchor = "middle";
|
||||||
|
controller = mctSplitPane.controller[3](
|
||||||
|
mockScope,
|
||||||
|
mockElement,
|
||||||
|
testAttrs
|
||||||
|
);
|
||||||
|
expect(mockLog.warn).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("updates positions on a timer", function () {
|
||||||
|
mockFirstPane[0].offsetWidth += 100;
|
||||||
|
// Should not reflect the change yet
|
||||||
|
expect(controller.position()).not.toEqual(
|
||||||
|
mockFirstPane[0].offsetWidth + mockSplitter[0].offsetWidth
|
||||||
|
);
|
||||||
|
mockInterval.mostRecentCall.args[0]();
|
||||||
|
expect(controller.position()).toEqual(
|
||||||
|
mockFirstPane[0].offsetWidth + mockSplitter[0].offsetWidth
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("cancels the active interval when scope is destroyed", function () {
|
||||||
|
expect(mockInterval.cancel).not.toHaveBeenCalled();
|
||||||
|
fireOn('$destroy');
|
||||||
|
expect(mockInterval.cancel).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user