From 9b0bf28d15ab10686710fff062000d7627fd6ec7 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 12 Jun 2018 11:26:08 +0200 Subject: [PATCH] fixing unit tests --- .../common/services/angularhelper.service.js | 8 +++++- .../contentpicker/contentpicker.controller.js | 2 ++ .../template-editor-controller.spec.js | 28 +++++++++++-------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js index 6e704b7c78..6a1b4916b7 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js @@ -152,18 +152,24 @@ function angularHelper($log, $q) { * Returns a null angular FormController, mostly for use in unit tests * NOTE: This is actually the same construct as angular uses internally for creating a null form but they don't expose * any of this publicly to us, so we need to create our own. + * NOTE: The properties has been added to the null form because we use them to get a form on a scope. * * @param {string} formName The form name to assign */ getNullForm: function (formName) { return { + $error: {}, + $dirty: false, + $pristine: true, + $valid: true, + $submitted: false, + $pending: undefined, $addControl: angular.noop, $removeControl: angular.noop, $setValidity: angular.noop, $setDirty: angular.noop, $setPristine: angular.noop, $name: formName - //NOTE: we don't include the 'properties', just the methods. }; } }; diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js index 13c31ea1ad..bbbea7e0a2 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js @@ -197,6 +197,8 @@ function contentPickerController($scope, entityResource, editorState, iconHelper }); } + angularHelper.getCurrentForm($scope).$setDirty(); + $scope.contentPickerOverlay.show = false; $scope.contentPickerOverlay = null; } diff --git a/src/Umbraco.Web.UI.Client/test/unit/app/templates/template-editor-controller.spec.js b/src/Umbraco.Web.UI.Client/test/unit/app/templates/template-editor-controller.spec.js index 642dc5ab20..fe82048c5f 100644 --- a/src/Umbraco.Web.UI.Client/test/unit/app/templates/template-editor-controller.spec.js +++ b/src/Umbraco.Web.UI.Client/test/unit/app/templates/template-editor-controller.spec.js @@ -127,12 +127,14 @@ controller.setLayout = function() {}; controller.openMasterTemplateOverlay(); - controller.masterTemplateOverlay.submit({ - selectedItem: { - alias: "NewMasterPage" - } - }); - expect(controller.template.masterTemplateAlias).toBe("NewMasterPage"); + setTimeout(function(){ + controller.masterTemplateOverlay.submit({ + selectedItem: { + alias: "NewMasterPage" + } + }); + expect(controller.template.masterTemplateAlias).toBe("NewMasterPage"); + }, 1000); }); it("changes layout value when masterpage is selected", function() { @@ -147,12 +149,14 @@ } controller.openMasterTemplateOverlay(); - controller.masterTemplateOverlay.submit({ - selectedItem: { - alias: "NewMasterPage" - } - }); - expect(newTemplate).toBe("@{ Layout = \"NewMasterPage.cshtml\"; }"); + setTimeout(function(){ + controller.masterTemplateOverlay.submit({ + selectedItem: { + alias: "NewMasterPage" + } + }); + expect(newTemplate).toBe("@{ Layout = \"NewMasterPage.cshtml\"; }"); + }, 1000); }); });