Test Setup Failed
Push — master ( 11cd9d...8453e3 )
by
unknown
03:59
created

ꞌ)   B

Complexity

Conditions 1
Paths 2

Size

Total Lines 82

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 2
dl 0
loc 82
rs 8.7769
nop 0

6 Functions

Rating   Name   Duplication   Size   Complexity  
A graphSpec.js ➔ ... ➔ isConnected 0 6 1
A graphSpec.js ➔ ... ➔ prepareGraph 0 6 1
A graphSpec.js ➔ ... ➔ it(ꞌshould add axises out from block centerꞌ) 0 23 1
A graphSpec.js ➔ ... ➔ it(ꞌshould add axises around blockꞌ) 0 18 1
A graphSpec.js ➔ ... ➔ it(ꞌshould finalize (setup connections) correctlyꞌ) 0 13 3
A graphSpec.js ➔ ... ➔ it(ꞌshould add axises at center between block pairsꞌ) 0 9 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
define(function(require) {
2
    'use strict';
3
4
    var Graph = require('oroworkflow/js/tools/path-finder/graph');
5
    var Rectangle = require('oroworkflow/js/tools/path-finder/rectangle');
6
    var directions = require('oroworkflow/js/tools/path-finder/directions');
7
    var _ = require('underscore');
8
9
    describe('oroworkflow/js/tools/path-finder/graph', function() {
10
        beforeEach(function prepareGraph() {
11
            var graph = new Graph();
12
            graph.outerRect = new Rectangle(0, 0, 500, 500);
13
            graph.rectangles.push(new Rectangle(100, 100, 100, 100));
14
            this.graph = graph;
15
        });
16
17
        function isConnected(node) {
18
            return node.connections[directions.TOP_TO_BOTTOM.id] ||
19
                node.connections[directions.BOTTOM_TO_TOP.id] ||
20
                node.connections[directions.LEFT_TO_RIGHT.id] ||
21
                node.connections[directions.RIGHT_TO_LEFT.id];
22
        }
23
24
        it('should add axises around block', function() {
25
            var graph = this.graph;
26
            var firstRect = graph.rectangles[0];
27
            graph.buildCornerAxises();
28
            expect(graph.baseAxises.length).toBe(4);
29
            expect(_.any(graph.baseAxises, function(axis) {
30
                return axis.a.x === firstRect.top;
31
            })).toBeTruthy();
32
            expect(_.any(graph.baseAxises, function(axis) {
33
                return axis.a.x === firstRect.bottom;
34
            })).toBeTruthy();
35
            expect(_.any(graph.baseAxises, function(axis) {
36
                return axis.a.y === firstRect.left;
37
            })).toBeTruthy();
38
            expect(_.any(graph.baseAxises, function(axis) {
39
                return axis.a.y === firstRect.right;
40
            })).toBeTruthy();
41
        });
42
43
        it('should add axises out from block center', function() {
44
            var graph = this.graph;
45
            var firstRect = graph.rectangles[0];
46
            var rectCenter = firstRect.center;
47
            graph.buildCenterAxises();
48
49
            var vX = _.countBy(graph.baseAxises, function(axis) {
50
                return axis.a.x;
51
            });
52
            var vY = _.countBy(graph.baseAxises, function(axis) {
53
                return axis.a.y;
54
            });
55
56
            expect(graph.baseAxises.length).toBe(8);
57
58
            expect(vX[rectCenter.x - 1]).toBe(2);
59
            expect(vX[rectCenter.x]).toBe(4);
60
            expect(vX[rectCenter.x + 1]).toBe(2);
61
62
            expect(vY[rectCenter.y - 1]).toBe(2);
63
            expect(vY[rectCenter.y]).toBe(4);
64
            expect(vY[rectCenter.y + 1]).toBe(2);
65
        });
66
67
        it('should add axises at center between block pairs', function() {
68
            var graph = this.graph;
69
            graph.rectangles.push(new Rectangle(300, 300, 100, 100));
70
            graph.buildCenterLinesBetweenNodes();
71
            expect(graph.baseAxises.length).toBe(2);
72
            expect(_.every(graph.baseAxises, function(ax) {
73
                return ax.a.x === 250 || ax.a.y === 250;
74
            })).toBeTruthy();
75
        });
76
77
        it('should finalize (setup connections) correctly', function() {
78
            var graph = this.graph;
79
            graph.rectangles.push(new Rectangle(300, 300, 100, 100));
80
            graph.build();
81
            expect(graph.verticalAxises.length).toBe(graph.horizontalAxises.length);
82
            expect(graph.verticalAxises.length).toBe(13);
83
            for (var id in graph.nodes) {
84
                if (graph.nodes.hasOwnProperty(id)) {
85
                    expect(isConnected(graph.nodes[id])).toBeTruthy();
86
                    expect(graph.nodes[id].vAxis).not.toBe(graph.nodes[id].hAxis);
87
                }
88
            }
89
        });
90
    });
91
});
92