-
Notifications
You must be signed in to change notification settings - Fork 16.6k
test: DatasourceControl #13605
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
Merged
Merged
test: DatasourceControl #13605
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
50a5345
Tests for DatasourceControl
yardz aa1732d
fix: lint error
yardz a69b3e6
Update superset-frontend/src/explore/components/controls/DatasourceCo…
yardz d9a4e6d
Update superset-frontend/src/explore/components/controls/DatasourceCo…
yardz 4cba16f
Update superset-frontend/src/explore/components/controls/DatasourceCo…
yardz afee3ed
Remove error comment
yardz 5fb2810
Merge remote-tracking branch 'apache/master' into test-DatasourceControl
yardz 95dda98
replace component data-test
yardz 48631c8
Merge remote-tracking branch 'apache/master' into test-DatasourceControl
yardz 31433ed
factory to props
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
147 changes: 147 additions & 0 deletions
147
...set-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
This file contains hidden or 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,147 @@ | ||
| /** | ||
| * 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, act } from 'spec/helpers/testing-library'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { SupersetClient } from '@superset-ui/core'; | ||
| import * as Utils from 'src/explore/exploreUtils'; | ||
| import DatasourceControl from '.'; | ||
|
|
||
| const SupersetClientGet = jest.spyOn(SupersetClient, 'get'); | ||
|
|
||
| const createProps = () => ({ | ||
| hovered: false, | ||
| type: 'DatasourceControl', | ||
| label: 'Datasource', | ||
| default: null, | ||
| description: null, | ||
| value: '25__table', | ||
| datasource: { | ||
| id: 25, | ||
| database: { | ||
| name: 'examples', | ||
| }, | ||
| name: 'channels', | ||
| type: 'table', | ||
| columns: [], | ||
| }, | ||
| validationErrors: [], | ||
| name: 'datasource', | ||
| actions: {}, | ||
| isEditable: true, | ||
| onChange: jest.fn(), | ||
| onDatasourceSave: jest.fn(), | ||
| }); | ||
|
|
||
| test('Should render', () => { | ||
| const props = createProps(); | ||
| render(<DatasourceControl {...props} />); | ||
| expect(screen.getByTestId('datasource-control')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Should have elements', () => { | ||
| const props = createProps(); | ||
| render(<DatasourceControl {...props} />); | ||
| expect(screen.getByText('channels')).toBeVisible(); | ||
| expect(screen.getByTestId('datasource-menu-trigger')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Should open a menu', () => { | ||
| const props = createProps(); | ||
| render(<DatasourceControl {...props} />); | ||
|
|
||
| expect(screen.queryByText('Edit dataset')).not.toBeInTheDocument(); | ||
| expect(screen.queryByText('Change dataset')).not.toBeInTheDocument(); | ||
| expect(screen.queryByText('View in SQL Lab')).not.toBeInTheDocument(); | ||
|
|
||
| userEvent.click(screen.getByTestId('datasource-menu-trigger')); | ||
|
|
||
| expect(screen.getByText('Edit dataset')).toBeInTheDocument(); | ||
| expect(screen.getByText('Change dataset')).toBeInTheDocument(); | ||
| expect(screen.getByText('View in SQL Lab')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('Click on Change dataset option', async () => { | ||
| const props = createProps(); | ||
| SupersetClientGet.mockImplementation( | ||
| async ({ endpoint }: { endpoint: string }) => { | ||
| if (endpoint.includes('_info')) { | ||
| return { | ||
| json: { permissions: ['can_read', 'can_write'] }, | ||
| } as any; | ||
| } | ||
| return { json: { result: [] } } as any; | ||
| }, | ||
| ); | ||
|
|
||
| render(<DatasourceControl {...props} />, { | ||
| useRedux: true, | ||
| }); | ||
| userEvent.click(screen.getByTestId('datasource-menu-trigger')); | ||
|
|
||
| await act(async () => { | ||
| userEvent.click(screen.getByText('Change dataset')); | ||
| }); | ||
| expect( | ||
| screen.getByText( | ||
| 'Changing the dataset may break the chart if the chart relies on columns or metadata that does not exist in the target dataset', | ||
| ), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('Click on Edit dataset', async () => { | ||
| const props = createProps(); | ||
| SupersetClientGet.mockImplementation( | ||
| async () => ({ json: { result: [] } } as any), | ||
| ); | ||
| render(<DatasourceControl {...props} />, { | ||
| useRedux: true, | ||
| }); | ||
| userEvent.click(screen.getByTestId('datasource-menu-trigger')); | ||
|
|
||
| await act(async () => { | ||
| userEvent.click(screen.getByText('Edit dataset')); | ||
| }); | ||
yardz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| expect( | ||
| screen.getByText( | ||
| 'Changing these settings will affect all charts using this dataset, including charts owned by other people.', | ||
| ), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('Click on View in SQL Lab', async () => { | ||
| const props = createProps(); | ||
| const postFormSpy = jest.spyOn(Utils, 'postForm'); | ||
| postFormSpy.mockImplementation(jest.fn()); | ||
|
|
||
| render(<DatasourceControl {...props} />, { | ||
| useRedux: true, | ||
| }); | ||
| userEvent.click(screen.getByTestId('datasource-menu-trigger')); | ||
|
|
||
| expect(postFormSpy).toBeCalledTimes(0); | ||
|
|
||
| await act(async () => { | ||
| userEvent.click(screen.getByText('View in SQL Lab')); | ||
| }); | ||
yardz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| expect(postFormSpy).toBeCalledTimes(1); | ||
| }); | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.