[Common UI] Reorganize general UI tests

Reorganize folder strucutre for tests in bundle
platform/commonUI/general; source folder structure
has been modified to accommodate additional classes
added to support autoflow tabular views, WTD-614,
so test folder needs to be reorganized accordingly
This commit is contained in:
Victor Woeltjen
2014-12-30 13:40:42 -08:00
parent 112622ab9f
commit 54c075dc88
10 changed files with 18 additions and 18 deletions

View File

@@ -0,0 +1,76 @@
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
define(
["../../src/controllers/ActionGroupController"],
function (ActionGroupController) {
"use strict";
describe("The action group controller", function () {
var mockScope,
mockActions,
controller;
function mockAction(metadata, index) {
var action = jasmine.createSpyObj(
"action" + index,
["perform", "getMetadata"]
);
action.getMetadata.andReturn(metadata);
return action;
}
beforeEach(function () {
mockActions = jasmine.createSpyObj("action", ["getActions"]);
mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
controller = new ActionGroupController(mockScope);
});
it("watches scope that may change applicable actions", function () {
// The action capability
expect(mockScope.$watch).toHaveBeenCalledWith(
"action",
jasmine.any(Function)
);
// The category of action to load
expect(mockScope.$watch).toHaveBeenCalledWith(
"parameters.category",
jasmine.any(Function)
);
});
it("populates the scope with grouped and ungrouped actions", function () {
mockScope.action = mockActions;
mockScope.parameters = { category: "test" };
mockActions.getActions.andReturn([
{ group: "a", someKey: 0 },
{ group: "a", someKey: 1 },
{ group: "b", someKey: 2 },
{ group: "a", someKey: 3 },
{ group: "b", someKey: 4 },
{ someKey: 5 },
{ someKey: 6 },
{ group: "a", someKey: 7 },
{ someKey: 8 }
].map(mockAction));
// Call the watch
mockScope.$watch.mostRecentCall.args[1]();
// Should have grouped and ungrouped actions in scope now
expect(mockScope.groups.length).toEqual(2);
expect(mockScope.groups[0].length).toEqual(4); // a
expect(mockScope.groups[1].length).toEqual(2); // b
expect(mockScope.ungrouped.length).toEqual(3); // ungrouped
});
it("provides empty arrays when no action capability is available", function () {
// Call the watch
mockScope.$watch.mostRecentCall.args[1]();
expect(mockScope.groups.length).toEqual(0);
expect(mockScope.ungrouped.length).toEqual(0);
});
});
}
);

View File

@@ -0,0 +1,55 @@
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
define(
["../../src/controllers/BottomBarController"],
function (BottomBarController) {
"use strict";
describe("The bottom bar controller", function () {
var testIndicators,
testIndicatorA,
testIndicatorB,
testIndicatorC,
mockIndicator,
controller;
beforeEach(function () {
mockIndicator = jasmine.createSpyObj(
"indicator",
[ "getGlyph", "getText" ]
);
testIndicatorA = {};
testIndicatorB = function () { return mockIndicator; };
testIndicatorC = { template: "someTemplate" };
testIndicators = [
testIndicatorA,
testIndicatorB,
testIndicatorC
];
controller = new BottomBarController(testIndicators);
});
it("exposes one indicator description per extension", function () {
expect(controller.getIndicators().length)
.toEqual(testIndicators.length);
});
it("uses template field provided, or its own default", function () {
// "indicator" is the default;
// only testIndicatorC overrides this.
var indicators = controller.getIndicators();
expect(indicators[0].template).toEqual("indicator");
expect(indicators[1].template).toEqual("indicator");
expect(indicators[2].template).toEqual("someTemplate");
});
it("instantiates indicators given as constructors", function () {
// testIndicatorB constructs to mockIndicator
expect(controller.getIndicators()[1].ngModel).toBe(mockIndicator);
});
});
}
);

View File

@@ -0,0 +1,73 @@
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
define(
["../../src/controllers/ClickAwayController"],
function (ClickAwayController) {
"use strict";
describe("The click-away controller", function () {
var mockScope,
mockDocument,
controller;
beforeEach(function () {
mockScope = jasmine.createSpyObj(
"$scope",
[ "$apply" ]
);
mockDocument = jasmine.createSpyObj(
"$document",
[ "on", "off" ]
);
controller = new ClickAwayController(mockScope, mockDocument);
});
it("is initially inactive", function () {
expect(controller.isActive()).toBe(false);
});
it("does not listen to the document before being toggled", function () {
expect(mockDocument.on).not.toHaveBeenCalled();
});
it("tracks enabled/disabled state when toggled", function () {
controller.toggle();
expect(controller.isActive()).toBe(true);
controller.toggle();
expect(controller.isActive()).toBe(false);
controller.toggle();
expect(controller.isActive()).toBe(true);
controller.toggle();
expect(controller.isActive()).toBe(false);
});
it("allows active state to be explictly specified", function () {
controller.setState(true);
expect(controller.isActive()).toBe(true);
controller.setState(true);
expect(controller.isActive()).toBe(true);
controller.setState(false);
expect(controller.isActive()).toBe(false);
controller.setState(false);
expect(controller.isActive()).toBe(false);
});
it("registers a mouse listener when activated", function () {
controller.setState(true);
expect(mockDocument.on).toHaveBeenCalled();
});
it("deactivates and detaches listener on document click", function () {
var callback;
controller.setState(true);
callback = mockDocument.on.mostRecentCall.args[1];
callback();
expect(controller.isActive()).toEqual(false);
expect(mockDocument.off).toHaveBeenCalledWith("mouseup", callback);
});
});
}
);

