2021-05-10 11:19:24 -04:00
|
|
|
/**
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2022-05-04 08:55:22 -04:00
|
|
|
import { ChartProps, supersetTheme } from '@superset-ui/core';
|
2022-03-27 22:20:06 -04:00
|
|
|
import { EchartsTreemapChartProps } from '../../src/Treemap/types';
|
2021-05-10 11:19:24 -04:00
|
|
|
import transformProps from '../../src/Treemap/transformProps';
|
|
|
|
|
2022-04-26 13:35:01 -04:00
|
|
|
describe('Treemap transformProps', () => {
|
2021-05-10 11:19:24 -04:00
|
|
|
const formData = {
|
|
|
|
colorScheme: 'bnbColors',
|
|
|
|
datasource: '3__table',
|
|
|
|
granularity_sqla: 'ds',
|
2021-05-24 06:07:25 -04:00
|
|
|
metric: 'sum__num',
|
2021-05-10 11:19:24 -04:00
|
|
|
groupby: ['foo', 'bar'],
|
|
|
|
};
|
|
|
|
const chartProps = new ChartProps({
|
|
|
|
formData,
|
|
|
|
width: 800,
|
|
|
|
height: 600,
|
|
|
|
queriesData: [
|
|
|
|
{
|
|
|
|
data: [
|
|
|
|
{ foo: 'Sylvester', bar: 'bar1', sum__num: 10 },
|
|
|
|
{ foo: 'Arnold', bar: 'bar2', sum__num: 2.5 },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2022-05-04 08:55:22 -04:00
|
|
|
theme: supersetTheme,
|
2021-05-10 11:19:24 -04:00
|
|
|
});
|
|
|
|
|
2022-04-26 13:35:01 -04:00
|
|
|
it('should transform chart props for viz', () => {
|
2022-03-27 22:20:06 -04:00
|
|
|
expect(transformProps(chartProps as EchartsTreemapChartProps)).toEqual(
|
2021-05-10 11:19:24 -04:00
|
|
|
expect.objectContaining({
|
|
|
|
width: 800,
|
|
|
|
height: 600,
|
|
|
|
echartOptions: expect.objectContaining({
|
|
|
|
series: [
|
|
|
|
expect.objectContaining({
|
|
|
|
data: expect.arrayContaining([
|
|
|
|
expect.objectContaining({
|
|
|
|
name: 'sum__num',
|
|
|
|
children: expect.arrayContaining([
|
|
|
|
expect.objectContaining({
|
|
|
|
name: 'Sylvester',
|
|
|
|
children: expect.arrayContaining([
|
|
|
|
expect.objectContaining({
|
|
|
|
name: 'bar1',
|
|
|
|
value: 10,
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|