|
1 | 1 | var Box = require('@src/traces/box');
|
2 | 2 |
|
| 3 | +describe('Test boxes supplyDefaults', function() { |
| 4 | + var traceIn; |
| 5 | + var traceOut; |
| 6 | + var defaultColor = '#444'; |
| 7 | + var supplyDefaults = Box.supplyDefaults; |
| 8 | + |
| 9 | + beforeEach(function() { |
| 10 | + traceOut = {}; |
| 11 | + }); |
| 12 | + |
| 13 | + it('should set visible to false when x and y are empty', function() { |
| 14 | + traceIn = {}; |
| 15 | + supplyDefaults(traceIn, traceOut, defaultColor); |
| 16 | + expect(traceOut.visible).toBe(false); |
| 17 | + |
| 18 | + traceIn = { |
| 19 | + x: [], |
| 20 | + y: [] |
| 21 | + }; |
| 22 | + supplyDefaults(traceIn, traceOut, defaultColor, {}); |
| 23 | + expect(traceOut.visible).toBe(false); |
| 24 | + }); |
3 | 25 |
|
4 |
| -describe('Test boxes', function() { |
5 |
| - 'use strict'; |
6 |
| - |
7 |
| - describe('supplyDefaults', function() { |
8 |
| - var traceIn, |
9 |
| - traceOut; |
10 |
| - |
11 |
| - var defaultColor = '#444'; |
12 |
| - |
13 |
| - var supplyDefaults = Box.supplyDefaults; |
14 |
| - |
15 |
| - beforeEach(function() { |
16 |
| - traceOut = {}; |
17 |
| - }); |
18 |
| - |
19 |
| - it('should set visible to false when x and y are empty', function() { |
20 |
| - traceIn = {}; |
21 |
| - supplyDefaults(traceIn, traceOut, defaultColor); |
22 |
| - expect(traceOut.visible).toBe(false); |
23 |
| - |
24 |
| - traceIn = { |
25 |
| - x: [], |
26 |
| - y: [] |
27 |
| - }; |
28 |
| - supplyDefaults(traceIn, traceOut, defaultColor, {}); |
29 |
| - expect(traceOut.visible).toBe(false); |
30 |
| - }); |
31 |
| - |
32 |
| - it('should set visible to false when x or y is empty', function() { |
33 |
| - traceIn = { |
34 |
| - x: [] |
35 |
| - }; |
36 |
| - supplyDefaults(traceIn, traceOut, defaultColor, {}); |
37 |
| - expect(traceOut.visible).toBe(false); |
38 |
| - |
39 |
| - traceIn = { |
40 |
| - x: [], |
41 |
| - y: [1, 2, 3] |
42 |
| - }; |
43 |
| - supplyDefaults(traceIn, traceOut, defaultColor, {}); |
44 |
| - expect(traceOut.visible).toBe(false); |
45 |
| - |
46 |
| - traceIn = { |
47 |
| - y: [] |
48 |
| - }; |
49 |
| - supplyDefaults(traceIn, traceOut, defaultColor, {}); |
50 |
| - expect(traceOut.visible).toBe(false); |
51 |
| - |
52 |
| - traceIn = { |
53 |
| - x: [1, 2, 3], |
54 |
| - y: [] |
55 |
| - }; |
56 |
| - supplyDefaults(traceIn, traceOut, defaultColor, {}); |
57 |
| - expect(traceOut.visible).toBe(false); |
58 |
| - }); |
59 |
| - |
60 |
| - it('should set orientation to v by default', function() { |
61 |
| - traceIn = { |
62 |
| - y: [1, 2, 3] |
63 |
| - }; |
64 |
| - supplyDefaults(traceIn, traceOut, defaultColor, {}); |
65 |
| - expect(traceOut.orientation).toBe('v'); |
66 |
| - |
67 |
| - traceIn = { |
68 |
| - x: [1, 1, 1], |
69 |
| - y: [1, 2, 3] |
70 |
| - }; |
71 |
| - supplyDefaults(traceIn, traceOut, defaultColor, {}); |
72 |
| - expect(traceOut.orientation).toBe('v'); |
73 |
| - }); |
74 |
| - |
75 |
| - it('should set orientation to h when only x is supplied', function() { |
76 |
| - traceIn = { |
77 |
| - x: [1, 2, 3] |
78 |
| - }; |
79 |
| - supplyDefaults(traceIn, traceOut, defaultColor, {}); |
80 |
| - expect(traceOut.orientation).toBe('h'); |
81 |
| - |
82 |
| - }); |
83 |
| - |
84 |
| - it('should inherit layout.calendar', function() { |
85 |
| - traceIn = { |
86 |
| - y: [1, 2, 3] |
87 |
| - }; |
88 |
| - supplyDefaults(traceIn, traceOut, defaultColor, {calendar: 'islamic'}); |
89 |
| - |
90 |
| - // we always fill calendar attributes, because it's hard to tell if |
91 |
| - // we're on a date axis at this point. |
92 |
| - expect(traceOut.xcalendar).toBe('islamic'); |
93 |
| - expect(traceOut.ycalendar).toBe('islamic'); |
94 |
| - }); |
95 |
| - |
96 |
| - it('should take its own calendars', function() { |
97 |
| - traceIn = { |
98 |
| - y: [1, 2, 3], |
99 |
| - xcalendar: 'coptic', |
100 |
| - ycalendar: 'ethiopian' |
101 |
| - }; |
102 |
| - supplyDefaults(traceIn, traceOut, defaultColor, {calendar: 'islamic'}); |
103 |
| - |
104 |
| - // we always fill calendar attributes, because it's hard to tell if |
105 |
| - // we're on a date axis at this point. |
106 |
| - expect(traceOut.xcalendar).toBe('coptic'); |
107 |
| - expect(traceOut.ycalendar).toBe('ethiopian'); |
108 |
| - }); |
| 26 | + it('should set visible to false when x or y is empty', function() { |
| 27 | + traceIn = { |
| 28 | + x: [] |
| 29 | + }; |
| 30 | + supplyDefaults(traceIn, traceOut, defaultColor, {}); |
| 31 | + expect(traceOut.visible).toBe(false); |
| 32 | + |
| 33 | + traceIn = { |
| 34 | + x: [], |
| 35 | + y: [1, 2, 3] |
| 36 | + }; |
| 37 | + supplyDefaults(traceIn, traceOut, defaultColor, {}); |
| 38 | + expect(traceOut.visible).toBe(false); |
| 39 | + |
| 40 | + traceIn = { |
| 41 | + y: [] |
| 42 | + }; |
| 43 | + supplyDefaults(traceIn, traceOut, defaultColor, {}); |
| 44 | + expect(traceOut.visible).toBe(false); |
| 45 | + |
| 46 | + traceIn = { |
| 47 | + x: [1, 2, 3], |
| 48 | + y: [] |
| 49 | + }; |
| 50 | + supplyDefaults(traceIn, traceOut, defaultColor, {}); |
| 51 | + expect(traceOut.visible).toBe(false); |
| 52 | + }); |
109 | 53 |
|
| 54 | + it('should set orientation to v by default', function() { |
| 55 | + traceIn = { |
| 56 | + y: [1, 2, 3] |
| 57 | + }; |
| 58 | + supplyDefaults(traceIn, traceOut, defaultColor, {}); |
| 59 | + expect(traceOut.orientation).toBe('v'); |
| 60 | + |
| 61 | + traceIn = { |
| 62 | + x: [1, 1, 1], |
| 63 | + y: [1, 2, 3] |
| 64 | + }; |
| 65 | + supplyDefaults(traceIn, traceOut, defaultColor, {}); |
| 66 | + expect(traceOut.orientation).toBe('v'); |
110 | 67 | });
|
111 | 68 |
|
| 69 | + it('should set orientation to h when only x is supplied', function() { |
| 70 | + traceIn = { |
| 71 | + x: [1, 2, 3] |
| 72 | + }; |
| 73 | + supplyDefaults(traceIn, traceOut, defaultColor, {}); |
| 74 | + expect(traceOut.orientation).toBe('h'); |
| 75 | + |
| 76 | + }); |
| 77 | + |
| 78 | + it('should inherit layout.calendar', function() { |
| 79 | + traceIn = { |
| 80 | + y: [1, 2, 3] |
| 81 | + }; |
| 82 | + supplyDefaults(traceIn, traceOut, defaultColor, {calendar: 'islamic'}); |
| 83 | + |
| 84 | + // we always fill calendar attributes, because it's hard to tell if |
| 85 | + // we're on a date axis at this point. |
| 86 | + expect(traceOut.xcalendar).toBe('islamic'); |
| 87 | + expect(traceOut.ycalendar).toBe('islamic'); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should take its own calendars', function() { |
| 91 | + traceIn = { |
| 92 | + y: [1, 2, 3], |
| 93 | + xcalendar: 'coptic', |
| 94 | + ycalendar: 'ethiopian' |
| 95 | + }; |
| 96 | + supplyDefaults(traceIn, traceOut, defaultColor, {calendar: 'islamic'}); |
| 97 | + |
| 98 | + // we always fill calendar attributes, because it's hard to tell if |
| 99 | + // we're on a date axis at this point. |
| 100 | + expect(traceOut.xcalendar).toBe('coptic'); |
| 101 | + expect(traceOut.ycalendar).toBe('ethiopian'); |
| 102 | + }); |
112 | 103 | });
|
0 commit comments