-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(added more tests): added more tests
- Loading branch information
1 parent
02b9772
commit 18dfc53
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...ugins/superset-ui-plugins/packages/superset-ui-plugin-chart-table/test/buildQuery.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'babel-polyfill'; | ||
import buildQuery from '../src/buildQuery'; | ||
|
||
describe('TableVis buildQuery', () => { | ||
const formData = { | ||
datasource: '5__table', | ||
granularity_sqla: 'ds', | ||
series: 'foo', | ||
viz_type: 'table', | ||
all_columns: ['a', 'b', 'c'], | ||
percent_metrics: ['a'], | ||
include_time: false, | ||
order_by_cols: [], | ||
}; | ||
|
||
it('should build groupby with series in form data', () => { | ||
const queryContext = buildQuery(formData); | ||
const [query] = queryContext.queries; | ||
expect(query.metrics[0].label).toEqual('a'); | ||
expect(query.groupby).toHaveLength(0); | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
...gins/superset-ui-plugins/packages/superset-ui-plugin-chart-table/test/processData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import processData from '../src/processData'; | ||
|
||
describe('processData', () => { | ||
const timeseriesLimitMetric = 'a'; | ||
const orderDesc = true; | ||
const records = [ | ||
{ | ||
a: 1, | ||
b: 1, | ||
c: 3, | ||
}, | ||
{ | ||
a: 2, | ||
b: 1, | ||
c: 2, | ||
}, | ||
{ | ||
a: 3, | ||
b: 1, | ||
c: 1, | ||
}, | ||
]; | ||
const metrics = ['a', 'b', 'c']; | ||
|
||
it('returns sorted result', () => { | ||
const result = processData({ | ||
timeseriesLimitMetric, | ||
orderDesc, | ||
records, | ||
metrics, | ||
}); | ||
const maxValue = Math.max(...records.map(r => r[timeseriesLimitMetric])); | ||
const minValue = Math.min(...records.map(r => r[timeseriesLimitMetric])); | ||
expect(result[0].data[timeseriesLimitMetric]).toEqual(maxValue); | ||
expect(result[result.length - 1].data[timeseriesLimitMetric]).toEqual(minValue); | ||
}); | ||
|
||
it('removes the timeseriesLimitMetric column if it is not included in metrics', () => { | ||
const filteredMetrics = metrics.filter(metric => metric !== timeseriesLimitMetric); | ||
const result = processData({ | ||
timeseriesLimitMetric, | ||
orderDesc, | ||
records, | ||
metrics: filteredMetrics, | ||
}); | ||
result.forEach(row => { | ||
expect(row.data).toEqual( | ||
expect.not.objectContaining({ | ||
[timeseriesLimitMetric]: expect(Number), | ||
}), | ||
); | ||
}); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
...s/superset-ui-plugins/packages/superset-ui-plugin-chart-table/test/processMetrics.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import processMetrics from '../src/processMetrics'; | ||
|
||
describe('processData', () => { | ||
const records = [ | ||
{ | ||
a: 1, | ||
'%b': 0.4, | ||
c: 3, | ||
}, | ||
{ | ||
a: 2, | ||
'%b': 0.4, | ||
c: 2, | ||
}, | ||
{ | ||
a: 3, | ||
'%b': 0.2, | ||
c: 1, | ||
}, | ||
]; | ||
const metrics = ['a']; | ||
const percentMetrics = ['b']; | ||
|
||
it('returns sorted result', () => { | ||
const result = processMetrics({ | ||
records, | ||
metrics, | ||
percentMetrics, | ||
}); | ||
const expected = ['a', '%b']; | ||
expect(result).toEqual(expect.arrayContaining(expected)); | ||
}); | ||
}); |