forked from Powerarena-Limited/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: chart gallery search improvement (apache#14484)
* feat: chart gallery search improvement * test: adding unit test for VizTypeControl * fix: lint errors Co-authored-by: einatnielsen <einat.bertenthal@nielsen.com>
- Loading branch information
1 parent
d406cf7
commit da800e6
Showing
3 changed files
with
128 additions
and
5 deletions.
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
111 changes: 111 additions & 0 deletions
111
superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeControl.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,111 @@ | ||
/** | ||
* 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 { Preset } from '@superset-ui/core'; | ||
import { render, cleanup, screen } from 'spec/helpers/testing-library'; | ||
import { Provider } from 'react-redux'; | ||
import { | ||
getMockStore, | ||
mockStore, | ||
stateWithoutNativeFilters, | ||
} from 'spec/fixtures/mockStore'; | ||
import React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { testWithId } from 'src/utils/testUtils'; | ||
import { | ||
EchartsMixedTimeseriesChartPlugin, | ||
EchartsTimeseriesChartPlugin, | ||
} from '@superset-ui/plugin-chart-echarts/lib'; | ||
import { LineChartPlugin } from '@superset-ui/preset-chart-xy/lib'; | ||
import TimeTableChartPlugin from '../../../../visualizations/TimeTable/TimeTableChartPlugin'; | ||
import VizTypeControl, { VIZ_TYPE_CONTROL_TEST_ID } from './index'; | ||
|
||
jest.useFakeTimers(); | ||
|
||
class MainPreset extends Preset { | ||
constructor() { | ||
super({ | ||
name: 'Legacy charts', | ||
plugins: [ | ||
new LineChartPlugin().configure({ key: 'line' }), | ||
new EchartsTimeseriesChartPlugin().configure({ | ||
key: 'echarts_timeseries', | ||
}), | ||
new TimeTableChartPlugin().configure({ key: 'time_table' }), | ||
new EchartsMixedTimeseriesChartPlugin().configure({ | ||
key: 'mixed_timeseries', | ||
}), | ||
], | ||
}); | ||
} | ||
} | ||
|
||
const getTestId = testWithId<string>(VIZ_TYPE_CONTROL_TEST_ID, true); | ||
|
||
describe('VizTypeControl', () => { | ||
new MainPreset().register(); | ||
const newVizTypeControlProps = { | ||
description: '', | ||
label: '', | ||
name: '', | ||
value: '', | ||
labelType: '', | ||
onChange: jest.fn(), | ||
}; | ||
|
||
const renderWrapper = ( | ||
props = newVizTypeControlProps, | ||
state: object = stateWithoutNativeFilters, | ||
) => | ||
render( | ||
<Provider | ||
store={state ? getMockStore(stateWithoutNativeFilters) : mockStore} | ||
> | ||
<VizTypeControl {...props} /> | ||
</Provider>, | ||
); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('Search visualization type', async () => { | ||
renderWrapper(); | ||
|
||
const visualizations = screen.getByTestId(getTestId('viz-row')); | ||
|
||
expect(visualizations).toHaveTextContent(/Time-series Table/); | ||
expect(visualizations).toHaveTextContent(/Time-series Chart/); | ||
expect(visualizations).toHaveTextContent(/Mixed timeseries chart/); | ||
expect(visualizations).toHaveTextContent(/Line Chart/); | ||
|
||
const searchInputText = 'time series'; | ||
|
||
// search | ||
userEvent.type( | ||
screen.getByTestId(getTestId('search-input')), | ||
searchInputText, | ||
); | ||
|
||
expect(visualizations).toHaveTextContent(/Time-series Table/); | ||
expect(visualizations).toHaveTextContent(/Time-series Chart/); | ||
expect(visualizations).toHaveTextContent(/Mixed timeseries chart/); | ||
expect(visualizations).not.toHaveTextContent(/Line Chart/); | ||
}); | ||
}); |
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