Datasets:

Modalities:
Text
Formats:
json
Languages:
code
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 3,528 Bytes
eb67da4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*global RequisitionNode:true */

/**
* @author Alejandro Galue <agalue@opennms.org>
* @copyright 2014 The OpenNMS Group, Inc.
*/

'use strict';

const angular = require('angular-js');
const _ = require('underscore-js');
require('angular-mocks');
require('../../../../../src/main/assets/js/apps/onms-requisitions/requisitions');

const RequisitionNode = require('../../../../../src/main/assets/js/apps/onms-requisitions/lib/scripts/model/RequisitionNode');

// Initialize testing environment

var controllerFactory, scope, $q, mockModal = {}, mockGrowl = {}, mockRequisitionsService = {};

var foreignSource = 'test-requisition';
var foreignId = '1001';
var categories = ['Production', 'Testing', 'Server', 'Storage'];
var locations = ['Default'];
var node = new RequisitionNode(foreignSource, { 'foreign-id': foreignId });
var requisition = { foreignSource: foreignSource, nodes: [{foreignId: '01'},{foreignId: '02'}] };

function createController() {
  return controllerFactory('NodeController', {
    $scope: scope,
    $routeParams: { 'foreignSource': foreignSource, 'foreignId': foreignId },
    $modal: mockModal,
    RequisitionsService: mockRequisitionsService,
    growl: mockGrowl
  });
}

beforeEach(angular.mock.module('onms-requisitions', function($provide) {
  $provide.value('$log', console);
}));

beforeEach(angular.mock.inject(function($rootScope, $controller, _$q_) {
  scope = $rootScope.$new();
  controllerFactory = $controller;
  $q = _$q_;
}));

beforeEach(function() {
  mockRequisitionsService.getTiming = jasmine.createSpy('getTiming');
  mockRequisitionsService.getNode = jasmine.createSpy('getNode');
  mockRequisitionsService.getRequisition = jasmine.createSpy('getRequisition');
  mockRequisitionsService.getAvailableCategories = jasmine.createSpy('getAvailableCategories');
  mockRequisitionsService.getAvailableLocations = jasmine.createSpy('getAvailableLocations');
  var nodeDefer = $q.defer();
  nodeDefer.resolve(node);
  mockRequisitionsService.getNode.and.returnValue(nodeDefer.promise);
  var categoriesDefer = $q.defer();
  categoriesDefer.resolve(categories);
  mockRequisitionsService.getAvailableCategories.and.returnValue(categoriesDefer.promise);
  var locationsDefer = $q.defer();
  locationsDefer.resolve(locations);
  mockRequisitionsService.getAvailableLocations.and.returnValue(locationsDefer.promise);
  var reqDefer = $q.defer();
  reqDefer.resolve(requisition);
  mockRequisitionsService.getRequisition.and.returnValue(reqDefer.promise);
  mockRequisitionsService.getTiming.and.returnValue({ isRunning: false });

  mockGrowl = {
    warning: function(msg) { console.warn(msg); },
    error: function(msg) { console.error(msg); },
    info: function(msg) { console.info(msg); },
    success: function(msg) { console.info(msg); }
  };
});

test('Controller: NodeController: test controller', function() {
  createController();
  scope.$digest();
  expect(mockRequisitionsService.getAvailableCategories).toHaveBeenCalled();
  expect(mockRequisitionsService.getNode).toHaveBeenCalledWith(foreignSource, foreignId);
  expect(scope.foreignSource).toBe(foreignSource);
  expect(scope.foreignId).toBe(foreignId);
  expect(scope.availableCategories.length).toBe(4);
  expect(scope.foreignIdBlackList).toEqual(['01', '02']);

  expect(scope.getAvailableCategories()).toEqual(categories);
  scope.node.categories.push({name: 'Production'});
  expect(scope.getAvailableCategories()).toEqual(['Testing', 'Server', 'Storage']);
  expect(scope.availableLocations).toEqual(locations);
});