Viewing File: /usr/local/cpanel/base/frontend/jupiter/site-monitor/directives/monitorsDirective.spec.js
/*
# site-monitor/directives/siteItemDirective.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/monitorsDirective"], function(angular, $) {
"use strict";
describe("<monitors>", function() {
var $scope, $rootScope, $compile;
beforeEach(function() {
module("libraries/cjt2/directives/spinner.phtml");
module("directives/monitorDirective.phtml");
module("directives/monitorsDirective.phtml");
module("cpanel.siteMonitor.monitorsDirective");
});
beforeEach(inject(function(_$rootScope_, _$compile_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
}));
/**
* Compile the directive.
*
* @param {Object} scope - initial scope to set when building the directive
* @returns
*/
function compileDirective(scope) {
$scope = $rootScope.$new();
angular.extend($scope, {}, scope);
var $directive = $compile(
"<div> \
<monitors id=\"monitors\" data=\"site\"> \
</monitors> \
</div>")($scope);
$scope.$digest();
return $directive;
}
it("should generate none message if there are not monitors on the site and the fetch succeeded.", function() {
var $directive = compileDirective({
site: {
monitors: [],
fetchFailed: false,
}
});
var span = $directive.find("span span");
expect(span.text()).toMatch('None');
});
it("should generate error message if there are not monitors on the site but the fetch failed.", function() {
var $directive = compileDirective({
site: {
monitors: [],
fetchFailed: true,
}
});
var span = $directive.find("span span");
expect(span.text()).toMatch('Error Loading');
});
it("should generate one row when there is one monitor on the site", function() {
var $directive = compileDirective({
site: {
monitors: [
{
name: "Gobo",
protocol: "https",
domain: "fraggle-rock.com",
port: 443,
path: "characters/gobo",
url: function() { return "https://fraggle-rock.com/characters/gobo" },
}
],
}
});
expect($directive.find("ul").children().length).toBe(1);
var li = $directive.find("li:first-child");
expect(li.text()).toMatch('https://fraggle-rock.com/characters/gobo');
$scope.site.monitors[0].port = 4443;
$scope.$digest();
li = $directive.find("li:first-child");
expect(li.text()).toMatch('https://fraggle-rock.com:4443/characters/gobo');
$scope.site.monitors[0].port = 443;
$scope.site.monitors[0].path = ''
$scope.$digest();
li = $directive.find("li:first-child");
expect(li.text()).toMatch('https://fraggle-rock.com');
});
it("should generate two rows when there are two monitors on the site", function() {
var $directive = compileDirective({
site: {
monitors: [
{
name: "Gobo",
protocol: "https",
domain: "fraggle-rock.com",
port: 443,
path: "characters/gobo",
url: function() { return "https://fraggle-rock.com/characters/gobo" },
},
{
name: "Kermit",
protocol: "https",
domain: "muppets.com",
port: 443,
path: "characters/kermit",
url: function() { return "https://muppets.com/characters/kermit" },
}
],
}
});
expect($directive.find("ul").children().length).toBe(2);
var li1 = $directive.find("li:first-child");
expect(li1.text()).toMatch('https://fraggle-rock.com/characters/gobo');
var li2 = $directive.find("li:last-child");
expect(li2.text()).toMatch('https://muppets.com/characters/kermit');
});
});
});
Back to Directory
File Manager