|
1 | | -import { DEFAULT_GEOMETRY_STYLES } from '../../../utils/themes/theme_commons'; |
2 | 1 | import { getSpecId } from '../../../utils/ids'; |
3 | 2 | import { |
4 | 3 | BarGeometry, |
|
8 | 7 | getStyleOverrides, |
9 | 8 | GeometryId, |
10 | 9 | } from './rendering'; |
11 | | -import { BarSeriesStyle } from '../../../utils/themes/theme'; |
| 10 | +import { BarSeriesStyle, SharedGeometryStyle } from '../../../utils/themes/theme'; |
12 | 11 | import { DataSeriesDatum } from '../utils/series'; |
13 | 12 | import { RecursivePartial, mergePartial } from '../../../utils/commons'; |
14 | 13 |
|
@@ -116,67 +115,58 @@ describe('Rendering utils', () => { |
116 | 115 | }, |
117 | 116 | }; |
118 | 117 |
|
119 | | - const sharedThemeStyle = DEFAULT_GEOMETRY_STYLES; |
120 | | - const specOpacity = 0.66; |
121 | | - |
122 | | - const defaultStyle = getGeometryStyle(geometryId, null, sharedThemeStyle); |
| 118 | + const sharedThemeStyle: SharedGeometryStyle = { |
| 119 | + default: { |
| 120 | + opacity: 1, |
| 121 | + }, |
| 122 | + highlighted: { |
| 123 | + opacity: 0.5, |
| 124 | + }, |
| 125 | + unhighlighted: { |
| 126 | + opacity: 0.25, |
| 127 | + }, |
| 128 | + }; |
123 | 129 |
|
124 | 130 | // no highlighted elements |
125 | | - expect(defaultStyle).toEqual({ opacity: 1 }); |
126 | | - |
127 | | - const customDefaultStyle = getGeometryStyle(geometryId, null, sharedThemeStyle, specOpacity); |
128 | | - |
129 | | - // no highlighted elements with custom spec opacity |
130 | | - expect(customDefaultStyle).toEqual({ opacity: 0.66 }); |
131 | | - |
132 | | - const highlightedStyle = getGeometryStyle(geometryId, highlightedLegendItem, sharedThemeStyle); |
| 131 | + const defaultStyle = getGeometryStyle(geometryId, null, sharedThemeStyle); |
| 132 | + expect(defaultStyle).toBe(sharedThemeStyle.default); |
133 | 133 |
|
134 | 134 | // should equal highlighted opacity |
135 | | - expect(highlightedStyle).toEqual({ opacity: 1 }); |
136 | | - |
137 | | - const unhighlightedStyle = getGeometryStyle(geometryId, unhighlightedLegendItem, sharedThemeStyle); |
| 135 | + const highlightedStyle = getGeometryStyle(geometryId, highlightedLegendItem, sharedThemeStyle); |
| 136 | + expect(highlightedStyle).toBe(sharedThemeStyle.highlighted); |
138 | 137 |
|
139 | 138 | // should equal unhighlighted opacity |
140 | | - expect(unhighlightedStyle).toEqual({ opacity: 0.25 }); |
141 | | - |
142 | | - const customHighlightedStyle = getGeometryStyle(geometryId, highlightedLegendItem, sharedThemeStyle, specOpacity); |
| 139 | + const unhighlightedStyle = getGeometryStyle(geometryId, unhighlightedLegendItem, sharedThemeStyle); |
| 140 | + expect(unhighlightedStyle).toBe(sharedThemeStyle.unhighlighted); |
143 | 141 |
|
144 | 142 | // should equal custom spec highlighted opacity |
145 | | - expect(customHighlightedStyle).toEqual({ opacity: 0.66 }); |
146 | | - |
147 | | - const customUnhighlightedStyle = getGeometryStyle( |
148 | | - geometryId, |
149 | | - unhighlightedLegendItem, |
150 | | - sharedThemeStyle, |
151 | | - specOpacity, |
152 | | - ); |
| 143 | + const customHighlightedStyle = getGeometryStyle(geometryId, highlightedLegendItem, sharedThemeStyle); |
| 144 | + expect(customHighlightedStyle).toBe(sharedThemeStyle.highlighted); |
153 | 145 |
|
154 | 146 | // unhighlighted elements remain unchanged with custom opacity |
155 | | - expect(customUnhighlightedStyle).toEqual({ opacity: 0.25 }); |
| 147 | + const customUnhighlightedStyle = getGeometryStyle(geometryId, unhighlightedLegendItem, sharedThemeStyle); |
| 148 | + expect(customUnhighlightedStyle).toBe(sharedThemeStyle.unhighlighted); |
156 | 149 |
|
157 | 150 | // has individual highlight |
158 | | - const hasIndividualHighlight = getGeometryStyle(geometryId, null, sharedThemeStyle, undefined, { |
| 151 | + const hasIndividualHighlight = getGeometryStyle(geometryId, null, sharedThemeStyle, { |
159 | 152 | hasHighlight: true, |
160 | 153 | hasGeometryHover: true, |
161 | 154 | }); |
162 | | - |
163 | | - expect(hasIndividualHighlight).toEqual({ opacity: 1 }); |
| 155 | + expect(hasIndividualHighlight).toBe(sharedThemeStyle.highlighted); |
164 | 156 |
|
165 | 157 | // no highlight |
166 | | - const noHighlight = getGeometryStyle(geometryId, null, sharedThemeStyle, undefined, { |
| 158 | + const noHighlight = getGeometryStyle(geometryId, null, sharedThemeStyle, { |
167 | 159 | hasHighlight: false, |
168 | 160 | hasGeometryHover: true, |
169 | 161 | }); |
170 | | - |
171 | | - expect(noHighlight).toEqual({ opacity: 0.25 }); |
| 162 | + expect(noHighlight).toBe(sharedThemeStyle.unhighlighted); |
172 | 163 |
|
173 | 164 | // no geometry hover |
174 | | - const noHover = getGeometryStyle(geometryId, null, sharedThemeStyle, undefined, { |
| 165 | + const noHover = getGeometryStyle(geometryId, null, sharedThemeStyle, { |
175 | 166 | hasHighlight: true, |
176 | 167 | hasGeometryHover: false, |
177 | 168 | }); |
178 | | - |
179 | | - expect(noHover).toEqual({ opacity: 1 }); |
| 169 | + expect(noHover).toBe(sharedThemeStyle.highlighted); |
180 | 170 | }); |
181 | 171 |
|
182 | 172 | describe('getStyleOverrides', () => { |
|
0 commit comments