<commit_before>﻿/// <reference path="../../../../lib/angular/1.1.5/angular.js" />
/// <reference path="../../../lib/angular/angular-mocks.js" />
/// <reference path="../../../../src/app.js" />
/// <reference path="../../../../src/views/templates/edit.controller.js" />

(function() {
    "use strict";

    describe("templates editor controller",
        function() {


            var scope,
                controllerFactory,
                q,
                ace,
                controller,
                nada = function() {};

            // UNCOMMENT TO RUN WITH RESHARPERS TESTRUNNER FOR JS
            //beforeEach(function() {
            //    angular.module('umbraco.filters', []);
            //    angular.module('umbraco.directives', []);
            //    angular.module('umbraco.resources', []);
            //    angular.module('umbraco.services', []);
            //    angular.module('umbraco.packages', []);
            //    angular.module('umbraco.views', []);
            //    angular.module('ngCookies', []);
            //    angular.module('ngSanitize', []);
            //    angular.module('ngMobile', []);
            //    angular.module('tmh.dynamicLocale', []);
            //    angular.module('ngFileUpload', []);
            //    angular.module('LocalStorageModule', []);
            //});

            beforeEach(module("umbraco"));

            beforeEach(inject(function($controller, $rootScope, $q) {

                controllerFactory = $controller;
                scope = $rootScope.$new();
                q = $q;

                ace = {
                    on: function(){}
                }

                controller = createController();
                scope.$digest();
                controller.aceOption.onLoad(ace);

            }));

            function resolvedPromise(obj) {
                return function() {
                    var def = q.defer();
                    def.resolve(obj);
                    return def.promise;
                }
            }

            function createController() {
                return controllerFactory("Umbraco.Editors.Templates.EditController",
                {
                    $scope: scope,
                    $routeParams: {},
                    templateResource: {
                        getById: resolvedPromise({})
                    },
                    assetsService: {
                        loadCss: function() {}
                    },
                    notificationsService: {
                    },
                    editorState: {
                        set: function(){}
                    },
                    navigationService: {
                        syncTree: resolvedPromise({})
                    },
                    appState: {
                        getSectionState : function() { return {}; }
                    },
                    macroService: {}
                });
            }

            it("has ace editor",
                function () {
                    expect(controller.editor).toBe(ace);
                });

            it("sets masterpage on template",
                function () {
                    controller.setLayout = function() {};

                    controller.openOrganizeOverlay();
                    controller.organizeOverlay.submit({
                        masterPage: {
                            alias: "NewMasterPage"
                        }
                    });
                    expect(controller.template.masterPageAlias).toBe("NewMasterPage");
                });

            it("changes layout value when masterpage is selected",
                function() {
                    var newTemplate;
                    ace.clearSelection = nada;
                    ace.navigateFileStart = nada;
                    ace.getValue = function () {
                        return "@{ Layout = null; }";
                    }
                    ace.setValue = function (value) {
                        newTemplate = value;
                    }

                    controller.openOrganizeOverlay();
                    controller.organizeOverlay.submit({
                        masterPage: {
                            alias: "NewMasterPage"
                        }
                    });
                    expect(newTemplate).toBe("@{ Layout = \"NewMasterPage.cshtml\"; }");
                });
        });

}());<commit_msg>fix unit tests<commit_after>﻿/// <reference path="../../../../lib/angular/1.1.5/angular.js" />
/// <reference path="../../../lib/angular/angular-mocks.js" />
/// <reference path="../../../../src/app.js" />
/// <reference path="../../../../src/views/templates/edit.controller.js" />

(function() {
    "use strict";

    describe("templates editor controller",
        function() {


            var scope,
                controllerFactory,
                q,
                ace,
                controller,
                nada = function() {};

            // UNCOMMENT TO RUN WITH RESHARPERS TESTRUNNER FOR JS
            //beforeEach(function() {
            //    angular.module('umbraco.filters', []);
            //    angular.module('umbraco.directives', []);
            //    angular.module('umbraco.resources', []);
            //    angular.module('umbraco.services', []);
            //    angular.module('umbraco.packages', []);
            //    angular.module('umbraco.views', []);
            //    angular.module('ngCookies', []);
            //    angular.module('ngSanitize', []);
            //    angular.module('ngMobile', []);
            //    angular.module('tmh.dynamicLocale', []);
            //    angular.module('ngFileUpload', []);
            //    angular.module('LocalStorageModule', []);
            //});

            beforeEach(module("umbraco"));

            beforeEach(inject(function($controller, $rootScope, $q) {

                controllerFactory = $controller;
                scope = $rootScope.$new();
                q = $q;

                ace = {
                    on: function(){},
                    navigateFileEnd: function() {},
                    getCursorPosition: function() {},
                    getValue: function() {},
                    setValue: function() {},
                    clearSelection: function() {},
                    navigateFileStart: function() {}
                };

                controller = createController();
                scope.$digest();
                controller.aceOption.onLoad(ace);

            }));

            function resolvedPromise(obj) {
                return function() {
                    var def = q.defer();
                    def.resolve(obj);
                    return def.promise;
                }
            }

            function createController() {
                return controllerFactory("Umbraco.Editors.Templates.EditController",
                {
                    $scope: scope,
                    $routeParams: {},
                    templateResource: {
                        getById: resolvedPromise({}),
                        getAll: resolvedPromise({})
                    },
                    assetsService: {
                        loadCss: function() {}
                    },
                    notificationsService: {
                    },
                    editorState: {
                        set: function(){}
                    },
                    navigationService: {
                        syncTree: resolvedPromise({})
                    },
                    appState: {
                        getSectionState : function() { return {}; }
                    },
                    macroService: {}
                });
            }

            it("has ace editor", function () {
                expect(controller.editor).toBe(ace);
            });

            it("sets masterpage on template", function () {
                controller.setLayout = function() {};

                controller.openMasterTemplateOverlay();
                controller.masterTemplateOverlay.submit({
                    selectedItem: {
                        alias: "NewMasterPage"
                    }
                });
                expect(controller.template.masterTemplateAlias).toBe("NewMasterPage");
            });

            it("changes layout value when masterpage is selected", function() {
                var newTemplate;
                ace.clearSelection = nada;
                ace.navigateFileStart = nada;
                ace.getValue = function () {
                    return "@{ Layout = null; }";
                }
                ace.setValue = function (value) {
                    newTemplate = value;
                }

                controller.openMasterTemplateOverlay();
                controller.masterTemplateOverlay.submit({
                    selectedItem: {
                        alias: "NewMasterPage"
                    }
                });
                expect(newTemplate).toBe("@{ Layout = \"NewMasterPage.cshtml\"; }");
            });
            
        });

}());
{'fraction_non_alphanumeric': 0.13065381666849196, 'fraction_numerical': 0.000657102179388895, 'mean_word_length': 1.0420393559928445, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3113842', 'n_tokens_mistral': 2108, 'n_tokens_neox': 1921, 'n_words': 310}