View File

@@ -0,0 +1,41 @@
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
define(
["../../src/controllers/ContextMenuController"],
function (ContextMenuController) {
"use strict";
describe("The context menu controller", function () {
var mockScope,
mockActions,
controller;
beforeEach(function () {
mockActions = jasmine.createSpyObj("action", ["getActions"]);
mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
controller = new ContextMenuController(mockScope);
});
it("watches scope that may change applicable actions", function () {
// The action capability
expect(mockScope.$watch).toHaveBeenCalledWith(
"action",
jasmine.any(Function)
);
});
it("populates the scope with grouped and ungrouped actions", function () {
mockScope.action = mockActions;
mockScope.parameters = { category: "test" };
mockActions.getActions.andReturn(["a", "b", "c"]);
// Call the watch
mockScope.$watch.mostRecentCall.args[1]();
// Should have grouped and ungrouped actions in scope now
expect(mockScope.menuActions.length).toEqual(3);
});
});
}
);

View File

@@ -0,0 +1,43 @@
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
define(
["../../src/controllers/ToggleController"],
function (ToggleController) {
"use strict";
describe("The toggle controller", function () {
var controller;
beforeEach(function () {
controller = new ToggleController();
});
it("is initially inactive", function () {
expect(controller.isActive()).toBe(false);
});
it("tracks enabled/disabled state when toggled", function () {
controller.toggle();
expect(controller.isActive()).toBe(true);
controller.toggle();
expect(controller.isActive()).toBe(false);
controller.toggle();
expect(controller.isActive()).toBe(true);
controller.toggle();
expect(controller.isActive()).toBe(false);
});
it("allows active state to be explictly specified", function () {
controller.setState(true);
expect(controller.isActive()).toBe(true);
controller.setState(true);
expect(controller.isActive()).toBe(true);
controller.setState(false);
expect(controller.isActive()).toBe(false);
controller.setState(false);
expect(controller.isActive()).toBe(false);
});
});
}
);

View File

