moved number generation to the radar model
[tech-radar.git] / test / models / radar-spec.js
1 describe('tr.models.Radar', function () {
2
3 it('has no quadrants by default', function () {
4 radar = new tr.models.Radar();
5
6 expect(radar.quadrants().I).toBe(null);
7 expect(radar.quadrants().II).toBe(null);
8 expect(radar.quadrants().III).toBe(null);
9 expect(radar.quadrants().IV).toBe(null);
10 });
11
12 it('sets the first quadrant', function () {
13 var quadrant, radar;
14
15 quadrant = new tr.models.Quadrant('First');
16 radar = new tr.models.Radar();
17
18 radar.setFirstQuadrant(quadrant);
19
20 expect(radar.quadrants().I).toEqual(quadrant);
21 });
22
23 it('sets the second quadrant', function () {
24 var quadrant, radar;
25
26 quadrant = new tr.models.Quadrant('Second');
27 radar = new tr.models.Radar();
28
29 radar.setSecondQuadrant(quadrant);
30
31 expect(radar.quadrants().II).toEqual(quadrant);
32 });
33
34 it('sets the third quadrant', function () {
35 var quadrant, radar;
36
37 quadrant = new tr.models.Quadrant('Third');
38 radar = new tr.models.Radar();
39
40 radar.setThirdQuadrant(quadrant);
41
42 expect(radar.quadrants().III).toEqual(quadrant);
43 });
44
45 it('sets the fourth quadrant', function () {
46 var quadrant, radar;
47
48 quadrant = new tr.models.Quadrant('Fourth');
49 radar = new tr.models.Radar();
50
51 radar.setFourthQuadrant(quadrant);
52
53 expect(radar.quadrants().IV).toEqual(quadrant);
54 });
55
56 describe('blip numbers', function () {
57 var firstQuadrant, secondQuadrant, radar, firstCycle;
58
59 beforeEach(function () {
60 firstCycle = new tr.models.Cycle('Adopt', 0);
61 firstQuadrant = new tr.models.Quadrant('First');
62 secondQuadrant = new tr.models.Quadrant('Second');
63 firstQuadrant.add([
64 new tr.models.Blip('A', firstCycle),
65 new tr.models.Blip('B', firstCycle)
66 ]);
67 secondQuadrant.add([
68 new tr.models.Blip('C', firstCycle),
69 new tr.models.Blip('D', firstCycle)
70 ]);
71 radar = new tr.models.Radar();
72 });
73
74 it('sets blip numbers starting on the first quadrant', function () {
75 radar.setFirstQuadrant(firstQuadrant);
76
77 expect(radar.quadrants().I.blips()[0].number()).toEqual(1);
78 expect(radar.quadrants().I.blips()[1].number()).toEqual(2);
79 });
80
81 it('continues the number from the previous quadrant set', function () {
82 radar.setFirstQuadrant(firstQuadrant);
83 radar.setSecondQuadrant(secondQuadrant);
84
85 expect(radar.quadrants().II.blips()[0].number()).toEqual(3);
86 expect(radar.quadrants().II.blips()[1].number()).toEqual(4);
87 });
88 });
89
90 describe('cycles', function () {
91 var quadrant, radar, firstCycle, secondCycle;
92
93 beforeEach(function () {
94 firstCycle = new tr.models.Cycle('Adopt', 0);
95 secondCycle = new tr.models.Cycle('Hold', 1);
96 quadrant = new tr.models.Quadrant('Fourth');
97 radar = new tr.models.Radar();
98 });
99
100 it('returns an array for a given set of blips', function () {
101 quadrant.add([
102 new tr.models.Blip('A', firstCycle),
103 new tr.models.Blip('B', secondCycle)
104 ]);
105
106 radar.setFirstQuadrant(quadrant);
107
108 expect(radar.cycles()).toEqual([firstCycle, secondCycle]);
109 });
110
111 it('has unique cycles', function () {
112 quadrant.add([
113 new tr.models.Blip('A', firstCycle),
114 new tr.models.Blip('B', firstCycle),
115 new tr.models.Blip('C', secondCycle)
116 ]);
117
118 radar.setFirstQuadrant(quadrant);
119
120 expect(radar.cycles()).toEqual([firstCycle, secondCycle]);
121 });
122
123 it('has sorts by the cycle order', function () {
124 quadrant.add([
125 new tr.models.Blip('C', secondCycle),
126 new tr.models.Blip('A', firstCycle),
127 new tr.models.Blip('B', firstCycle)
128 ]);
129
130 radar.setFirstQuadrant(quadrant);
131
132 expect(radar.cycles()).toEqual([firstCycle, secondCycle]);
133 });
134 });
135 });