[Common UI] Continue filling in Browse specs

Continue filling in specs for scripts introduced as part
of bundle platform/commonUI/browse, which is responsible
for browse mode. WTD-574.
This commit is contained in:
Victor Woeltjen 2014-11-25 20:26:37 -08:00
parent 528f6bdf56
commit 48ff8c4c03
5 changed files with 311 additions and 2 deletions

View File

@ -9,7 +9,65 @@ define(
"use strict";
describe("The create action provider", function () {
var mockTypeService,
mockDialogService,
mockCreationService,
provider;
function createMockType(name) {
var mockType = jasmine.createSpyObj(
"type" + name,
[
"getKey",
"getGlyph",
"getName",
"getDescription",
"getProperties",
"getInitialModel"
]
);
mockType.getName.andReturn(name);
return mockType;
}
beforeEach(function () {
mockTypeService = jasmine.createSpyObj(
"typeService",
[ "listTypes" ]
);
mockDialogService = jasmine.createSpyObj(
"dialogService",
[ "getUserInput" ]
);
mockCreationService = jasmine.createSpyObj(
"creationService",
[ "createObject" ]
);
mockTypeService.listTypes.andReturn(
[ "A", "B", "C" ].map(createMockType)
);
provider = new CreateActionProvider(
mockTypeService,
mockDialogService,
mockCreationService
);
});
it("exposes one create action per type", function () {
expect(provider.getActions({
key: "create",
domainObject: {}
}).length).toEqual(3);
});
it("exposes no non-create actions", function () {
expect(provider.getActions({
key: "somethingElse",
domainObject: {}
}).length).toEqual(0);
});
});
}
);

View File

@ -9,6 +9,100 @@ define(
"use strict";
describe("The create action", function () {
var mockType,
mockParent,
mockContext,
mockDialogService,
mockCreationService,
action;
function mockPromise(value) {
return {
then: function (callback) {
return mockPromise(callback(value));
}
};
}
beforeEach(function () {
mockType = jasmine.createSpyObj(
"type",
[
"getKey",
"getGlyph",
"getName",
"getDescription",
"getProperties",
"getInitialModel"
]
);
mockParent = jasmine.createSpyObj(
"domainObject",
[
"getId",
"getModel",
"getCapability"
]
);
mockContext = {
domainObject: mockParent
};
mockDialogService = jasmine.createSpyObj(
"dialogService",
[ "getUserInput" ]
);
mockCreationService = jasmine.createSpyObj(
"creationService",
[ "createObject" ]
);
mockType.getKey.andReturn("test");
mockType.getGlyph.andReturn("T");
mockType.getDescription.andReturn("a test type");
mockType.getName.andReturn("Test");
mockType.getProperties.andReturn([]);
mockType.getInitialModel.andReturn({});
mockDialogService.getUserInput.andReturn(mockPromise({}));
action = new CreateAction(
mockType,
mockParent,
mockContext,
mockDialogService,
mockCreationService
);
});
it("exposes type-appropriate metadata", function () {
var metadata = action.getMetadata();
expect(metadata.name).toEqual("Test");
expect(metadata.description).toEqual("a test type");
expect(metadata.glyph).toEqual("T");
});
it("invokes the creation service when performed", function () {
action.perform();
expect(mockCreationService.createObject).toHaveBeenCalledWith(
{ type: "test" },
mockParent
);
});
it("does not create an object if the user cancels", function () {
mockDialogService.getUserInput.andReturn({
then: function (callback, fail) {
fail();
}
});
action.perform();
expect(mockCreationService.createObject)
.not.toHaveBeenCalled();
});
});
}

View File

@ -5,11 +5,42 @@
*/
define(
["../../src/creation/CreateMenuController"],
function (CreateActionProvider) {
function (CreateMenuController) {
"use strict";
describe("The create menu controller", function () {
var mockScope,
mockActions,
controller;
beforeEach(function () {
mockActions = jasmine.createSpyObj("action", ["getActions"]);
mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
controller = new CreateMenuController(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 create actions", function () {
mockScope.action = mockActions;
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.createActions.length).toEqual(3);
// Make sure the right action type was requested
expect(mockActions.getActions).toHaveBeenCalledWith("create");
});
});
}
);

View File

@ -8,7 +8,89 @@ define(
function (CreateWizard) {
"use strict";
describe("The create action provider", function () {
describe("The create wizard", function () {
var mockType,
mockParent,
mockProperties,
wizard;
function createMockProperty(name) {
var mockProperty = jasmine.createSpyObj(
"property" + name,
[ "getDefinition", "getValue", "setValue" ]
);
mockProperty.getDefinition.andReturn({
name: name,
key: name.toLowerCase()
});
return mockProperty;
}
beforeEach(function () {
mockType = jasmine.createSpyObj(
"type",
[
"getKey",
"getGlyph",
"getName",
"getDescription",
"getProperties",
"getInitialModel"
]
);
mockParent = jasmine.createSpyObj(
"domainObject",
[
"getId",
"getModel",
"getCapability"
]
);
mockProperties = [ "A", "B", "C" ].map(createMockProperty);
mockType.getKey.andReturn("test");
mockType.getGlyph.andReturn("T");
mockType.getDescription.andReturn("a test type");
mockType.getName.andReturn("Test");
mockType.getInitialModel.andReturn({});
mockType.getProperties.andReturn(mockProperties);
wizard = new CreateWizard(
mockType,
mockParent
);
});
it("creates a form model with a Properties section", function () {
expect(wizard.getFormModel().sections[0].name)
.toEqual("Properties");
});
it("adds one row per defined type property", function () {
// Three properties were defined in the mock type
expect(wizard.getFormModel().sections[0].rows.length)
.toEqual(3);
});
it("interprets form data using type-defined properties", function () {
// Use key names from mock properties
wizard.createModel({
a: "field 0",
b: "field 1",
c: "field 2"
});
// Should have gotten a setValue call
mockProperties.forEach(function (mockProperty, i) {
expect(mockProperty.setValue).toHaveBeenCalledWith(
{ type: 'test' },
"field " + i
);
});
});
});
}

View File

@ -9,6 +9,50 @@ define(
"use strict";
describe("The navigate action", function () {
var mockNavigationService,
mockQ,
actionContext,
mockDomainObject,
action;
function mockPromise(value) {
return {
then: function (callback) {
return mockPromise(callback(value));
}
};
}
beforeEach(function () {
mockNavigationService = jasmine.createSpyObj(
"navigationService",
[ "setNavigation" ]
);
mockQ = { when: mockPromise };
mockDomainObject = jasmine.createSpyObj(
"domainObject",
[ "getId", "getModel", "getCapability" ]
);
action = new NavigateAction(
mockNavigationService,
mockQ,
{ domainObject: mockDomainObject }
);
});
it("invokes the navigate service when performed", function () {
action.perform();
expect(mockNavigationService.setNavigation)
.toHaveBeenCalledWith(mockDomainObject);
});
it("is only applicable when a domain object is in context", function () {
expect(NavigateAction.appliesTo({})).toBeFalsy();
expect(NavigateAction.appliesTo({
domainObject: mockDomainObject
})).toBeTruthy();
});
});
}