@@ -0,0 +1,167 @@
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
define(
["../../src/controllers/TreeNodeController"],
function (TreeNodeController) {
"use strict";
describe("The tree node controller", function () {
var mockScope,
mockTimeout,
controller;
function TestObject(id, context) {
return {
getId: function () { return id; },
getCapability: function (key) {
return key === 'context' ? context : undefined;
}
};
}
beforeEach(function () {
mockScope = jasmine.createSpyObj("$scope", ["$watch", "$on"]);
mockTimeout = jasmine.createSpy("$timeout");
controller = new TreeNodeController(mockScope, mockTimeout);
});
it("allows tracking of expansion state", function () {
// The tree node tracks whether or not it has ever
// been expanded in order to lazily load the expanded
// portion of the tree.
expect(controller.hasBeenExpanded()).toBeFalsy();
controller.trackExpansion();
// Expansion is tracked on a timeout, because too
// much expansion can result in an unstable digest.
expect(mockTimeout).toHaveBeenCalled();
mockTimeout.mostRecentCall.args[0]();
expect(controller.hasBeenExpanded()).toBeTruthy();
controller.trackExpansion();
expect(controller.hasBeenExpanded()).toBeTruthy();
});
it("tracks whether or not the represented object is currently navigated-to", function () {
// This is needed to highlight the current selection
var mockContext = jasmine.createSpyObj(
"context",
[ "getParent", "getPath", "getRoot" ]
),
obj = new TestObject("test-object", mockContext);
mockContext.getPath.andReturn([obj]);
// Verify precondition
expect(controller.isSelected()).toBeFalsy();
// Change the represented domain object
mockScope.domainObject = obj;
// Invoke the watch with the new selection
mockScope.$watch.calls[0].args[1](obj);
expect(controller.isSelected()).toBeTruthy();
});
it("expands a node if it is on the navigation path", function () {
var mockParentContext = jasmine.createSpyObj(
"parentContext",
[ "getParent", "getPath", "getRoot" ]
),
mockChildContext = jasmine.createSpyObj(
"childContext",
[ "getParent", "getPath", "getRoot" ]
),
parent = new TestObject("parent", mockParentContext),
child = new TestObject("child", mockChildContext);
mockChildContext.getParent.andReturn(parent);
mockChildContext.getPath.andReturn([parent, child]);
mockParentContext.getPath.andReturn([parent]);
// Set up such that we are on, but not at the end of, a path
mockScope.ngModel = { selectedObject: child };
mockScope.domainObject = parent;
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
// Invoke the watch with the new selection
mockScope.$watch.calls[0].args[1](child);
// Expansion is tracked on a timeout, because too
// much expansion can result in an unstable digest.
// Trigger that timeout.
expect(mockTimeout).toHaveBeenCalled();
mockTimeout.mostRecentCall.args[0]();
expect(mockScope.toggle.setState).toHaveBeenCalledWith(true);
expect(controller.hasBeenExpanded()).toBeTruthy();
expect(controller.isSelected()).toBeFalsy();
});
it("does not expand a node if it is not on the navigation path", function () {
var mockParentContext = jasmine.createSpyObj(
"parentContext",
[ "getParent", "getPath", "getRoot" ]
),
mockChildContext = jasmine.createSpyObj(
"childContext",
[ "getParent", "getPath", "getRoot" ]
),
parent = new TestObject("parent", mockParentContext),
child = new TestObject("child", mockChildContext);
mockChildContext.getParent.andReturn(parent);
mockChildContext.getPath.andReturn([child, child]);
mockParentContext.getPath.andReturn([parent]);
// Set up such that we are on, but not at the end of, a path
mockScope.ngModel = { selectedObject: child };
mockScope.domainObject = parent;
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
// Invoke the watch with the new selection
mockScope.$watch.calls[0].args[1](child);
// Expansion is tracked on a timeout, because too
// much expansion can result in an unstable digest.
// We want to make sure no timeouts are pending here.
expect(mockTimeout).not.toHaveBeenCalled();
expect(controller.hasBeenExpanded()).toBeFalsy();
expect(controller.isSelected()).toBeFalsy();
});
it("does not expand a node if no context is available", function () {
var mockParentContext = jasmine.createSpyObj(
"parentContext",
[ "getParent", "getPath", "getRoot" ]
),
mockChildContext = jasmine.createSpyObj(
"childContext",
[ "getParent", "getPath", "getRoot" ]
),
parent = new TestObject("parent", mockParentContext),
child = new TestObject("child", undefined);
mockChildContext.getParent.andReturn(parent);
mockChildContext.getPath.andReturn([parent, child]);
mockParentContext.getPath.andReturn([parent]);
// Set up such that we are on, but not at the end of, a path
mockScope.ngModel = { selectedObject: child };
mockScope.domainObject = parent;
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
// Invoke the watch with the new selection
mockScope.$watch.calls[0].args[1](child);
expect(mockScope.toggle.setState).not.toHaveBeenCalled();
expect(controller.hasBeenExpanded()).toBeFalsy();
expect(controller.isSelected()).toBeFalsy();
});
});
}
);

View File

@@ -0,0 +1,76 @@
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
/**
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
*/
define(
["../../src/controllers/ViewSwitcherController"],
function (ViewSwitcherController) {
"use strict";
describe("The view switcher controller", function () {
var mockScope,
controller;
beforeEach(function () {
mockScope = jasmine.createSpyObj("$scope", [ "$watch" ]);
mockScope.ngModel = {};
controller = new ViewSwitcherController(mockScope);
});
it("watches for changes in applicable views", function () {
// The view capability is used by associated
// representations, so "view" in scope should always
// be the list of applicable views. The view switcher
// controller should be watching this.
expect(mockScope.$watch).toHaveBeenCalledWith(
"view",
jasmine.any(Function)
);
});
it("maintains the current selection when views change", function () {
var views = [
{ key: "a", name: "View A" },
{ key: "b", name: "View B" },
{ key: "c", name: "View C" },
{ key: "d", name: "View D" }
];
mockScope.$watch.mostRecentCall.args[1](views);
mockScope.ngModel.selected = views[1];
// Change the set of applicable views
mockScope.$watch.mostRecentCall.args[1]([
{ key: "a", name: "View A" },
{ key: "b", name: "View B" },
{ key: "x", name: "View X" }
]);
// "b" is still in there, should remain selected
expect(mockScope.ngModel.selected).toEqual(views[1]);
});
it("chooses a default if a selected view becomes inapplicable", function () {
var views = [
{ key: "a", name: "View A" },
{ key: "b", name: "View B" },
{ key: "c", name: "View C" },
{ key: "d", name: "View D" }
];
mockScope.$watch.mostRecentCall.args[1](views);
mockScope.ngModel.selected = views[1];
// Change the set of applicable views
mockScope.$watch.mostRecentCall.args[1]([
{ key: "a", name: "View A" },
{ key: "c", name: "View C" },
{ key: "x", name: "View X" }
]);
// "b" is still in there, should remain selected
expect(mockScope.ngModel.selected).not.toEqual(views[1]);
});
});
}
);