Skip to content

Commit 4f91957

Browse files
committed
🔒 behavior target arrays are shorter/longer than other arrays
1 parent 9c70ee9 commit 4f91957

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

test/jasmine/tests/transform_sort_test.js

+52
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,58 @@ describe('Test sort transform calc:', function() {
146146
expect(out[0].marker.color).toEqual([0.4, 0.1, 0.1, 0.2, 0.2, 0.3, 0.3]);
147147
expect(out[0].marker.size).toEqual([10, 10, 1, 20, 6, 5, 0]);
148148
});
149+
150+
it('should truncate transformed arrays to target array length (short target case)', function() {
151+
var out = _transform([
152+
extend({
153+
transforms: [{
154+
order: 'descending',
155+
target: [0, 1]
156+
}]
157+
}
158+
), extend({
159+
text: ['A', 'B'],
160+
transforms: [{ target: 'text' }]
161+
})]);
162+
163+
expect(out[0].x).toEqual([-1, -2]);
164+
expect(out[0].y).toEqual([2, 1]);
165+
expect(out[0].ids).toEqual(['n1', 'n0']);
166+
expect(out[0].marker.color).toEqual([0.2, 0.1]);
167+
expect(out[0].marker.size).toEqual([20, 10]);
168+
169+
expect(out[1].x).toEqual([-2, -1]);
170+
expect(out[1].y).toEqual([1, 2]);
171+
expect(out[1].ids).toEqual(['n0', 'n1']);
172+
expect(out[1].marker.color).toEqual([0.1, 0.2]);
173+
expect(out[1].marker.size).toEqual([10, 20]);
174+
});
175+
176+
it('should truncate transformed arrays to target array length (long target case)', function() {
177+
var out = _transform([
178+
extend({
179+
transforms: [{
180+
order: 'descending',
181+
target: [0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3]
182+
}]
183+
}
184+
), extend({
185+
text: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
186+
transforms: [{ target: 'text' }]
187+
})]);
188+
189+
expect(out[0].x).toEqual([1, undefined, -2, 3, undefined, -1, 1, undefined, -2, 0, undefined]);
190+
expect(out[0].y).toEqual([1, undefined, 3, 3, undefined, 2, 2, undefined, 1, 1, undefined]);
191+
expect(out[0].ids).toEqual(['p3', undefined, 'n2', 'p2', undefined, 'n1', 'p1', undefined, 'n0', 'z', undefined]);
192+
expect(out[0].marker.color).toEqual([0.4, undefined, 0.3, 0.3, undefined, 0.2, 0.2, undefined, 0.1, 0.1, undefined]);
193+
expect(out[0].marker.size).toEqual([10, undefined, 5, 0, undefined, 20, 6, undefined, 10, 1, undefined]);
194+
195+
expect(out[1].x).toEqual([-2, -1, -2, 0, 1, 3, 1, undefined, undefined]);
196+
expect(out[1].y).toEqual([1, 2, 3, 1, 2, 3, 1, undefined, undefined]);
197+
expect(out[1].ids).toEqual(['n0', 'n1', 'n2', 'z', 'p1', 'p2', 'p3', undefined, undefined]);
198+
expect(out[1].marker.color).toEqual([0.1, 0.2, 0.3, 0.1, 0.2, 0.3, 0.4, undefined, undefined]);
199+
expect(out[1].marker.size).toEqual([10, 20, 5, 1, 6, 0, 10, undefined, undefined]);
200+
});
149201
});
150202

151203
describe('Test sort transform interactions:', function() {

0 commit comments

Comments
 (0)