Viewing File: /usr/local/cpanel/base/frontend/jupiter/site-monitor/directives/docrootDirective.spec.js
/*
# site-monitor/directives/docroot.spec.js Copyright(c) 2021 cPanel, L.L.C.
# All rights reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
*/
/* global define: false, describe: false, it: false, module: false, inject: false, beforeEach: false, expect: false */
define(["angular",
"jquery",
"cjt/core",
"ngResource",
"ngMocks",
"site-monitor/directives/docrootDirective"], function(angular) {
"use strict";
describe("<docroot>", function() {
var $scope, $rootScope, $compile;
var _page = {
"banana": "1",
};
var _fileManApp = {
target: "theater",
url: "muppets.com",
canOpen: true,
};
beforeEach(function() {
module("directives/docrootDirective.phtml");
module("cpanel.siteMonitor.docrootDirective", function($provide) {
$provide.value("PAGE", _page);
});
});
beforeEach(inject(function(_$rootScope_, _$compile_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
}));
/**
* Create a directive from the template
*
* @param {Object} scope - initial scope for the directive
* @returns
*/
function compileDirective(scope) {
$scope = $rootScope.$new();
angular.extend($scope, {}, scope);
var $directive = $compile(
"<docroot \
id=\"{{id}}\" \
docroot=\"{{docroot}}\" \
homedir=\"{{homedir}}\"> \
</docroot>")($scope);
$scope.$digest();
return $directive;
}
it("creates id's for elements", function() {
var scope = {
id: "docroot-1234",
docroot: "/mybigfancyhomedir/a/sub/directory",
homedir: "/mybigfancyhomedir",
};
var $directive = compileDirective(scope);
expect($directive.attr("id")).toBe(scope.id);
var span = $directive.find("#" + scope.id + "_nolink");
expect(span.length).toBe(1);
expect(span.attr("title")).toMatch($scope.docroot);
// Activate the file manager portion.
_page.fileManager = _fileManApp;
_page.APP_NAME = "cpanel";
$directive = compileDirective(scope);
var link = $directive.find("#" + scope.id + "_link");
expect(link.length).toBe(1);
expect(link.attr("target")).toBe(_fileManApp.target);
expect(link.attr("href")).toMatch(_fileManApp.url);
expect(link.attr("title")).toMatch($scope.docroot);
});
it("creates title with [fullPath]", function() {
var scope = {
id: "docroot-1234",
docroot: "/mybigfancyhomedir/a/sub/directory",
homedir: "/mybigfancyhomedir",
};
_page.fileManager = null;
_page.APP_NAME = "banana";
var $directive = compileDirective(scope);
var span = $directive.find("#" + scope.id + "_nolink");
expect(span.attr("title")).toBe($scope.docroot);
// Activate the file manager portion.
_page.fileManager = _fileManApp;
_page.APP_NAME = "cpanel";
$directive = compileDirective(scope);
var link = $directive.find("#" + scope.id + "_link");
expect(link.attr("title")).toBe($scope.docroot);
expect(link.attr("href")).toMatch(encodeURIComponent($scope.docroot));
});
it("displays with just the partial path", function() {
var scope = {
id: "docroot-1234",
docroot: "/mybigfancyhomedir/a/sub/directory",
homedir: "/mybigfancyhomedir",
};
var $directive = compileDirective(scope);
expect($directive.text()).toMatch("a/sub/directory");
});
it("displays with a root path", function() {
var scope = {
id: "docroot-1234",
docroot: "/",
homedir: "/mybigfancyhomedir",
};
var $directive = compileDirective(scope);
expect($directive.text()).toMatch("/");
});
});
});
Back to Directory
File Manager