-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: DataTableControl #13668
Merged
Merged
test: DataTableControl #13668
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b379b9b
Tests for DataTableControl
yardz 3077dfe
Merge remote-tracking branch 'apache/master' into test-DataTableControl
yardz 7ce3626
Update superset-frontend/src/explore/components/DataTableControl/RowC…
yardz a066777
Update superset-frontend/src/explore/components/DataTableControl/RowC…
yardz 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
28 changes: 28 additions & 0 deletions
28
superset-frontend/src/explore/components/DataTableControl/CopyButton.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,28 @@ | ||
/** | ||
* 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 { render, screen } from 'spec/helpers/testing-library'; | ||
|
||
import { CopyButton } from '.'; | ||
|
||
test('Render a button', () => { | ||
render(<CopyButton>btn</CopyButton>); | ||
expect(screen.getByRole('button')).toBeInTheDocument(); | ||
expect(screen.getByRole('button')).toHaveClass('superset-button'); | ||
}); |
41 changes: 41 additions & 0 deletions
41
superset-frontend/src/explore/components/DataTableControl/CopyToClipboardButton.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,41 @@ | ||
/** | ||
* 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 userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
import { render, screen } from 'spec/helpers/testing-library'; | ||
import { CopyToClipboardButton } from '.'; | ||
|
||
test('Render a button', () => { | ||
render(<CopyToClipboardButton data={{ copy: 'data', data: 'copy' }} />, { | ||
useRedux: true, | ||
}); | ||
expect(screen.getByRole('button')).toBeInTheDocument(); | ||
}); | ||
|
||
test('Should copy to clipboard', () => { | ||
document.execCommand = jest.fn(); | ||
|
||
render(<CopyToClipboardButton data={{ copy: 'data', data: 'copy' }} />, { | ||
useRedux: true, | ||
}); | ||
|
||
expect(document.execCommand).toHaveBeenCalledTimes(0); | ||
userEvent.click(screen.getByRole('button')); | ||
expect(document.execCommand).toHaveBeenCalledWith('copy'); | ||
}); |
37 changes: 37 additions & 0 deletions
37
superset-frontend/src/explore/components/DataTableControl/FilterInput.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,37 @@ | ||
/** | ||
* 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 userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
import { render, screen } from 'spec/helpers/testing-library'; | ||
import { FilterInput } from '.'; | ||
|
||
jest.mock('lodash/debounce', () => ({ | ||
__esModule: true, | ||
default: (fuc: Function) => fuc, | ||
})); | ||
|
||
test('Render a FilterInput', async () => { | ||
const onChangeHandler = jest.fn(); | ||
render(<FilterInput onChangeHandler={onChangeHandler} />); | ||
|
||
expect(onChangeHandler).toBeCalledTimes(0); | ||
userEvent.type(screen.getByRole('textbox'), 'test'); | ||
|
||
expect(onChangeHandler).toBeCalledTimes(4); | ||
}); |
31 changes: 31 additions & 0 deletions
31
superset-frontend/src/explore/components/DataTableControl/RowCount.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,31 @@ | ||
/** | ||
* 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 { render, screen } from 'spec/helpers/testing-library'; | ||
import { RowCount } from '.'; | ||
|
||
test('Render a RowCount', async () => { | ||
yardz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
render(<RowCount data={[{}, {}, {}]} loading={false} />); | ||
expect(screen.getByText('3 rows retrieved')).toBeInTheDocument(); | ||
}); | ||
|
||
test('Render a RowCount on loading', async () => { | ||
yardz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
render(<RowCount data={[{}, {}, {}]} loading />); | ||
expect(screen.getByText('Loading...')).toBeInTheDocument(); | ||
}); |
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
57 changes: 57 additions & 0 deletions
57
superset-frontend/src/explore/components/DataTableControl/useFilteredTableData.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,57 @@ | ||
/** | ||
* 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 { renderHook } from '@testing-library/react-hooks'; | ||
import { useFilteredTableData } from '.'; | ||
|
||
const data = [ | ||
{ col01: 'some', col02: 'data' }, | ||
{ col01: 'any', col02: 'data' }, | ||
{ col01: 'some', col02: 'thing' }, | ||
{ col01: 'any', col02: 'things' }, | ||
]; | ||
|
||
test('Empty filter', () => { | ||
const hook = renderHook(() => useFilteredTableData('', data)); | ||
expect(hook.result.current).toEqual(data); | ||
}); | ||
|
||
test('Filter by the word "data"', () => { | ||
const hook = renderHook(() => useFilteredTableData('data', data)); | ||
expect(hook.result.current).toEqual([ | ||
{ col01: 'some', col02: 'data' }, | ||
{ col01: 'any', col02: 'data' }, | ||
]); | ||
}); | ||
|
||
test('Filter by the word "thing"', () => { | ||
const hook = renderHook(() => useFilteredTableData('thing', data)); | ||
expect(hook.result.current).toEqual([ | ||
{ col01: 'some', col02: 'thing' }, | ||
{ col01: 'any', col02: 'things' }, | ||
]); | ||
}); | ||
|
||
test('Filter by the word "any"', () => { | ||
const hook = renderHook(() => useFilteredTableData('any', data)); | ||
expect(hook.result.current).toEqual([ | ||
{ col01: 'any', col02: 'data' }, | ||
{ col01: 'any', col02: 'things' }, | ||
]); | ||
}); |
64 changes: 64 additions & 0 deletions
64
superset-frontend/src/explore/components/DataTableControl/useTableColumns.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,64 @@ | ||
/** | ||
* 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 { renderHook } from '@testing-library/react-hooks'; | ||
import { useTableColumns } from '.'; | ||
|
||
const data = [ | ||
{ col01: 'some', col02: 'data' }, | ||
{ col01: 'any', col02: 'data' }, | ||
{ col01: 'some', col02: 'thing' }, | ||
{ col01: 'any', col02: 'things', col03: 'secret' }, | ||
]; | ||
|
||
test('useTableColumns with no options', () => { | ||
const hook = renderHook(() => useTableColumns(data)); | ||
expect(hook.result.current).toEqual([ | ||
{ Cell: expect.any(Function), Header: 'col01', accessor: 'col01' }, | ||
{ Cell: expect.any(Function), Header: 'col02', accessor: 'col02' }, | ||
]); | ||
}); | ||
|
||
test('use only the first record columns', () => { | ||
const hook = renderHook(() => useTableColumns(data)); | ||
expect(hook.result.current).toEqual([ | ||
{ Cell: expect.any(Function), Header: 'col01', accessor: 'col01' }, | ||
{ Cell: expect.any(Function), Header: 'col02', accessor: 'col02' }, | ||
]); | ||
|
||
const hook2 = renderHook(() => useTableColumns([data[3], data[0]])); | ||
expect(hook2.result.current).toEqual([ | ||
{ Cell: expect.any(Function), Header: 'col01', accessor: 'col01' }, | ||
{ Cell: expect.any(Function), Header: 'col02', accessor: 'col02' }, | ||
{ Cell: expect.any(Function), Header: 'col03', accessor: 'col03' }, | ||
]); | ||
}); | ||
|
||
test('useTableColumns with options', () => { | ||
const hook = renderHook(() => useTableColumns(data, { col01: { id: 'ID' } })); | ||
expect(hook.result.current).toEqual([ | ||
{ | ||
Cell: expect.any(Function), | ||
Header: 'col01', | ||
accessor: 'col01', | ||
id: 'ID', | ||
}, | ||
{ Cell: expect.any(Function), Header: 'col02', accessor: 'col02' }, | ||
]); | ||
}); |
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.
Just out of curiosity, why do you think checking the class here would benefit the tests?
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.
It doesn't really add much value. It’s just because a test that just checks that it’s a button doesn’t add much... At least with the class I check if "added the correct button"