-
Notifications
You must be signed in to change notification settings - Fork 592
/
scale.test.ts
91 lines (80 loc) · 3.41 KB
/
scale.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import {ScaleChannel, SCALE_CHANNELS} from '../src/channel';
import * as scale from '../src/scale';
import {channelSupportScaleType, CONTINUOUS_TO_CONTINUOUS_SCALES, ScaleType, SCALE_TYPES} from '../src/scale';
import {some} from '../src/util';
import {without} from './util';
describe('scale', () => {
describe('scaleTypeSupportProperty', () => {
// Make sure we always edit this when we add new channel
it('should have at least one supported scale types for all scale properties', () => {
for (const prop of scale.SCALE_PROPERTIES) {
expect(
some(scale.SCALE_TYPES, scaleType => {
return scale.scaleTypeSupportProperty(scaleType, prop);
})
).toBeTruthy();
}
});
// TODO: write more test blindly (Don't look at our code, just look at Vega scale typings and D3 code.)
});
describe('scaleTypes', () => {
it('should either hasContinuousDomain or hasDiscreteDomain', () => {
for (const scaleType of scale.SCALE_TYPES) {
expect(scale.hasContinuousDomain(scaleType) !== scale.hasDiscreteDomain(scaleType)).toBeTruthy();
}
});
});
describe('channelSupportScaleType', () => {
// Make sure we always edit this when we add new channel
it('should have at least one supported scale types for all channels with scale', () => {
for (const channel of SCALE_CHANNELS) {
expect(
some(SCALE_TYPES, scaleType => {
return channelSupportScaleType(channel, scaleType);
})
).toBeTruthy();
}
});
// Make sure we always edit this when we add new scale type
it('should have at least one supported channel for all scale types', () => {
for (const scaleType of SCALE_TYPES) {
expect(
some(SCALE_CHANNELS, channel => {
return channelSupportScaleType(channel, scaleType);
})
).toBeTruthy();
}
});
it('shape should support only ordinal', () => {
expect(channelSupportScaleType('shape', 'ordinal')).toBeTruthy();
const nonOrdinal = without<ScaleType>(SCALE_TYPES, ['ordinal']);
for (const scaleType of nonOrdinal) {
expect(!channelSupportScaleType('shape', scaleType)).toBeTruthy();
}
});
it('color should support all scale types except band', () => {
for (const scaleType of SCALE_TYPES) {
expect(channelSupportScaleType('color', scaleType)).toEqual(scaleType !== 'band');
}
});
it('x and y support all continuous scale type as well as band and point', () => {
// x,y should use either band or point for ordinal input
const scaleTypes = [...CONTINUOUS_TO_CONTINUOUS_SCALES, ScaleType.BAND, ScaleType.POINT];
for (const channel of ['x', 'y'] as ScaleChannel[]) {
expect(channelSupportScaleType(channel, 'ordinal')).toBeFalsy();
for (const scaleType of scaleTypes) {
expect(channelSupportScaleType(channel, scaleType)).toBeTruthy();
}
}
});
it('size and opacity support all continuous scale type as well as band and point', () => {
// x,y should use either band or point for ordinal input
const scaleTypes = [...CONTINUOUS_TO_CONTINUOUS_SCALES, ScaleType.BAND, ScaleType.POINT];
for (const channel of ['size', 'opacity'] as ScaleChannel[]) {
for (const scaleType of scaleTypes) {
expect(channelSupportScaleType(channel, scaleType)).toBeTruthy();
}
}
});
});
});