Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenLYZ committed Jun 16, 2022
1 parent bc503d3 commit 0b1c5e7
Showing 1 changed file with 43 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,41 +59,41 @@ describe('getColorFunction()', () => {
{
operator: COMPARATOR.GREATER_THAN,
targetValue: 50,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
);
expect(colorFunction(50)).toBeUndefined();
expect(colorFunction(100)).toEqual('rgba(255,0,0,1)');
expect(colorFunction(100)).toEqual('#FF0000FF');
});

it('getColorFunction LESS_THAN', () => {
const colorFunction = getColorFunction(
{
operator: COMPARATOR.LESS_THAN,
targetValue: 100,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
);
expect(colorFunction(100)).toBeUndefined();
expect(colorFunction(50)).toEqual('rgba(255,0,0,1)');
expect(colorFunction(50)).toEqual('#FF0000FF');
});

it('getColorFunction GREATER_OR_EQUAL', () => {
const colorFunction = getColorFunction(
{
operator: COMPARATOR.GREATER_OR_EQUAL,
targetValue: 50,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
);
expect(colorFunction(50)).toEqual('rgba(255,0,0,0.05)');
expect(colorFunction(100)).toEqual('rgba(255,0,0,1)');
expect(colorFunction(50)).toEqual('#FF00000D');
expect(colorFunction(100)).toEqual('#FF0000FF');
expect(colorFunction(0)).toBeUndefined();
});

Expand All @@ -102,13 +102,13 @@ describe('getColorFunction()', () => {
{
operator: COMPARATOR.LESS_OR_EQUAL,
targetValue: 100,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
);
expect(colorFunction(50)).toEqual('rgba(255,0,0,1)');
expect(colorFunction(100)).toEqual('rgba(255,0,0,0.05)');
expect(colorFunction(50)).toEqual('#FF0000FF');
expect(colorFunction(100)).toEqual('#FF00000D');
expect(colorFunction(150)).toBeUndefined();
});

Expand All @@ -117,41 +117,41 @@ describe('getColorFunction()', () => {
{
operator: COMPARATOR.EQUAL,
targetValue: 100,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
);
expect(colorFunction(50)).toBeUndefined();
expect(colorFunction(100)).toEqual('rgba(255,0,0,1)');
expect(colorFunction(100)).toEqual('#FF0000FF');
});

it('getColorFunction NOT_EQUAL', () => {
let colorFunction = getColorFunction(
{
operator: COMPARATOR.NOT_EQUAL,
targetValue: 60,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
);
expect(colorFunction(60)).toBeUndefined();
expect(colorFunction(100)).toEqual('rgba(255,0,0,1)');
expect(colorFunction(50)).toEqual('rgba(255,0,0,0.29)');
expect(colorFunction(100)).toEqual('#FF0000FF');
expect(colorFunction(50)).toEqual('#FF00004A');

colorFunction = getColorFunction(
{
operator: COMPARATOR.NOT_EQUAL,
targetValue: 90,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
);
expect(colorFunction(90)).toBeUndefined();
expect(colorFunction(100)).toEqual('rgba(255,0,0,0.29)');
expect(colorFunction(50)).toEqual('rgba(255,0,0,1)');
expect(colorFunction(100)).toEqual('#FF00004A');
expect(colorFunction(50)).toEqual('#FF0000FF');
});

it('getColorFunction BETWEEN', () => {
Expand All @@ -160,13 +160,13 @@ describe('getColorFunction()', () => {
operator: COMPARATOR.BETWEEN,
targetValueLeft: 75,
targetValueRight: 125,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
);
expect(colorFunction(50)).toBeUndefined();
expect(colorFunction(100)).toEqual('rgba(255,0,0,0.53)');
expect(colorFunction(100)).toEqual('#FF000087');
});

it('getColorFunction BETWEEN_OR_EQUAL', () => {
Expand All @@ -175,13 +175,13 @@ describe('getColorFunction()', () => {
operator: COMPARATOR.BETWEEN_OR_EQUAL,
targetValueLeft: 50,
targetValueRight: 100,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
);
expect(colorFunction(50)).toEqual('rgba(255,0,0,0.05)');
expect(colorFunction(100)).toEqual('rgba(255,0,0,1)');
expect(colorFunction(50)).toEqual('#FF00000D');
expect(colorFunction(100)).toEqual('#FF0000FF');
expect(colorFunction(150)).toBeUndefined();
});

Expand All @@ -191,12 +191,12 @@ describe('getColorFunction()', () => {
operator: COMPARATOR.BETWEEN_OR_LEFT_EQUAL,
targetValueLeft: 50,
targetValueRight: 100,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
);
expect(colorFunction(50)).toEqual('rgba(255,0,0,0.05)');
expect(colorFunction(50)).toEqual('#FF00000D');
expect(colorFunction(100)).toBeUndefined();
});

Expand All @@ -206,21 +206,21 @@ describe('getColorFunction()', () => {
operator: COMPARATOR.BETWEEN_OR_RIGHT_EQUAL,
targetValueLeft: 50,
targetValueRight: 100,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
);
expect(colorFunction(50)).toBeUndefined();
expect(colorFunction(100)).toEqual('rgba(255,0,0,1)');
expect(colorFunction(100)).toEqual('#FF0000FF');
});

it('getColorFunction GREATER_THAN with target value undefined', () => {
const colorFunction = getColorFunction(
{
operator: COMPARATOR.GREATER_THAN,
targetValue: undefined,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
Expand All @@ -235,7 +235,7 @@ describe('getColorFunction()', () => {
operator: COMPARATOR.BETWEEN,
targetValueLeft: undefined,
targetValueRight: 100,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
Expand All @@ -250,7 +250,7 @@ describe('getColorFunction()', () => {
operator: COMPARATOR.BETWEEN,
targetValueLeft: 50,
targetValueRight: undefined,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
Expand All @@ -265,7 +265,7 @@ describe('getColorFunction()', () => {
// @ts-ignore
operator: 'unsupported operator',
targetValue: 50,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
Expand All @@ -278,15 +278,15 @@ describe('getColorFunction()', () => {
const colorFunction = getColorFunction(
{
operator: COMPARATOR.NONE,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
);
expect(colorFunction(20)).toEqual(undefined);
expect(colorFunction(50)).toEqual('rgba(255,0,0,0)');
expect(colorFunction(75)).toEqual('rgba(255,0,0,0.5)');
expect(colorFunction(100)).toEqual('rgba(255,0,0,1)');
expect(colorFunction(50)).toEqual('#FF000000');
expect(colorFunction(75)).toEqual('#FF000080');
expect(colorFunction(100)).toEqual('#FF0000FF');
expect(colorFunction(120)).toEqual(undefined);
});

Expand All @@ -295,7 +295,7 @@ describe('getColorFunction()', () => {
{
operator: undefined,
targetValue: 150,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
countValues,
Expand Down Expand Up @@ -325,47 +325,41 @@ describe('getColorFormatters()', () => {
{
operator: COMPARATOR.GREATER_THAN,
targetValue: 50,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
{
operator: COMPARATOR.LESS_THAN,
targetValue: 300,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'sum',
},
{
operator: COMPARATOR.BETWEEN,
targetValueLeft: 75,
targetValueRight: 125,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: 'count',
},
{
operator: COMPARATOR.GREATER_THAN,
targetValue: 150,
colorScheme: 'rgb(255,0,0)',
colorScheme: '#FF0000',
column: undefined,
},
];
const colorFormatters = getColorFormatters(columnConfig, mockData);
expect(colorFormatters.length).toEqual(3);

expect(colorFormatters[0].column).toEqual('count');
expect(colorFormatters[0].getColorFromValue(100)).toEqual(
'rgba(255,0,0,1)',
);
expect(colorFormatters[0].getColorFromValue(100)).toEqual('#FF0000FF');

expect(colorFormatters[1].column).toEqual('sum');
expect(colorFormatters[1].getColorFromValue(200)).toEqual(
'rgba(255,0,0,1)',
);
expect(colorFormatters[1].getColorFromValue(200)).toEqual('#FF0000FF');
expect(colorFormatters[1].getColorFromValue(400)).toBeUndefined();

expect(colorFormatters[2].column).toEqual('count');
expect(colorFormatters[2].getColorFromValue(100)).toEqual(
'rgba(255,0,0,0.53)',
);
expect(colorFormatters[2].getColorFromValue(100)).toEqual('#FF000087');
});

it('undefined column config', () => {
Expand Down

0 comments on commit 0b1c5e7

Please sign in to comment.