|
| 1 | +var Sliders = require('@src/components/sliders'); |
| 2 | +// var constants = require('@src/components/sliders/constants'); |
| 3 | + |
| 4 | +// var d3 = require('d3'); |
| 5 | +// var Plotly = require('@lib'); |
| 6 | +// var Lib = require('@src/lib'); |
| 7 | +// var createGraphDiv = require('../assets/create_graph_div'); |
| 8 | +// var destroyGraphDiv = require('../assets/destroy_graph_div'); |
| 9 | + |
| 10 | +describe('sliders defaults', function() { |
| 11 | + 'use strict'; |
| 12 | + |
| 13 | + var supply = Sliders.supplyLayoutDefaults; |
| 14 | + |
| 15 | + var layoutIn, layoutOut; |
| 16 | + |
| 17 | + beforeEach(function() { |
| 18 | + layoutIn = {}; |
| 19 | + layoutOut = {}; |
| 20 | + }); |
| 21 | + |
| 22 | + it('should set \'visible\' to false when no steps are present', function() { |
| 23 | + layoutIn.sliders = [{ |
| 24 | + steps: [{ |
| 25 | + method: 'relayout', |
| 26 | + args: ['title', 'Hello World'] |
| 27 | + }, { |
| 28 | + method: 'update', |
| 29 | + args: [ { 'marker.size': 20 }, { 'xaxis.range': [0, 10] }, [0, 1] ] |
| 30 | + }, { |
| 31 | + method: 'animate', |
| 32 | + args: [ 'frame1', { transition: { duration: 500, ease: 'cubic-in-out' }}] |
| 33 | + }] |
| 34 | + }, { |
| 35 | + bgcolor: 'red' |
| 36 | + }, { |
| 37 | + visible: false, |
| 38 | + steps: [{ |
| 39 | + method: 'relayout', |
| 40 | + args: ['title', 'Hello World'] |
| 41 | + }] |
| 42 | + }]; |
| 43 | + |
| 44 | + supply(layoutIn, layoutOut); |
| 45 | + |
| 46 | + expect(layoutOut.sliders[0].visible).toBe(true); |
| 47 | + expect(layoutOut.sliders[0].active).toEqual(0); |
| 48 | + expect(layoutOut.sliders[0].steps[0].args.length).toEqual(2); |
| 49 | + expect(layoutOut.sliders[0].steps[1].args.length).toEqual(3); |
| 50 | + expect(layoutOut.sliders[0].steps[2].args.length).toEqual(2); |
| 51 | + |
| 52 | + expect(layoutOut.sliders[1].visible).toBe(false); |
| 53 | + expect(layoutOut.sliders[1].active).toBeUndefined(); |
| 54 | + |
| 55 | + expect(layoutOut.sliders[2].visible).toBe(false); |
| 56 | + expect(layoutOut.sliders[2].active).toBeUndefined(); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should skip over non-object steps', function() { |
| 60 | + layoutIn.sliders = [{ |
| 61 | + steps: [ |
| 62 | + null, |
| 63 | + { |
| 64 | + method: 'relayout', |
| 65 | + args: ['title', 'Hello World'] |
| 66 | + }, |
| 67 | + 'remove' |
| 68 | + ] |
| 69 | + }]; |
| 70 | + |
| 71 | + supply(layoutIn, layoutOut); |
| 72 | + |
| 73 | + expect(layoutOut.sliders[0].steps.length).toEqual(1); |
| 74 | + expect(layoutOut.sliders[0].steps[0]).toEqual({ |
| 75 | + method: 'relayout', |
| 76 | + args: ['title', 'Hello World'], |
| 77 | + label: '', |
| 78 | + _index: 1 |
| 79 | + }); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should skip over steps with array \'args\' field', function() { |
| 83 | + layoutIn.sliders = [{ |
| 84 | + steps: [{ |
| 85 | + method: 'restyle', |
| 86 | + }, { |
| 87 | + method: 'relayout', |
| 88 | + args: ['title', 'Hello World'] |
| 89 | + }, { |
| 90 | + method: 'relayout', |
| 91 | + args: null |
| 92 | + }, {}] |
| 93 | + }]; |
| 94 | + |
| 95 | + supply(layoutIn, layoutOut); |
| 96 | + |
| 97 | + expect(layoutOut.sliders[0].steps.length).toEqual(1); |
| 98 | + expect(layoutOut.sliders[0].steps[0]).toEqual({ |
| 99 | + method: 'relayout', |
| 100 | + args: ['title', 'Hello World'], |
| 101 | + label: '', |
| 102 | + _index: 1 |
| 103 | + }); |
| 104 | + }); |
| 105 | + |
| 106 | + it('should keep ref to input update menu container', function() { |
| 107 | + layoutIn.sliders = [{ |
| 108 | + steps: [{ |
| 109 | + method: 'relayout', |
| 110 | + args: ['title', 'Hello World'] |
| 111 | + }] |
| 112 | + }, { |
| 113 | + bgcolor: 'red' |
| 114 | + }, { |
| 115 | + visible: false, |
| 116 | + steps: [{ |
| 117 | + method: 'relayout', |
| 118 | + args: ['title', 'Hello World'] |
| 119 | + }] |
| 120 | + }]; |
| 121 | + |
| 122 | + supply(layoutIn, layoutOut); |
| 123 | + |
| 124 | + expect(layoutOut.sliders[0]._input).toBe(layoutIn.sliders[0]); |
| 125 | + expect(layoutOut.sliders[1]._input).toBe(layoutIn.sliders[1]); |
| 126 | + expect(layoutOut.sliders[2]._input).toBe(layoutIn.sliders[2]); |
| 127 | + }); |
| 128 | + |
| 129 | + it('should default \'bgcolor\' to layout \'paper_bgcolor\'', function() { |
| 130 | + var steps = [{ |
| 131 | + method: 'relayout', |
| 132 | + args: ['title', 'Hello World'] |
| 133 | + }]; |
| 134 | + |
| 135 | + layoutIn.sliders = [{ |
| 136 | + steps: steps, |
| 137 | + }, { |
| 138 | + bgcolor: 'red', |
| 139 | + steps: steps |
| 140 | + }]; |
| 141 | + |
| 142 | + layoutOut.paper_bgcolor = 'blue'; |
| 143 | + |
| 144 | + supply(layoutIn, layoutOut); |
| 145 | + |
| 146 | + expect(layoutOut.sliders[0].bgcolor).toEqual('blue'); |
| 147 | + expect(layoutOut.sliders[1].bgcolor).toEqual('red'); |
| 148 | + }); |
| 149 | +}); |
0 commit comments