This repository has been archived by the owner on Jun 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
fix(legacy-table): avoid React DOM #392
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2351369
fix(legacy-table): avoid React DOM
ktmud 623f4cf
fix(legacy-table): handle the case when percentMetrics is null
ktmud 0e95808
fix(legacy-table): linting errors
ktmud a6701b5
refactor: use nimbus build
ktmud cdaf494
test(legacy-table): add React component tests
ktmud 2f25555
test(legacy-table): more sophisticated cases
ktmud c8a58c9
fix: address PR #392 comments
ktmud 933c3f9
chore(legacy-table): clean up tests case setups
ktmud b7596d0
fix(legacy-table): misleading comment
ktmud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
65 changes: 65 additions & 0 deletions
65
packages/superset-ui-legacy-plugin-chart-table/test/ReactDataTable.test.tsx
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,65 @@ | ||
/** | ||
* 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. | ||
*/ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import ReactDataTable from '../src/ReactDataTable'; | ||
import transformProps from '../src/transformProps'; | ||
import * as testData from './test_data'; | ||
|
||
describe('legacy-table', () => { | ||
// Can test more prop transformation here. Not needed for now. | ||
describe('transformProps', () => {}); | ||
|
||
describe('ReactDataTable', () => { | ||
// Jest throw an error at `console.warn`, this disables that behavior | ||
ktmud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
beforeAll(() => { | ||
console.warn = console.log; | ||
}); | ||
afterAll(() => { | ||
console.warn = console.error; | ||
}); | ||
|
||
let wrap: any; // the SuperChart wraper | ||
|
||
it('render basic data', () => { | ||
wrap = mount(<ReactDataTable {...transformProps(testData.basic)} />); | ||
const tree = wrap.render(); // returns a CheerioWrapper with jQuery-like API | ||
const cells = tree.find('td'); | ||
expect(tree.hasClass('superset-legacy-chart-table')).toEqual(true); | ||
expect(cells).toHaveLength(4); | ||
expect(cells.eq(0).text()).toEqual('Michael'); | ||
expect(cells.eq(3).attr('data-sort')).toEqual('2467'); | ||
}); | ||
|
||
it('render advanced data', () => { | ||
// should successfull rerender with new props | ||
wrap.setProps(transformProps(testData.advanced)); | ||
const tree = wrap.render(); | ||
const cells = tree.find('td'); | ||
expect( | ||
tree | ||
.find('th') | ||
.eq(1) | ||
.text(), | ||
).toEqual('Sum of Num'); | ||
expect(cells.eq(2).text()).toEqual('12.346%'); | ||
expect(cells.eq(4).text()).toEqual('2.47k'); | ||
}); | ||
}); | ||
}); |
103 changes: 103 additions & 0 deletions
103
packages/superset-ui-legacy-plugin-chart-table/test/test_data.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,103 @@ | ||
/** | ||
ktmud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* 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. | ||
*/ | ||
import { ChartProps } from '@superset-ui/chart'; | ||
|
||
const basicFormData = { | ||
alignPn: false, | ||
colorPn: false, | ||
includeSearch: false, | ||
orderDesc: true, | ||
pageLength: 0, | ||
metrics: [], | ||
percentMetrics: null, | ||
timeseriesLimitMetric: null, | ||
tableFilter: false, | ||
tableTimestampFormat: '%Y-%m-%d %H:%M:%S', | ||
}; | ||
|
||
const basicChartProps = { | ||
width: 200, | ||
height: 500, | ||
annotationData: {}, | ||
datasource: { | ||
columnFormats: {}, | ||
verboseMap: {}, | ||
}, | ||
rawDatasource: {}, | ||
rawFormData: {}, | ||
hooks: {}, | ||
initialValues: {}, | ||
queryData: { | ||
data: { | ||
columns: [], | ||
records: [], | ||
}, | ||
}, | ||
formData: basicFormData, | ||
}; | ||
|
||
/** | ||
* Basic data input | ||
*/ | ||
export const basic: ChartProps = { | ||
...basicChartProps, | ||
queryData: { | ||
data: { | ||
columns: ['name', 'sum__num'], | ||
records: [ | ||
{ | ||
name: 'Michael', | ||
sum__num: 2467063, | ||
'%pct_nice': 0.123456, | ||
}, | ||
{ | ||
name: 'Joe', | ||
sum__num: 2467, | ||
'%pct_nice': 0.00001, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
/** | ||
* Advanced data input with | ||
* - verbose map | ||
* - metric columns | ||
*/ | ||
export const advanced: ChartProps = { | ||
...basic, | ||
datasource: { | ||
columnFormats: {}, | ||
verboseMap: { | ||
sum__num: 'Sum of Num', | ||
}, | ||
}, | ||
formData: { | ||
...basicFormData, | ||
metrics: ['sum__num'], | ||
percentMetrics: ['pct_nice'], | ||
}, | ||
queryData: { | ||
data: { | ||
columns: ['name', 'sum__num', '%pct_nice'], | ||
records: [...basic.queryData.data.records], | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use specific import to enable warning if we later do not use some of these.
import { basic, advance } from ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wanted to have a namespace so it's more explicit in later code, but also wanted to keep variable names simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a default export for
testData
. I think it looks better thanimport *
.In the future, maybe all plugins can reuse the same test data---similar to switching visualization type in Superset.