From eda1f23df9ca36f10c83332ed8c4e1cd8300153f Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 26 May 2016 11:35:56 -0700 Subject: [PATCH 1/4] [Edit Mode] #629 rewriting disabled tests --- .../edit/test/actions/CancelActionSpec.js | 109 +++++++++++++----- .../test/ConductorRepresenterSpec.js | 2 +- 2 files changed, 79 insertions(+), 32 deletions(-) diff --git a/platform/commonUI/edit/test/actions/CancelActionSpec.js b/platform/commonUI/edit/test/actions/CancelActionSpec.js index 411fdb1659..b83fbdab2b 100644 --- a/platform/commonUI/edit/test/actions/CancelActionSpec.js +++ b/platform/commonUI/edit/test/actions/CancelActionSpec.js @@ -24,12 +24,11 @@ define( ["../../src/actions/CancelAction"], function (CancelAction) { - //TODO: Disabled for NEM Beta - xdescribe("The Cancel action", function () { - var mockLocation, - mockDomainObject, - mockEditorCapability, - mockUrlService, + describe("The Cancel action", function () { + var mockDomainObject, + mockParentObject, + capabilities = {}, + parentCapabilities = {}, actionContext, action; @@ -42,61 +41,109 @@ define( } beforeEach(function () { - mockLocation = jasmine.createSpyObj( - "$location", - ["path"] - ); mockDomainObject = jasmine.createSpyObj( "domainObject", - ["getCapability", "hasCapability"] + [ + "getCapability", + "hasCapability", + "getModel" + ] ); - mockEditorCapability = jasmine.createSpyObj( + mockDomainObject.getModel.andReturn({}); + + mockParentObject = jasmine.createSpyObj( + "parentObject", + [ + "getCapability" + ] + ); + mockParentObject.getCapability.andCallFake(function (name) { + return parentCapabilities[name]; + }); + + capabilities.editor = jasmine.createSpyObj( "editor", - ["save", "cancel"] + ["save", "cancel", "isEditContextRoot"] ); - mockUrlService = jasmine.createSpyObj( - "urlService", - ["urlForLocation"] + capabilities.action = jasmine.createSpyObj( + "actionCapability", + [ + "perform" + ] + ); + capabilities.location = jasmine.createSpyObj( + "locationCapability", + [ + "getOriginal" + ] + ); + capabilities.location.getOriginal.andReturn(mockPromise(mockDomainObject)); + capabilities.context = jasmine.createSpyObj( + "contextCapability", + [ + "getParent" + ] + ); + capabilities.context.getParent.andReturn(mockParentObject); + + parentCapabilities.action = jasmine.createSpyObj( + "actionCapability", + [ + "perform" + ] ); actionContext = { domainObject: mockDomainObject }; - mockDomainObject.hasCapability.andReturn(true); - mockDomainObject.getCapability.andReturn(mockEditorCapability); - mockEditorCapability.cancel.andReturn(mockPromise(true)); + mockDomainObject.getCapability.andCallFake(function (name) { + return capabilities[name]; + }); - action = new CancelAction(mockLocation, mockUrlService, actionContext); + mockDomainObject.hasCapability.andCallFake(function (name) { + return !!capabilities[name]; + }); + + capabilities.editor.cancel.andReturn(mockPromise(true)); + + action = new CancelAction(actionContext); }); - it("only applies to domain object with an editor capability", function () { + it("only applies to domain object that is being edited", function () { + capabilities.editor.isEditContextRoot.andReturn(true); expect(CancelAction.appliesTo(actionContext)).toBeTruthy(); expect(mockDomainObject.hasCapability).toHaveBeenCalledWith("editor"); + capabilities.editor.isEditContextRoot.andReturn(false); + expect(CancelAction.appliesTo(actionContext)).toBeFalsy(); + mockDomainObject.hasCapability.andReturn(false); - mockDomainObject.getCapability.andReturn(undefined); expect(CancelAction.appliesTo(actionContext)).toBeFalsy(); }); - it("invokes the editor capability's save functionality when performed", function () { - // Verify precondition - expect(mockEditorCapability.cancel).not.toHaveBeenCalled(); + it("invokes the editor capability's cancel functionality when" + + " performed", function () { action.perform(); // Should have called cancel - expect(mockEditorCapability.cancel).toHaveBeenCalled(); + expect(capabilities.editor.cancel).toHaveBeenCalled(); // Definitely shouldn't call save! - expect(mockEditorCapability.save).not.toHaveBeenCalled(); + expect(capabilities.editor.save).not.toHaveBeenCalled(); }); - it("returns to browse when performed", function () { + it("navigates to object if existing", function () { + mockDomainObject.getModel.andReturn({persisted: 1}); action.perform(); - expect(mockLocation.path).toHaveBeenCalledWith( - mockUrlService.urlForLocation("browse", mockDomainObject) - ); + expect(capabilities.action.perform).toHaveBeenCalledWith("navigate"); + }); + + it("navigates to parent if new", function () { + mockDomainObject.getModel.andReturn({persisted: undefined}); + action.perform(); + expect(parentCapabilities.action.perform).toHaveBeenCalledWith("navigate"); }); }); } diff --git a/platform/features/conductor/test/ConductorRepresenterSpec.js b/platform/features/conductor/test/ConductorRepresenterSpec.js index 83d37fb8a6..bd60b303e1 100644 --- a/platform/features/conductor/test/ConductorRepresenterSpec.js +++ b/platform/features/conductor/test/ConductorRepresenterSpec.js @@ -42,7 +42,7 @@ define( 'parent' ]; - xdescribe("ConductorRepresenter", function () { + describe("ConductorRepresenter", function () { var mockThrottle, mockConductorService, mockCompile, From f30174185261c6adf4515ac3debe4d86e8061ed4 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 26 May 2016 11:42:15 -0700 Subject: [PATCH 2/4] [Edit Mode] #629 restored disabled tests for DropGesture. Removed extraneous argument to broadcast function --- .../src/gestures/DropGesture.js | 3 +-- .../test/gestures/DropGestureSpec.js | 20 +------------------ 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/platform/representation/src/gestures/DropGesture.js b/platform/representation/src/gestures/DropGesture.js index 966618d88c..8da98b38a7 100644 --- a/platform/representation/src/gestures/DropGesture.js +++ b/platform/representation/src/gestures/DropGesture.js @@ -61,8 +61,7 @@ define( { x: event.pageX - rect.left, y: event.pageY - rect.top - }, - domainObject + } ); } } diff --git a/platform/representation/test/gestures/DropGestureSpec.js b/platform/representation/test/gestures/DropGestureSpec.js index 79ed9d1139..f8ed7c80da 100644 --- a/platform/representation/test/gestures/DropGestureSpec.js +++ b/platform/representation/test/gestures/DropGestureSpec.js @@ -34,8 +34,7 @@ define( TEST_ID = "test-id", DROP_ID = "drop-id"; - //TODO: Disabled for NEM Beta - xdescribe("The drop gesture", function () { + describe("The drop gesture", function () { var mockDndService, mockQ, mockElement, @@ -144,23 +143,6 @@ define( expect(mockCompose.perform).toHaveBeenCalled(); }); - - it("does not invoke compose on drop in browse mode for non-folders", function () { - // Set the mockDomainObject to not have the editor capability - mockDomainObject.hasCapability.andReturn(false); - // Set the mockDomainObject to not have a type of folder - mockDomainObject.getModel.andReturn({type: 'notAFolder'}); - - callbacks.dragover(mockEvent); - expect(mockAction.getActions).toHaveBeenCalledWith({ - key: 'compose', - selectedObject: mockDraggedObject - }); - callbacks.drop(mockEvent); - expect(mockCompose.perform).not.toHaveBeenCalled(); - }); - - it("invokes compose on drop in browse mode for folders", function () { // Set the mockDomainObject to not have the editor capability mockDomainObject.hasCapability.andReturn(false); From 165e158f3770a979f5d0818888df3cbb926bacdb Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 26 May 2016 11:44:43 -0700 Subject: [PATCH 3/4] [Edit Mode] #629 Removed redundant test from DomainObjectProviderSpec --- platform/core/test/objects/DomainObjectProviderSpec.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/platform/core/test/objects/DomainObjectProviderSpec.js b/platform/core/test/objects/DomainObjectProviderSpec.js index c8450551f4..4e60f19645 100644 --- a/platform/core/test/objects/DomainObjectProviderSpec.js +++ b/platform/core/test/objects/DomainObjectProviderSpec.js @@ -82,16 +82,6 @@ define( expect(result.a.getModel()).toEqual(model); }); - //TODO: Disabled for NEM Beta - xit("provides a new, fully constituted domain object for a" + - " provided model", function () { - var model = { someKey: "some value"}, - result; - result = provider.newObject("a", model); - expect(result.getId()).toEqual("a"); - expect(result.getModel()).toEqual(model); - }); - }); } ); From 7fc2fcfa07afbaff5eb1fd7cfb4a7649957f80ed Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 26 May 2016 11:55:13 -0700 Subject: [PATCH 4/4] [Edit Mode] #629 Rewrote obsolete DomainColumn tests --- .../features/table/test/DomainColumnSpec.js | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/platform/features/table/test/DomainColumnSpec.js b/platform/features/table/test/DomainColumnSpec.js index e707c8dd0b..516c32deae 100644 --- a/platform/features/table/test/DomainColumnSpec.js +++ b/platform/features/table/test/DomainColumnSpec.js @@ -30,23 +30,21 @@ define( var TEST_DOMAIN_VALUE = "some formatted domain value"; describe("A domain column", function () { - var mockDataSet, + var mockDatum, testMetadata, mockFormatter, column; beforeEach(function () { - mockDataSet = jasmine.createSpyObj( - "data", - ["getDomainValue"] - ); + mockFormatter = jasmine.createSpyObj( "formatter", ["formatDomainValue", "formatRangeValue"] ); testMetadata = { key: "testKey", - name: "Test Name" + name: "Test Name", + format: "Test Format" }; mockFormatter.formatDomainValue.andReturn(TEST_DOMAIN_VALUE); @@ -57,24 +55,24 @@ define( expect(column.getTitle()).toEqual("Test Name"); }); - xit("looks up data from a data set", function () { - column.getValue(undefined, mockDataSet, 42); - expect(mockDataSet.getDomainValue) - .toHaveBeenCalledWith(42, "testKey"); - }); + describe("when given a datum", function () { + beforeEach(function () { + mockDatum = { + testKey: "testKeyValue" + }; + }); - xit("formats domain values as time", function () { - mockDataSet.getDomainValue.andReturn(402513731000); + it("looks up data from the given datum", function () { + expect(column.getValue(undefined, mockDatum)) + .toEqual({ text: TEST_DOMAIN_VALUE }); + }); - // Should have just given the value the formatter gave - expect(column.getValue(undefined, mockDataSet, 42).text) - .toEqual(TEST_DOMAIN_VALUE); + it("uses formatter to format domain values as requested", function () { + column.getValue(undefined, mockDatum); + expect(mockFormatter.formatDomainValue) + .toHaveBeenCalledWith("testKeyValue", "Test Format"); + }); - // Make sure that service interactions were as expected - expect(mockFormatter.formatDomainValue) - .toHaveBeenCalledWith(402513731000); - expect(mockFormatter.formatRangeValue) - .not.toHaveBeenCalled(); }); });