Update test specs to use Jasmine 3 (#2089)
* Updated Karma and Jasmine versions * Added DOMObserver class. Supports promise-based testing of DOM changes Update asynchronous test specs to use promises or done() instead of waitsFor/runs * Modified ActionCapability to duplicate context object properties as own properties for better object equality comparisons * Global find + replace to fix syntax issues * Fixed various issues caused by non-deterministic runtime order of tests in Jasmine 3. Fixed issues caused by changes to determination of object equality * Addressed review comments * Resolved merge conflicts with master * Fixed style errors * Use spy.calls.count() instead of manually tracking
This commit is contained in:
committed by
Pete Richards
parent
013eba744d
commit
433dee0314
@@ -46,12 +46,12 @@ define([
|
||||
|
||||
splashElement.className = 'some-class-name';
|
||||
|
||||
$document.querySelectorAll.andReturn([splashElement]);
|
||||
$document.querySelectorAll.and.returnValue([splashElement]);
|
||||
});
|
||||
|
||||
describe('when element exists', function () {
|
||||
beforeEach(function () {
|
||||
$document.querySelectorAll.andReturn([splashElement]);
|
||||
$document.querySelectorAll.and.returnValue([splashElement]);
|
||||
return new SplashScreenManager([$document]);
|
||||
});
|
||||
|
||||
@@ -69,14 +69,14 @@ define([
|
||||
.not
|
||||
.toHaveBeenCalled();
|
||||
|
||||
splashElement.addEventListener.mostRecentCall.args[1]();
|
||||
splashElement.addEventListener.calls.mostRecent().args[1]();
|
||||
expect(splashElement.parentNode.removeChild)
|
||||
.toHaveBeenCalledWith(splashElement);
|
||||
});
|
||||
});
|
||||
|
||||
it('does not error when element doesn\'t exist', function () {
|
||||
$document.querySelectorAll.andReturn([]);
|
||||
$document.querySelectorAll.and.returnValue([]);
|
||||
|
||||
function run() {
|
||||
return new SplashScreenManager([$document]);
|
||||
|
||||
@@ -52,14 +52,14 @@ define(
|
||||
mockHead = jasmine.createSpyObj("head", ["append"]);
|
||||
mockElement = jasmine.createSpyObj("link", ["setAttribute"]);
|
||||
|
||||
mockDocument.find.andReturn(mockHead);
|
||||
mockPlainDocument.createElement.andReturn(mockElement);
|
||||
mockDocument.find.and.returnValue(mockHead);
|
||||
mockPlainDocument.createElement.and.returnValue(mockElement);
|
||||
|
||||
loader = new StyleSheetLoader(testStyleSheets, mockDocument);
|
||||
});
|
||||
|
||||
it("appends one link per stylesheet extension", function () {
|
||||
expect(mockHead.append.calls.length)
|
||||
expect(mockHead.append.calls.count())
|
||||
.toEqual(testStyleSheets.length);
|
||||
});
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ define(
|
||||
"action" + index,
|
||||
["perform", "getMetadata"]
|
||||
);
|
||||
action.getMetadata.andReturn(metadata);
|
||||
action.getMetadata.and.returnValue(metadata);
|
||||
return action;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ define(
|
||||
mockScope.action = mockActions;
|
||||
mockScope.parameters = { category: "test" };
|
||||
|
||||
mockActions.getActions.andReturn([
|
||||
mockActions.getActions.and.returnValue([
|
||||
{ group: "a", someKey: 0 },
|
||||
{ group: "a", someKey: 1 },
|
||||
{ group: "b", someKey: 2 },
|
||||
@@ -74,7 +74,7 @@ define(
|
||||
].map(mockAction));
|
||||
|
||||
// Call the watch
|
||||
mockScope.$watch.mostRecentCall.args[1]();
|
||||
mockScope.$watch.calls.mostRecent().args[1]();
|
||||
|
||||
// Should have grouped and ungrouped actions in scope now
|
||||
expect(mockScope.groups.length).toEqual(2);
|
||||
@@ -85,7 +85,7 @@ define(
|
||||
|
||||
it("provides empty arrays when no action capability is available", function () {
|
||||
// Call the watch
|
||||
mockScope.$watch.mostRecentCall.args[1]();
|
||||
mockScope.$watch.calls.mostRecent().args[1]();
|
||||
|
||||
expect(mockScope.groups.length).toEqual(0);
|
||||
expect(mockScope.ungrouped.length).toEqual(0);
|
||||
|
||||
@@ -79,9 +79,9 @@ define(
|
||||
it("deactivates and detaches listener on document click", function () {
|
||||
var callback, timeout;
|
||||
controller.setState(true);
|
||||
callback = mockDocument.on.mostRecentCall.args[1];
|
||||
callback = mockDocument.on.calls.mostRecent().args[1];
|
||||
callback();
|
||||
timeout = mockTimeout.mostRecentCall.args[0];
|
||||
timeout = mockTimeout.calls.mostRecent().args[0];
|
||||
timeout();
|
||||
expect(controller.isActive()).toEqual(false);
|
||||
expect(mockDocument.off).toHaveBeenCalledWith("mouseup", callback);
|
||||
|
||||
@@ -47,10 +47,10 @@ define(
|
||||
mockScope.action = mockActions;
|
||||
mockScope.parameters = { category: "test" };
|
||||
|
||||
mockActions.getActions.andReturn(["a", "b", "c"]);
|
||||
mockActions.getActions.and.returnValue(["a", "b", "c"]);
|
||||
|
||||
// Call the watch
|
||||
mockScope.$watch.mostRecentCall.args[1]();
|
||||
mockScope.$watch.calls.mostRecent().args[1]();
|
||||
|
||||
// Should have grouped and ungrouped actions in scope now
|
||||
expect(mockScope.menuActions.length).toEqual(3);
|
||||
|
||||
@@ -33,7 +33,7 @@ define(
|
||||
controller;
|
||||
|
||||
function fireWatch(expr, value) {
|
||||
mockScope.$watch.calls.forEach(function (call) {
|
||||
mockScope.$watch.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === expr) {
|
||||
call.args[1](value);
|
||||
}
|
||||
@@ -50,15 +50,15 @@ define(
|
||||
'format'
|
||||
]);
|
||||
|
||||
mockFormatService.getFormat.andReturn(mockFormat);
|
||||
mockFormatService.getFormat.and.returnValue(mockFormat);
|
||||
|
||||
mockFormat.validate.andCallFake(function (text) {
|
||||
mockFormat.validate.and.callFake(function (text) {
|
||||
return moment.utc(text, TEST_FORMAT).isValid();
|
||||
});
|
||||
mockFormat.parse.andCallFake(function (text) {
|
||||
mockFormat.parse.and.callFake(function (text) {
|
||||
return moment.utc(text, TEST_FORMAT).valueOf();
|
||||
});
|
||||
mockFormat.format.andCallFake(function (value) {
|
||||
mockFormat.format.and.callFake(function (value) {
|
||||
return moment.utc(value).format(TEST_FORMAT);
|
||||
});
|
||||
|
||||
@@ -159,8 +159,8 @@ define(
|
||||
var newText = "2015-3-3 01:02:04",
|
||||
oldValue = mockScope.ngModel.testField;
|
||||
|
||||
mockFormat.validate.andReturn(true);
|
||||
mockFormat.parse.andReturn(42);
|
||||
mockFormat.validate.and.returnValue(true);
|
||||
mockFormat.parse.and.returnValue(42);
|
||||
mockScope.textValue = newText;
|
||||
fireWatch("textValue", newText);
|
||||
|
||||
@@ -176,7 +176,7 @@ define(
|
||||
});
|
||||
|
||||
it("throws an error for unknown formats", function () {
|
||||
mockFormatService.getFormat.andReturn(undefined);
|
||||
mockFormatService.getFormat.and.returnValue(undefined);
|
||||
expect(function () {
|
||||
fireWatch("structure.format", "some-format");
|
||||
}).toThrow();
|
||||
@@ -187,9 +187,9 @@ define(
|
||||
testText = "some text";
|
||||
|
||||
beforeEach(function () {
|
||||
mockFormat.validate.andReturn(true);
|
||||
mockFormat.parse.andReturn(testValue);
|
||||
mockFormat.format.andReturn(testText);
|
||||
mockFormat.validate.and.returnValue(true);
|
||||
mockFormat.parse.and.returnValue(testValue);
|
||||
mockFormat.format.and.returnValue(testText);
|
||||
});
|
||||
|
||||
it("parses user input", function () {
|
||||
|
||||
@@ -30,7 +30,7 @@ define(
|
||||
controller;
|
||||
|
||||
function fireWatch(expr, value) {
|
||||
mockScope.$watch.calls.forEach(function (call) {
|
||||
mockScope.$watch.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === expr) {
|
||||
call.args[1](value);
|
||||
}
|
||||
@@ -38,7 +38,7 @@ define(
|
||||
}
|
||||
|
||||
function fireWatchCollection(expr, value) {
|
||||
mockScope.$watchCollection.calls.forEach(function (call) {
|
||||
mockScope.$watchCollection.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === expr) {
|
||||
call.args[1](value);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ define(
|
||||
expect(mockScope.ngModel)
|
||||
.not.toHaveBeenCalledWith("some new value");
|
||||
// Fire the matching watcher
|
||||
mockScope.$watch.calls.forEach(function (call) {
|
||||
mockScope.$watch.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === "getterSetter.value") {
|
||||
call.args[1](mockScope.getterSetter.value);
|
||||
}
|
||||
@@ -64,11 +64,11 @@ define(
|
||||
});
|
||||
|
||||
it("updates internal state when external changes are detected", function () {
|
||||
mockScope.ngModel.andReturn("some other new value");
|
||||
mockScope.ngModel.and.returnValue("some other new value");
|
||||
// Verify precondition
|
||||
expect(mockScope.getterSetter.value).toBeUndefined();
|
||||
// Fire the matching watcher
|
||||
mockScope.$watch.calls.forEach(function (call) {
|
||||
mockScope.$watch.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === "ngModel()") {
|
||||
call.args[1]("some other new value");
|
||||
}
|
||||
|
||||
@@ -50,14 +50,14 @@ define(
|
||||
"promise",
|
||||
["then"]
|
||||
);
|
||||
mockObjectService.getObjects.andReturn(mockPromise);
|
||||
mockObjectService.getObjects.and.returnValue(mockPromise);
|
||||
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"selectedObject",
|
||||
["hasCapability", "getCapability", "useCapability", "getModel"]
|
||||
);
|
||||
mockDomainObject.getModel.andReturn({location: 'somewhere'});
|
||||
mockDomainObject.hasCapability.andReturn(true);
|
||||
mockDomainObject.getModel.and.returnValue({location: 'somewhere'});
|
||||
mockDomainObject.hasCapability.and.returnValue(true);
|
||||
|
||||
mockContextCapability = jasmine.createSpyObj(
|
||||
"context capability",
|
||||
@@ -68,7 +68,7 @@ define(
|
||||
["isLink"]
|
||||
);
|
||||
|
||||
mockDomainObject.getCapability.andCallFake(function (param) {
|
||||
mockDomainObject.getCapability.and.callFake(function (param) {
|
||||
if (param === 'location') {
|
||||
return mockLocationCapability;
|
||||
} else if (param === 'context') {
|
||||
@@ -91,21 +91,21 @@ define(
|
||||
});
|
||||
|
||||
it("looks for contextual parent objects", function () {
|
||||
mockScope.$watch.mostRecentCall.args[1]();
|
||||
mockScope.$watch.calls.mostRecent().args[1]();
|
||||
expect(mockContextCapability.getParent).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("if link, looks for primary parent objects", function () {
|
||||
mockLocationCapability.isLink.andReturn(true);
|
||||
mockLocationCapability.isLink.and.returnValue(true);
|
||||
|
||||
mockScope.$watch.mostRecentCall.args[1]();
|
||||
mockScope.$watch.calls.mostRecent().args[1]();
|
||||
expect(mockDomainObject.getModel).toHaveBeenCalled();
|
||||
expect(mockObjectService.getObjects).toHaveBeenCalled();
|
||||
mockPromise.then.mostRecentCall.args[0]({'somewhere': mockDomainObject});
|
||||
mockPromise.then.calls.mostRecent().args[0]({'somewhere': mockDomainObject});
|
||||
});
|
||||
|
||||
it("gets metadata", function () {
|
||||
mockScope.$watch.mostRecentCall.args[1]();
|
||||
mockScope.$watch.calls.mostRecent().args[1]();
|
||||
expect(mockDomainObject.useCapability).toHaveBeenCalledWith('metadata');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -45,7 +45,7 @@ define(
|
||||
'object-' + id,
|
||||
['getId']
|
||||
);
|
||||
mockObject.getId.andReturn(id);
|
||||
mockObject.getId.and.returnValue(id);
|
||||
return mockObject;
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ define(
|
||||
mockDomainObjects[id] = makeMockObject(id);
|
||||
});
|
||||
|
||||
mockDomainObject.getCapability.andReturn(mockType);
|
||||
mockObjectService.getObjects.andReturn(promiseOf(mockDomainObjects));
|
||||
mockDomainObject.getCapability.and.returnValue(mockType);
|
||||
mockObjectService.getObjects.and.returnValue(promiseOf(mockDomainObjects));
|
||||
mockScope.field = "testField";
|
||||
mockScope.ngModel = {};
|
||||
|
||||
@@ -91,27 +91,27 @@ define(
|
||||
it("watches for changes in selection in left-hand tree", function () {
|
||||
var testObject = { a: 123, b: 456 };
|
||||
// This test is sensitive to ordering of watch calls
|
||||
expect(mockScope.$watch.calls.length).toEqual(1);
|
||||
expect(mockScope.$watch.calls.count()).toEqual(1);
|
||||
// Make sure we're watching the correct object
|
||||
controller.treeModel.selectedObject = testObject;
|
||||
expect(mockScope.$watch.calls[0].args[0]()).toBe(testObject);
|
||||
expect(mockScope.$watch.calls.all()[0].args[0]()).toBe(testObject);
|
||||
});
|
||||
|
||||
it("watches for changes in controlled property", function () {
|
||||
var testValue = ["a", "b", 1, 2];
|
||||
// This test is sensitive to ordering of watch calls
|
||||
expect(mockScope.$watchCollection.calls.length).toEqual(1);
|
||||
expect(mockScope.$watchCollection.calls.count()).toEqual(1);
|
||||
// Make sure we're watching the correct object
|
||||
mockScope.ngModel = { testField: testValue };
|
||||
expect(mockScope.$watchCollection.calls[0].args[0]()).toBe(testValue);
|
||||
expect(mockScope.$watchCollection.calls.all()[0].args[0]()).toBe(testValue);
|
||||
});
|
||||
|
||||
it("rejects selection of incorrect types", function () {
|
||||
mockScope.structure = { type: "someType" };
|
||||
mockType.instanceOf.andReturn(false);
|
||||
mockType.instanceOf.and.returnValue(false);
|
||||
controller.treeModel.selectedObject = mockDomainObject;
|
||||
// Fire the watch
|
||||
mockScope.$watch.calls[0].args[1](mockDomainObject);
|
||||
mockScope.$watch.calls.all()[0].args[1](mockDomainObject);
|
||||
// Should have cleared the selection
|
||||
expect(controller.treeModel.selectedObject).toBeUndefined();
|
||||
// Verify interaction (that instanceOf got a useful argument)
|
||||
@@ -120,10 +120,10 @@ define(
|
||||
|
||||
it("permits selection of matching types", function () {
|
||||
mockScope.structure = { type: "someType" };
|
||||
mockType.instanceOf.andReturn(true);
|
||||
mockType.instanceOf.and.returnValue(true);
|
||||
controller.treeModel.selectedObject = mockDomainObject;
|
||||
// Fire the watch
|
||||
mockScope.$watch.calls[0].args[1](mockDomainObject);
|
||||
mockScope.$watch.calls.all()[0].args[1](mockDomainObject);
|
||||
// Should have preserved the selection
|
||||
expect(controller.treeModel.selectedObject).toEqual(mockDomainObject);
|
||||
// Verify interaction (that instanceOf got a useful argument)
|
||||
@@ -133,11 +133,11 @@ define(
|
||||
it("loads objects when the underlying list changes", function () {
|
||||
var testIds = ["abc", "def", "xyz"];
|
||||
// This test is sensitive to ordering of watch calls
|
||||
expect(mockScope.$watchCollection.calls.length).toEqual(1);
|
||||
expect(mockScope.$watchCollection.calls.count()).toEqual(1);
|
||||
// Make sure we're watching the correct object
|
||||
mockScope.ngModel = { testField: testIds };
|
||||
// Fire the watch
|
||||
mockScope.$watchCollection.calls[0].args[1](testIds);
|
||||
mockScope.$watchCollection.calls.all()[0].args[1](testIds);
|
||||
// Should have loaded the corresponding objects
|
||||
expect(mockObjectService.getObjects).toHaveBeenCalledWith(testIds);
|
||||
});
|
||||
@@ -169,8 +169,8 @@ define(
|
||||
controller.select(mockDomainObjects.def);
|
||||
controller.select(mockDomainObjects.abc);
|
||||
// Fire the watch for the id changes...
|
||||
mockScope.$watchCollection.calls[0].args[1](
|
||||
mockScope.$watchCollection.calls[0].args[0]()
|
||||
mockScope.$watchCollection.calls.all()[0].args[1](
|
||||
mockScope.$watchCollection.calls.all()[0].args[0]()
|
||||
);
|
||||
// Should have loaded and exposed those objects
|
||||
expect(controller.selected()).toEqual(
|
||||
|
||||
@@ -39,7 +39,7 @@ define(
|
||||
controller;
|
||||
|
||||
function fireWatch(expr, value) {
|
||||
mockScope.$watch.calls.forEach(function (call) {
|
||||
mockScope.$watch.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === expr) {
|
||||
call.args[1](value);
|
||||
}
|
||||
@@ -47,7 +47,7 @@ define(
|
||||
}
|
||||
|
||||
function fireWatchCollection(expr, value) {
|
||||
mockScope.$watchCollection.calls.forEach(function (call) {
|
||||
mockScope.$watchCollection.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === expr) {
|
||||
call.args[1](value);
|
||||
}
|
||||
@@ -73,9 +73,9 @@ define(
|
||||
["validate", "format", "parse"]
|
||||
);
|
||||
|
||||
mockFormatService.getFormat.andReturn(mockFormat);
|
||||
mockFormatService.getFormat.and.returnValue(mockFormat);
|
||||
|
||||
mockFormat.format.andCallFake(function (value) {
|
||||
mockFormat.format.and.callFake(function (value) {
|
||||
return moment.utc(value).format("YYYY-MM-DD HH:mm:ss");
|
||||
});
|
||||
|
||||
@@ -300,7 +300,7 @@ define(
|
||||
});
|
||||
|
||||
it("throws an error for unknown formats", function () {
|
||||
mockFormatService.getFormat.andReturn(undefined);
|
||||
mockFormatService.getFormat.and.returnValue(undefined);
|
||||
expect(function () {
|
||||
fireWatch("parameters.format", "some-format");
|
||||
}).toThrow();
|
||||
|
||||
@@ -62,7 +62,7 @@ define(
|
||||
// Expansion is tracked on a timeout, because too
|
||||
// much expansion can result in an unstable digest.
|
||||
expect(mockTimeout).toHaveBeenCalled();
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
|
||||
expect(controller.hasBeenExpanded()).toBeTruthy();
|
||||
controller.trackExpansion();
|
||||
@@ -77,7 +77,7 @@ define(
|
||||
),
|
||||
obj = new TestObject("test-object", mockContext);
|
||||
|
||||
mockContext.getPath.andReturn([obj]);
|
||||
mockContext.getPath.and.returnValue([obj]);
|
||||
|
||||
// Verify precondition
|
||||
expect(controller.isSelected()).toBeFalsy();
|
||||
@@ -86,7 +86,7 @@ define(
|
||||
mockScope.domainObject = obj;
|
||||
|
||||
// Invoke the watch with the new selection
|
||||
mockScope.$watch.calls[0].args[1](obj);
|
||||
mockScope.$watch.calls.all()[0].args[1](obj);
|
||||
|
||||
expect(controller.isSelected()).toBeTruthy();
|
||||
});
|
||||
@@ -103,9 +103,9 @@ define(
|
||||
parent = new TestObject("parent", mockParentContext),
|
||||
child = new TestObject("child", mockChildContext);
|
||||
|
||||
mockChildContext.getParent.andReturn(parent);
|
||||
mockChildContext.getPath.andReturn([parent, child]);
|
||||
mockParentContext.getPath.andReturn([parent]);
|
||||
mockChildContext.getParent.and.returnValue(parent);
|
||||
mockChildContext.getPath.and.returnValue([parent, child]);
|
||||
mockParentContext.getPath.and.returnValue([parent]);
|
||||
|
||||
// Set up such that we are on, but not at the end of, a path
|
||||
mockScope.ngModel = { selectedObject: child };
|
||||
@@ -113,13 +113,13 @@ define(
|
||||
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
|
||||
|
||||
// Invoke the watch with the new selection
|
||||
mockScope.$watch.calls[0].args[1](child);
|
||||
mockScope.$watch.calls.all()[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]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
|
||||
expect(mockScope.toggle.setState).toHaveBeenCalledWith(true);
|
||||
expect(controller.hasBeenExpanded()).toBeTruthy();
|
||||
@@ -139,9 +139,9 @@ define(
|
||||
parent = new TestObject("parent", mockParentContext),
|
||||
child = new TestObject("child", mockChildContext);
|
||||
|
||||
mockChildContext.getParent.andReturn(parent);
|
||||
mockChildContext.getPath.andReturn([child, child]);
|
||||
mockParentContext.getPath.andReturn([parent]);
|
||||
mockChildContext.getParent.and.returnValue(parent);
|
||||
mockChildContext.getPath.and.returnValue([child, child]);
|
||||
mockParentContext.getPath.and.returnValue([parent]);
|
||||
|
||||
// Set up such that we are on, but not at the end of, a path
|
||||
mockScope.ngModel = { selectedObject: child };
|
||||
@@ -149,7 +149,7 @@ define(
|
||||
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
|
||||
|
||||
// Invoke the watch with the new selection
|
||||
mockScope.$watch.calls[0].args[1](child);
|
||||
mockScope.$watch.calls.all()[0].args[1](child);
|
||||
|
||||
// Expansion is tracked on a timeout, because too
|
||||
// much expansion can result in an unstable digest.
|
||||
@@ -172,9 +172,9 @@ define(
|
||||
parent = new TestObject("parent", mockParentContext),
|
||||
child = new TestObject("child", undefined);
|
||||
|
||||
mockChildContext.getParent.andReturn(parent);
|
||||
mockChildContext.getPath.andReturn([parent, child]);
|
||||
mockParentContext.getPath.andReturn([parent]);
|
||||
mockChildContext.getParent.and.returnValue(parent);
|
||||
mockChildContext.getPath.and.returnValue([parent, child]);
|
||||
mockParentContext.getPath.and.returnValue([parent]);
|
||||
|
||||
// Set up such that we are on, but not at the end of, a path
|
||||
mockScope.ngModel = { selectedObject: child };
|
||||
@@ -182,7 +182,7 @@ define(
|
||||
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
|
||||
|
||||
// Invoke the watch with the new selection
|
||||
mockScope.$watch.calls[0].args[1](child);
|
||||
mockScope.$watch.calls.all()[0].args[1](child);
|
||||
|
||||
expect(mockScope.toggle.setState).not.toHaveBeenCalled();
|
||||
expect(controller.hasBeenExpanded()).toBeFalsy();
|
||||
|
||||
@@ -35,7 +35,7 @@ define(
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
|
||||
mockTimeout = jasmine.createSpy("$timeout");
|
||||
mockTimeout.andCallFake(function (cb) {
|
||||
mockTimeout.and.callFake(function (cb) {
|
||||
cb();
|
||||
});
|
||||
mockScope.ngModel = {};
|
||||
@@ -60,11 +60,11 @@ define(
|
||||
{ key: "c", name: "View C" },
|
||||
{ key: "d", name: "View D" }
|
||||
];
|
||||
mockScope.$watch.mostRecentCall.args[1](views);
|
||||
mockScope.$watch.calls.mostRecent().args[1](views);
|
||||
mockScope.ngModel.selected = views[1];
|
||||
|
||||
// Change the set of applicable views
|
||||
mockScope.$watch.mostRecentCall.args[1]([
|
||||
mockScope.$watch.calls.mostRecent().args[1]([
|
||||
{ key: "a", name: "View A" },
|
||||
{ key: "b", name: "View B" },
|
||||
{ key: "x", name: "View X" }
|
||||
@@ -81,11 +81,11 @@ define(
|
||||
{ key: "c", name: "View C" },
|
||||
{ key: "d", name: "View D" }
|
||||
];
|
||||
mockScope.$watch.mostRecentCall.args[1](views);
|
||||
mockScope.$watch.calls.mostRecent().args[1](views);
|
||||
mockScope.ngModel.selected = views[1];
|
||||
|
||||
// Change the set of applicable views
|
||||
mockScope.$watch.mostRecentCall.args[1]([
|
||||
mockScope.$watch.calls.mostRecent().args[1]([
|
||||
{ key: "a", name: "View A" },
|
||||
{ key: "c", name: "View C" },
|
||||
{ key: "x", name: "View X" }
|
||||
@@ -102,7 +102,7 @@ define(
|
||||
expect(mockTimeout).not.toHaveBeenCalled();
|
||||
|
||||
// Invoke the watch for set of views
|
||||
mockScope.$watch.mostRecentCall.args[1]([]);
|
||||
mockScope.$watch.calls.mostRecent().args[1]([]);
|
||||
|
||||
// Should have run on a timeout
|
||||
expect(mockTimeout).toHaveBeenCalled();
|
||||
|
||||
@@ -66,9 +66,9 @@ define(
|
||||
height: 75
|
||||
};
|
||||
mockElement[0] = mockPlainEl;
|
||||
mockPlainEl.getBoundingClientRect.andReturn(testRect);
|
||||
mockPlainEl.getBoundingClientRect.and.returnValue(testRect);
|
||||
|
||||
mockDocument.find.andReturn(mockBody);
|
||||
mockDocument.find.and.returnValue(mockBody);
|
||||
|
||||
mctClickElsewhere = new MCTClickElsewhere(mockDocument);
|
||||
mctClickElsewhere.link(mockScope, mockElement, testAttrs);
|
||||
@@ -80,14 +80,14 @@ define(
|
||||
|
||||
it("detaches listeners when destroyed", function () {
|
||||
expect(mockBody.off).not.toHaveBeenCalled();
|
||||
mockScope.$on.calls.forEach(function (call) {
|
||||
mockScope.$on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === '$destroy') {
|
||||
call.args[1]();
|
||||
}
|
||||
});
|
||||
expect(mockBody.off).toHaveBeenCalled();
|
||||
expect(mockBody.off.mostRecentCall.args)
|
||||
.toEqual(mockBody.on.mostRecentCall.args);
|
||||
expect(mockBody.off.calls.mostRecent().args)
|
||||
.toEqual(mockBody.on.calls.mostRecent().args);
|
||||
});
|
||||
|
||||
it("listens for mousedown on the document's body", function () {
|
||||
@@ -97,7 +97,7 @@ define(
|
||||
|
||||
describe("when a click occurs outside the element's bounds", function () {
|
||||
beforeEach(function () {
|
||||
mockBody.on.mostRecentCall.args[1](testEvent(
|
||||
mockBody.on.calls.mostRecent().args[1](testEvent(
|
||||
testRect.left + testRect.width + 10,
|
||||
testRect.top + testRect.height + 10
|
||||
));
|
||||
@@ -105,7 +105,7 @@ define(
|
||||
|
||||
it("triggers an evaluation of its related Angular expression", function () {
|
||||
expect(mockScope.$apply).toHaveBeenCalled();
|
||||
mockScope.$apply.mostRecentCall.args[0]();
|
||||
mockScope.$apply.calls.mostRecent().args[0]();
|
||||
expect(mockScope.$eval)
|
||||
.toHaveBeenCalledWith(testAttrs.mctClickElsewhere);
|
||||
});
|
||||
@@ -113,7 +113,7 @@ define(
|
||||
|
||||
describe("when a click occurs within the element's bounds", function () {
|
||||
beforeEach(function () {
|
||||
mockBody.on.mostRecentCall.args[1](testEvent(
|
||||
mockBody.on.calls.mostRecent().args[1](testEvent(
|
||||
testRect.left + testRect.width / 2,
|
||||
testRect.top + testRect.height / 2
|
||||
));
|
||||
|
||||
@@ -61,8 +61,8 @@ define(
|
||||
mctDragUp: "ending a drag"
|
||||
};
|
||||
|
||||
mockDocument.find.andReturn(mockBody);
|
||||
mockAgentService.isMobile.andReturn(true);
|
||||
mockDocument.find.and.returnValue(mockBody);
|
||||
mockAgentService.isMobile.and.returnValue(true);
|
||||
|
||||
mctDrag = new MCTDrag(mockDocument, mockAgentService);
|
||||
mctDrag.link(mockScope, mockElement, testAttrs);
|
||||
@@ -84,7 +84,7 @@ define(
|
||||
|
||||
it("invokes mctDragDown when dragging begins", function () {
|
||||
var event = testEvent(42, 60);
|
||||
mockElement.on.mostRecentCall.args[1](event);
|
||||
mockElement.on.calls.mostRecent().args[1](event);
|
||||
expect(mockScope.$eval).toHaveBeenCalledWith(
|
||||
testAttrs.mctDragDown,
|
||||
{ delta: [0, 0], $event: event }
|
||||
@@ -92,7 +92,7 @@ define(
|
||||
});
|
||||
|
||||
it("listens for touchmove after dragging begins", function () {
|
||||
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||
mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
|
||||
expect(mockBody.on).toHaveBeenCalledWith(
|
||||
"touchmove",
|
||||
jasmine.any(Function)
|
||||
@@ -106,10 +106,10 @@ define(
|
||||
it("invokes mctDrag expression during drag", function () {
|
||||
var event;
|
||||
|
||||
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||
mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
|
||||
|
||||
// Find and invoke the touchmove listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
mockBody.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'touchmove') {
|
||||
call.args[1](event = testEvent(52, 200));
|
||||
}
|
||||
@@ -125,16 +125,16 @@ define(
|
||||
it("invokes mctDragUp expression after drag", function () {
|
||||
var event;
|
||||
|
||||
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||
mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
|
||||
|
||||
// Find and invoke the touchmove listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
mockBody.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'touchmove') {
|
||||
call.args[1](testEvent(52, 200));
|
||||
}
|
||||
});
|
||||
// Find and invoke the touchmove listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
mockBody.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'touchend') {
|
||||
call.args[1](event = testEvent(40, 71));
|
||||
}
|
||||
@@ -189,8 +189,8 @@ define(
|
||||
mctDragUp: "ending a drag"
|
||||
};
|
||||
|
||||
mockDocument.find.andReturn(mockBody);
|
||||
mockAgentService.isMobile.andReturn(false);
|
||||
mockDocument.find.and.returnValue(mockBody);
|
||||
mockAgentService.isMobile.and.returnValue(false);
|
||||
|
||||
mctDrag = new MCTDrag(mockDocument, mockAgentService);
|
||||
mctDrag.link(mockScope, mockElement, testAttrs);
|
||||
@@ -212,7 +212,7 @@ define(
|
||||
|
||||
it("invokes mctDragDown when dragging begins", function () {
|
||||
var event = testEvent(42, 60);
|
||||
mockElement.on.mostRecentCall.args[1](event);
|
||||
mockElement.on.calls.mostRecent().args[1](event);
|
||||
expect(mockScope.$eval).toHaveBeenCalledWith(
|
||||
testAttrs.mctDragDown,
|
||||
{ delta: [0, 0], $event: event }
|
||||
@@ -220,7 +220,7 @@ define(
|
||||
});
|
||||
|
||||
it("listens for mousemove after dragging begins", function () {
|
||||
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||
mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
|
||||
expect(mockBody.on).toHaveBeenCalledWith(
|
||||
"mousemove",
|
||||
jasmine.any(Function)
|
||||
@@ -234,10 +234,10 @@ define(
|
||||
it("invokes mctDrag expression during drag", function () {
|
||||
var event;
|
||||
|
||||
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||
mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
|
||||
|
||||
// Find and invoke the mousemove listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
mockBody.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'mousemove') {
|
||||
call.args[1](event = testEvent(52, 200));
|
||||
}
|
||||
@@ -253,16 +253,16 @@ define(
|
||||
it("invokes mctDragUp expression after drag", function () {
|
||||
var event;
|
||||
|
||||
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||
mockElement.on.calls.mostRecent().args[1](testEvent(42, 60));
|
||||
|
||||
// Find and invoke the mousemove listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
mockBody.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'mousemove') {
|
||||
call.args[1](testEvent(52, 200));
|
||||
}
|
||||
});
|
||||
// Find and invoke the mousemove listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
mockBody.on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === 'mouseup') {
|
||||
call.args[1](event = testEvent(40, 71));
|
||||
}
|
||||
|
||||
@@ -78,14 +78,14 @@ define(
|
||||
height: 75
|
||||
};
|
||||
|
||||
mockCompile.andCallFake(function () {
|
||||
mockCompile.and.callFake(function () {
|
||||
var mockFn = jasmine.createSpy();
|
||||
mockFn.andReturn(mockNewElement);
|
||||
mockFn.and.returnValue(mockNewElement);
|
||||
return mockFn;
|
||||
});
|
||||
mockElement.parent.andReturn([mockParentEl]);
|
||||
mockParentEl.getBoundingClientRect.andReturn(testRect);
|
||||
mockPopupService.display.andReturn(mockPopup);
|
||||
mockElement.parent.and.returnValue([mockParentEl]);
|
||||
mockParentEl.getBoundingClientRect.and.returnValue(testRect);
|
||||
mockPopupService.display.and.returnValue(mockPopup);
|
||||
|
||||
mctPopup = new MCTPopup(mockCompile, mockPopupService);
|
||||
|
||||
@@ -113,14 +113,14 @@ define(
|
||||
it("displays transcluded content", function () {
|
||||
var mockClone =
|
||||
jasmine.createSpyObj('clone', JQLITE_METHODS);
|
||||
mockTransclude.mostRecentCall.args[0](mockClone);
|
||||
mockTransclude.calls.mostRecent().args[0](mockClone);
|
||||
expect(mockNewElement.append)
|
||||
.toHaveBeenCalledWith(mockClone);
|
||||
});
|
||||
|
||||
it("is removed when its containing scope is destroyed", function () {
|
||||
expect(mockPopup.dismiss).not.toHaveBeenCalled();
|
||||
mockScope.$on.calls.forEach(function (call) {
|
||||
mockScope.$on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === '$destroy') {
|
||||
call.args[1]();
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ define(
|
||||
);
|
||||
|
||||
// Fire the timeout
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
|
||||
// Should have triggered an evaluation of mctResize
|
||||
// with the new width & height
|
||||
@@ -91,56 +91,56 @@ define(
|
||||
.toHaveBeenCalledWith("$destroy", jasmine.any(Function));
|
||||
|
||||
// Should have scheduled the first timeout
|
||||
expect(mockTimeout.calls.length).toEqual(1);
|
||||
expect(mockTimeout.calls.count()).toEqual(1);
|
||||
|
||||
// Fire the timeout
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
|
||||
// Should have scheduled another timeout
|
||||
expect(mockTimeout.calls.length).toEqual(2);
|
||||
expect(mockTimeout.calls.count()).toEqual(2);
|
||||
|
||||
// Broadcast a destroy event
|
||||
mockScope.$on.mostRecentCall.args[1]();
|
||||
mockScope.$on.calls.mostRecent().args[1]();
|
||||
|
||||
testElement.offsetWidth = 300;
|
||||
testElement.offsetHeight = 350;
|
||||
mockScope.$eval.reset();
|
||||
mockScope.$eval.calls.reset();
|
||||
|
||||
// Fire the timeout
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
|
||||
// Should NOT have scheduled another timeout
|
||||
expect(mockTimeout.calls.length).toEqual(2);
|
||||
expect(mockTimeout.calls.count()).toEqual(2);
|
||||
expect(mockScope.$eval).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("triggers a digest cycle when size changes", function () {
|
||||
var applyCount;
|
||||
mctResize.link(mockScope, [testElement], testAttrs);
|
||||
applyCount = mockScope.$apply.calls.length;
|
||||
applyCount = mockScope.$apply.calls.count();
|
||||
|
||||
// Change the element's apparent size
|
||||
testElement.offsetWidth = 300;
|
||||
testElement.offsetHeight = 350;
|
||||
|
||||
// Fire the timeout
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
|
||||
// No more apply calls
|
||||
expect(mockScope.$apply.calls.length)
|
||||
expect(mockScope.$apply.calls.count())
|
||||
.toBeGreaterThan(applyCount);
|
||||
});
|
||||
|
||||
it("does not trigger a digest cycle when size does not change", function () {
|
||||
var applyCount;
|
||||
mctResize.link(mockScope, [testElement], testAttrs);
|
||||
applyCount = mockScope.$apply.calls.length;
|
||||
applyCount = mockScope.$apply.calls.count();
|
||||
|
||||
// Fire the timeout
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
mockTimeout.calls.mostRecent().args[0]();
|
||||
|
||||
// No more apply calls
|
||||
expect(mockScope.$apply.calls.length).toEqual(applyCount);
|
||||
expect(mockScope.$apply.calls.count()).toEqual(applyCount);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -49,7 +49,7 @@ define(
|
||||
mockElement = [{ testProperty: 42 }];
|
||||
mockElement.on = jasmine.createSpy('on');
|
||||
|
||||
mockParse.andReturn(mockParsed);
|
||||
mockParse.and.returnValue(mockParsed);
|
||||
|
||||
testAttrs = {};
|
||||
testAttrs[ATTRIBUTE] = EXPRESSION;
|
||||
@@ -76,7 +76,7 @@ define(
|
||||
jasmine.any(Function)
|
||||
);
|
||||
// Should have been only watch (other tests need this to be true)
|
||||
expect(mockScope.$watch.calls.length).toEqual(1);
|
||||
expect(mockScope.$watch.calls.count()).toEqual(1);
|
||||
});
|
||||
|
||||
it("listens for scroll events", function () {
|
||||
@@ -85,7 +85,7 @@ define(
|
||||
jasmine.any(Function)
|
||||
);
|
||||
// Should have been only listener (other tests need this to be true)
|
||||
expect(mockElement.on.calls.length).toEqual(1);
|
||||
expect(mockElement.on.calls.count()).toEqual(1);
|
||||
});
|
||||
|
||||
it("publishes initial scroll state", function () {
|
||||
@@ -94,13 +94,13 @@ define(
|
||||
});
|
||||
|
||||
it("updates scroll state when scope changes", function () {
|
||||
mockScope.$watch.mostRecentCall.args[1](64);
|
||||
mockScope.$watch.calls.mostRecent().args[1](64);
|
||||
expect(mockElement[0].testProperty).toEqual(64);
|
||||
});
|
||||
|
||||
it("updates scope when scroll state changes", function () {
|
||||
mockElement[0].testProperty = 12321;
|
||||
mockElement.on.mostRecentCall.args[1]({ target: mockElement[0] });
|
||||
mockElement.on.calls.mostRecent().args[1]({ target: mockElement[0] });
|
||||
expect(mockParsed.assign).toHaveBeenCalledWith(mockScope, 12321);
|
||||
expect(mockScope.$apply).toHaveBeenCalledWith(EXPRESSION);
|
||||
});
|
||||
|
||||
@@ -49,7 +49,7 @@ define(
|
||||
mockInterval.cancel = jasmine.createSpy('mockCancel');
|
||||
mockParsed = jasmine.createSpy('parsed');
|
||||
mockParsed.assign = jasmine.createSpy('assign');
|
||||
mockParse.andReturn(mockParsed);
|
||||
mockParse.and.returnValue(mockParsed);
|
||||
|
||||
mockWindow.localStorage = {
|
||||
store: {},
|
||||
@@ -84,7 +84,7 @@ define(
|
||||
controller;
|
||||
|
||||
function fireOn(eventType) {
|
||||
mockScope.$on.calls.forEach(function (call) {
|
||||
mockScope.$on.calls.all().forEach(function (call) {
|
||||
if (call.args[0] === eventType) {
|
||||
call.args[1]();
|
||||
}
|
||||
@@ -106,12 +106,12 @@ define(
|
||||
mockSecondPane =
|
||||
jasmine.createSpyObj('secondPane', JQLITE_METHODS);
|
||||
|
||||
mockElement.children.andReturn(mockChildren);
|
||||
mockElement.children.and.returnValue(mockChildren);
|
||||
mockElement[0] = {
|
||||
offsetWidth: 12321,
|
||||
offsetHeight: 45654
|
||||
};
|
||||
mockChildren.eq.andCallFake(function (i) {
|
||||
mockChildren.eq.and.callFake(function (i) {
|
||||
return [mockFirstPane, mockSplitter, mockSecondPane][i];
|
||||
});
|
||||
mockFirstPane[0] = { offsetWidth: 123, offsetHeight: 456 };
|
||||
@@ -135,7 +135,7 @@ define(
|
||||
});
|
||||
|
||||
it("sets an interval which does not trigger digests", function () {
|
||||
expect(mockInterval.mostRecentCall.args[3]).toBe(false);
|
||||
expect(mockInterval.calls.mostRecent().args[3]).toBe(false);
|
||||
});
|
||||
|
||||
it("exposes its splitter's initial position", function () {
|
||||
@@ -202,7 +202,7 @@ define(
|
||||
expect(controller.position()).not.toEqual(
|
||||
mockFirstPane[0].offsetWidth
|
||||
);
|
||||
mockInterval.mostRecentCall.args[0]();
|
||||
mockInterval.calls.mostRecent().args[0]();
|
||||
expect(controller.position()).toEqual(
|
||||
mockFirstPane[0].offsetWidth
|
||||
);
|
||||
|
||||
@@ -78,8 +78,8 @@ define(
|
||||
|
||||
beforeEach(function () {
|
||||
testPosition = 12321;
|
||||
mockSplitPane.position.andReturn(testPosition);
|
||||
mockSplitPane.anchor.andReturn({
|
||||
mockSplitPane.position.and.returnValue(testPosition);
|
||||
mockSplitPane.anchor.and.returnValue({
|
||||
orientation: 'vertical',
|
||||
reversed: false
|
||||
});
|
||||
|
||||
@@ -38,8 +38,8 @@ define([
|
||||
'getCapability',
|
||||
'hasCapability'
|
||||
]);
|
||||
mockDomainObject.getId.andReturn(id);
|
||||
mockDomainObject.getModel.andReturn({});
|
||||
mockDomainObject.getId.and.returnValue(id);
|
||||
mockDomainObject.getModel.and.returnValue({});
|
||||
return mockDomainObject;
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ define([
|
||||
mockParse = jasmine.createSpy('$parse');
|
||||
mockExpr = jasmine.createSpy('expr');
|
||||
mockExpr.assign = jasmine.createSpy('assign');
|
||||
mockParse.andReturn(mockExpr);
|
||||
spyOn(TreeView.prototype, 'observe').andCallThrough();
|
||||
mockParse.and.returnValue(mockExpr);
|
||||
spyOn(TreeView.prototype, 'observe').and.callThrough();
|
||||
|
||||
mctTree = new MCTTree(mockParse, mockGestureService);
|
||||
});
|
||||
@@ -118,7 +118,7 @@ define([
|
||||
it("does not trigger $apply during $watches", function () {
|
||||
mockScope.mctObject = makeMockDomainObject('root');
|
||||
mockScope.mctMode = makeMockDomainObject('selection');
|
||||
mockScope.$watch.calls.forEach(function (call) {
|
||||
mockScope.$watch.calls.all().forEach(function (call) {
|
||||
call.args[1](mockScope[call.args[0]]);
|
||||
});
|
||||
expect(mockScope.$apply).not.toHaveBeenCalled();
|
||||
@@ -129,7 +129,7 @@ define([
|
||||
return;
|
||||
}
|
||||
// White-boxy; we know this is the setter for the tree's value
|
||||
var treeValueFn = TreeView.prototype.observe.calls[0].args[0];
|
||||
var treeValueFn = TreeView.prototype.observe.calls.all()[0].args[0];
|
||||
|
||||
mockScope.mctObject = makeMockDomainObject('root');
|
||||
mockScope.mctMode = makeMockDomainObject('selection');
|
||||
|
||||
@@ -41,7 +41,7 @@ define(
|
||||
'remove'
|
||||
]);
|
||||
|
||||
mockDocument.find.andCallFake(function (query) {
|
||||
mockDocument.find.and.callFake(function (query) {
|
||||
return query === 'body' && mockBody;
|
||||
});
|
||||
|
||||
|
||||
@@ -60,25 +60,25 @@ define(
|
||||
|
||||
// The mockContext is set a path
|
||||
// for the mockDomainObject
|
||||
mockContext.getPath.andReturn(
|
||||
mockContext.getPath.and.returnValue(
|
||||
[mockDomainObject]
|
||||
);
|
||||
|
||||
// view capability used with the testviews made
|
||||
mockDomainObject.useCapability.andCallFake(function (c) {
|
||||
mockDomainObject.useCapability.and.callFake(function (c) {
|
||||
return (c === 'view') && testViews;
|
||||
});
|
||||
|
||||
// context capability used with the mockContext created
|
||||
// so the variables including context in the urlFor are
|
||||
// initialized and reached
|
||||
mockDomainObject.getCapability.andCallFake(function (c) {
|
||||
mockDomainObject.getCapability.and.callFake(function (c) {
|
||||
return c === 'context' && mockContext;
|
||||
});
|
||||
|
||||
// Uses the mockLocation to get the current
|
||||
// "mock" website's view
|
||||
mockLocation.search.andReturn({ view: 'def' });
|
||||
mockLocation.search.and.returnValue({ view: 'def' });
|
||||
|
||||
urlService = new UrlService(mockLocation);
|
||||
});
|
||||
|
||||
@@ -46,15 +46,15 @@ define([
|
||||
'useCapability'
|
||||
]
|
||||
);
|
||||
mockDomainObj.getId.andReturn(id);
|
||||
mockDomainObj.getModel.andReturn(model);
|
||||
mockDomainObj.hasCapability.andCallFake(function (c) {
|
||||
mockDomainObj.getId.and.returnValue(id);
|
||||
mockDomainObj.getModel.and.returnValue(model);
|
||||
mockDomainObj.hasCapability.and.callFake(function (c) {
|
||||
return !!(capabilities[c]);
|
||||
});
|
||||
mockDomainObj.getCapability.andCallFake(function (c) {
|
||||
mockDomainObj.getCapability.and.callFake(function (c) {
|
||||
return capabilities[c];
|
||||
});
|
||||
mockDomainObj.useCapability.andCallFake(function (c) {
|
||||
mockDomainObj.useCapability.and.callFake(function (c) {
|
||||
return capabilities[c] && capabilities[c].invoke();
|
||||
});
|
||||
return mockDomainObj;
|
||||
@@ -68,11 +68,11 @@ define([
|
||||
|
||||
mockGestureHandle = jasmine.createSpyObj('gestures', ['destroy']);
|
||||
|
||||
mockGestureService.attachGestures.andReturn(mockGestureHandle);
|
||||
mockGestureService.attachGestures.and.returnValue(mockGestureHandle);
|
||||
|
||||
mockMutation = jasmine.createSpyObj('mutation', ['listen']);
|
||||
mockUnlisten = jasmine.createSpy('unlisten');
|
||||
mockMutation.listen.andReturn(mockUnlisten);
|
||||
mockMutation.listen.and.returnValue(mockUnlisten);
|
||||
|
||||
testCapabilities = { mutation: mockMutation };
|
||||
|
||||
@@ -102,7 +102,7 @@ define([
|
||||
var mockStatus =
|
||||
jasmine.createSpyObj('status', ['listen', 'list']);
|
||||
|
||||
mockStatus.list.andReturn([]);
|
||||
mockStatus.list.and.returnValue([]);
|
||||
|
||||
return {
|
||||
context: jasmine.createSpyObj('context', ['getPath']),
|
||||
@@ -113,16 +113,6 @@ define([
|
||||
};
|
||||
}
|
||||
|
||||
function waitForCompositionCallback() {
|
||||
var calledBack = false;
|
||||
testCapabilities.composition.invoke().then(function () {
|
||||
calledBack = true;
|
||||
});
|
||||
waitsFor(function () {
|
||||
return calledBack;
|
||||
});
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
mockComposition = ['a', 'b', 'c'].map(function (id) {
|
||||
var testCaps = makeGenericCapabilities(),
|
||||
@@ -130,7 +120,7 @@ define([
|
||||
makeMockDomainObject(id, {}, testCaps);
|
||||
|
||||
testCaps.context.getPath
|
||||
.andReturn([mockDomainObject, mockChild]);
|
||||
.and.returnValue([mockDomainObject, mockChild]);
|
||||
|
||||
return mockChild;
|
||||
});
|
||||
@@ -138,10 +128,10 @@ define([
|
||||
testCapabilities.composition =
|
||||
jasmine.createSpyObj('composition', ['invoke']);
|
||||
testCapabilities.composition.invoke
|
||||
.andReturn(Promise.resolve(mockComposition));
|
||||
.and.returnValue(Promise.resolve(mockComposition));
|
||||
|
||||
treeView.model(mockDomainObject);
|
||||
waitForCompositionCallback();
|
||||
return testCapabilities.composition.invoke();
|
||||
});
|
||||
|
||||
it("adds one node per composition element", function () {
|
||||
@@ -158,8 +148,8 @@ define([
|
||||
beforeEach(function () {
|
||||
mockComposition.pop();
|
||||
testCapabilities.mutation.listen
|
||||
.mostRecentCall.args[0](mockDomainObject.getModel());
|
||||
waitForCompositionCallback();
|
||||
.calls.mostRecent().args[0](mockDomainObject.getModel());
|
||||
return testCapabilities.composition.invoke();
|
||||
});
|
||||
|
||||
it("continues to show one node per composition element", function () {
|
||||
@@ -219,38 +209,30 @@ define([
|
||||
mockNewChild =
|
||||
makeMockDomainObject('d', {}, newCapabilities),
|
||||
mockGrandchild =
|
||||
makeMockDomainObject('gc', {}, gcCapabilities),
|
||||
calledBackInner = false;
|
||||
makeMockDomainObject('gc', {}, gcCapabilities);
|
||||
|
||||
newCapabilities.composition =
|
||||
jasmine.createSpyObj('composition', ['invoke']);
|
||||
newCapabilities.composition.invoke
|
||||
.andReturn(Promise.resolve([mockGrandchild]));
|
||||
.and.returnValue(Promise.resolve([mockGrandchild]));
|
||||
mockComposition.push(mockNewChild);
|
||||
|
||||
newCapabilities.context.getPath.andReturn([
|
||||
newCapabilities.context.getPath.and.returnValue([
|
||||
mockDomainObject,
|
||||
mockNewChild
|
||||
]);
|
||||
gcCapabilities.context.getPath.andReturn([
|
||||
gcCapabilities.context.getPath.and.returnValue([
|
||||
mockDomainObject,
|
||||
mockNewChild,
|
||||
mockGrandchild
|
||||
]);
|
||||
|
||||
testCapabilities.mutation.listen
|
||||
.mostRecentCall.args[0](mockDomainObject);
|
||||
waitForCompositionCallback();
|
||||
runs(function () {
|
||||
// Select the innermost object to force expansion,
|
||||
// such that we can verify the subtree is present.
|
||||
.calls.mostRecent().args[0](mockDomainObject);
|
||||
|
||||
return testCapabilities.composition.invoke().then(function () {
|
||||
treeView.value(mockGrandchild);
|
||||
newCapabilities.composition.invoke().then(function () {
|
||||
calledBackInner = true;
|
||||
});
|
||||
});
|
||||
waitsFor(function () {
|
||||
return calledBackInner;
|
||||
return newCapabilities.composition.invoke();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -268,8 +250,8 @@ define([
|
||||
|
||||
testStatuses = ['foo'];
|
||||
|
||||
mockStatus.list.andReturn(testStatuses);
|
||||
mockStatus.listen.mostRecentCall.args[0](testStatuses);
|
||||
mockStatus.list.and.returnValue(testStatuses);
|
||||
mockStatus.listen.calls.mostRecent().args[0](testStatuses);
|
||||
});
|
||||
|
||||
it("reflects the status change in the tree", function () {
|
||||
|
||||
Reference in New Issue
Block a user