feat: changed name from 'Histogram' to 'Frequency chart' (#5369)

* feat: changed name from 'Histogram' to 'Frequence chart'

* feat: cdoe refactor and test case changes

* feat: added test case for frequency chart
This commit is contained in:
SagarRajput-7 2024-07-08 20:02:10 +05:30 committed by GitHub
parent e6eaaa660a
commit 9c9ed741b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 61 additions and 27 deletions

View File

@ -63,10 +63,10 @@ import { v4 } from 'uuid';
function LogsExplorerViews({ function LogsExplorerViews({
selectedView, selectedView,
showHistogram, showFrequencyChart,
}: { }: {
selectedView: SELECTED_VIEWS; selectedView: SELECTED_VIEWS;
showHistogram: boolean; showFrequencyChart: boolean;
}): JSX.Element { }): JSX.Element {
const { notifications } = useNotifications(); const { notifications } = useNotifications();
const history = useHistory(); const history = useHistory();
@ -561,7 +561,7 @@ function LogsExplorerViews({
return ( return (
<div className="logs-explorer-views-container"> <div className="logs-explorer-views-container">
{showHistogram && ( {showFrequencyChart && (
<LogsExplorerChart <LogsExplorerChart
className="logs-histogram" className="logs-histogram"
isLoading={isFetchingListChartData || isLoadingListChartData} isLoading={isFetchingListChartData || isLoadingListChartData}

View File

@ -76,7 +76,10 @@ const renderer = (): RenderResult =>
<VirtuosoMockContext.Provider <VirtuosoMockContext.Provider
value={{ viewportHeight: 300, itemHeight: 100 }} value={{ viewportHeight: 300, itemHeight: 100 }}
> >
<LogsExplorerViews selectedView={SELECTED_VIEWS.SEARCH} showHistogram /> <LogsExplorerViews
selectedView={SELECTED_VIEWS.SEARCH}
showFrequencyChart
/>
</VirtuosoMockContext.Provider> </VirtuosoMockContext.Provider>
</QueryBuilderProvider> </QueryBuilderProvider>
</MockQueryClientProvider> </MockQueryClientProvider>

View File

@ -10,7 +10,7 @@ interface LeftToolbarActionsProps {
selectedView: string; selectedView: string;
onToggleHistrogramVisibility: () => void; onToggleHistrogramVisibility: () => void;
onChangeSelectedView: (view: SELECTED_VIEWS) => void; onChangeSelectedView: (view: SELECTED_VIEWS) => void;
showHistogram: boolean; showFrequencyChart: boolean;
} }
const activeTab = 'active-tab'; const activeTab = 'active-tab';
@ -22,7 +22,7 @@ export default function LeftToolbarActions({
selectedView, selectedView,
onToggleHistrogramVisibility, onToggleHistrogramVisibility,
onChangeSelectedView, onChangeSelectedView,
showHistogram, showFrequencyChart,
}: LeftToolbarActionsProps): JSX.Element { }: LeftToolbarActionsProps): JSX.Element {
const { clickhouse, search, queryBuilder: QB } = items; const { clickhouse, search, queryBuilder: QB } = items;
@ -71,11 +71,11 @@ export default function LeftToolbarActions({
)} )}
</div> </div>
<div className="histogram-view-controller"> <div className="frequency-chart-view-controller">
<Typography>Histogram</Typography> <Typography>Frequency chart</Typography>
<Switch <Switch
size="small" size="small"
checked={showHistogram} checked={showFrequencyChart}
defaultChecked defaultChecked
onChange={onToggleHistrogramVisibility} onChange={onToggleHistrogramVisibility}
/> />

View File

@ -37,7 +37,7 @@
} }
} }
.histogram-view-controller { .frequency-chart-view-controller {
display: flex; display: flex;
align-items: center; align-items: center;
padding-left: 8px; padding-left: 8px;

View File

@ -8,7 +8,7 @@ import RightToolbarActions from '../RightToolbarActions';
describe('ToolbarActions', () => { describe('ToolbarActions', () => {
it('LeftToolbarActions - renders correctly with default props', async () => { it('LeftToolbarActions - renders correctly with default props', async () => {
const handleChangeSelectedView = jest.fn(); const handleChangeSelectedView = jest.fn();
const handleToggleShowHistogram = jest.fn(); const handleToggleShowFrequencyChart = jest.fn();
const { queryByTestId } = render( const { queryByTestId } = render(
<LeftToolbarActions <LeftToolbarActions
items={{ items={{
@ -32,8 +32,8 @@ describe('ToolbarActions', () => {
}} }}
selectedView={SELECTED_VIEWS.SEARCH} selectedView={SELECTED_VIEWS.SEARCH}
onChangeSelectedView={handleChangeSelectedView} onChangeSelectedView={handleChangeSelectedView}
onToggleHistrogramVisibility={handleToggleShowHistogram} onToggleHistrogramVisibility={handleToggleShowFrequencyChart}
showHistogram showFrequencyChart
/>, />,
); );
expect(screen.getByTestId('search-view')).toBeInTheDocument(); expect(screen.getByTestId('search-view')).toBeInTheDocument();
@ -51,7 +51,7 @@ describe('ToolbarActions', () => {
it('renders - clickhouse view and test histogram toggle', async () => { it('renders - clickhouse view and test histogram toggle', async () => {
const handleChangeSelectedView = jest.fn(); const handleChangeSelectedView = jest.fn();
const handleToggleShowHistogram = jest.fn(); const handleToggleShowFrequencyChart = jest.fn();
const { queryByTestId, getByRole } = render( const { queryByTestId, getByRole } = render(
<LeftToolbarActions <LeftToolbarActions
items={{ items={{
@ -76,8 +76,8 @@ describe('ToolbarActions', () => {
}} }}
selectedView={SELECTED_VIEWS.QUERY_BUILDER} selectedView={SELECTED_VIEWS.QUERY_BUILDER}
onChangeSelectedView={handleChangeSelectedView} onChangeSelectedView={handleChangeSelectedView}
onToggleHistrogramVisibility={handleToggleShowHistogram} onToggleHistrogramVisibility={handleToggleShowFrequencyChart}
showHistogram showFrequencyChart
/>, />,
); );
@ -88,7 +88,7 @@ describe('ToolbarActions', () => {
expect(handleChangeSelectedView).toBeCalled(); expect(handleChangeSelectedView).toBeCalled();
await userEvent.click(getByRole('switch')); await userEvent.click(getByRole('switch'));
expect(handleToggleShowHistogram).toBeCalled(); expect(handleToggleShowFrequencyChart).toBeCalled();
}); });
it('RightToolbarActions - render correctly with props', async () => { it('RightToolbarActions - render correctly with props', async () => {

View File

@ -35,12 +35,14 @@ jest.mock(
return <div>Time Series Chart</div>; return <div>Time Series Chart</div>;
}, },
); );
const frequencyChartContent = 'Frequency chart content';
jest.mock( jest.mock(
'container/LogsExplorerChart', 'container/LogsExplorerChart',
() => () =>
// eslint-disable-next-line func-names, @typescript-eslint/explicit-function-return-type, react/display-name // eslint-disable-next-line func-names, @typescript-eslint/explicit-function-return-type, react/display-name
function () { function () {
return <div>Histogram Chart</div>; return <div>{frequencyChartContent}</div>;
}, },
); );
@ -83,13 +85,13 @@ describe('Logs Explorer Tests', () => {
</MemoryRouter>, </MemoryRouter>,
); );
// check the presence of histogram chart // check the presence of frequency chart content
expect(getByText('Histogram Chart')).toBeInTheDocument(); expect(getByText(frequencyChartContent)).toBeInTheDocument();
// toggle the chart and check it gets removed from the DOM // toggle the chart and check it gets removed from the DOM
const histogramToggle = getByRole('switch'); const histogramToggle = getByRole('switch');
await userEvent.click(histogramToggle); await userEvent.click(histogramToggle);
expect(queryByText('Histogram Chart')).not.toBeInTheDocument(); expect(queryByText(frequencyChartContent)).not.toBeInTheDocument();
// check the presence of search bar and query builder and absence of clickhouse // check the presence of search bar and query builder and absence of clickhouse
const searchView = getByTestId('search-view'); const searchView = getByTestId('search-view');
@ -229,4 +231,33 @@ describe('Logs Explorer Tests', () => {
const aggrInterval = queryAllByText('AGGREGATION INTERVAL'); const aggrInterval = queryAllByText('AGGREGATION INTERVAL');
expect(aggrInterval.length).toBe(2); expect(aggrInterval.length).toBe(2);
}); });
test('frequency chart visibility and switch toggle', async () => {
const { getByRole, queryByText } = render(
<MemoryRouter initialEntries={[logExplorerRoute]}>
<Provider store={store}>
<I18nextProvider i18n={i18n}>
<MockQueryClientProvider>
<QueryBuilderProvider>
<LogsExplorer />,
</QueryBuilderProvider>
</MockQueryClientProvider>
</I18nextProvider>
</Provider>
</MemoryRouter>,
);
// check the presence of Frequency Chart
expect(queryByText('Frequency chart')).toBeInTheDocument();
// check the default state of the histogram toggle
const histogramToggle = getByRole('switch');
expect(histogramToggle).toBeInTheDocument();
expect(histogramToggle).toBeChecked();
expect(queryByText(frequencyChartContent)).toBeInTheDocument();
// toggle the chart and check it gets removed from the DOM
await userEvent.click(histogramToggle);
expect(queryByText(frequencyChartContent)).not.toBeInTheDocument();
});
}); });

View File

@ -16,15 +16,15 @@ import { WrapperStyled } from './styles';
import { SELECTED_VIEWS } from './utils'; import { SELECTED_VIEWS } from './utils';
function LogsExplorer(): JSX.Element { function LogsExplorer(): JSX.Element {
const [showHistogram, setShowHistogram] = useState(true); const [showFrequencyChart, setShowFrequencyChart] = useState(true);
const [selectedView, setSelectedView] = useState<SELECTED_VIEWS>( const [selectedView, setSelectedView] = useState<SELECTED_VIEWS>(
SELECTED_VIEWS.SEARCH, SELECTED_VIEWS.SEARCH,
); );
const { handleRunQuery, currentQuery } = useQueryBuilder(); const { handleRunQuery, currentQuery } = useQueryBuilder();
const handleToggleShowHistogram = (): void => { const handleToggleShowFrequencyChart = (): void => {
setShowHistogram(!showHistogram); setShowFrequencyChart(!showFrequencyChart);
}; };
const handleChangeSelectedView = (view: SELECTED_VIEWS): void => { const handleChangeSelectedView = (view: SELECTED_VIEWS): void => {
@ -78,8 +78,8 @@ function LogsExplorer(): JSX.Element {
items={toolbarViews} items={toolbarViews}
selectedView={selectedView} selectedView={selectedView}
onChangeSelectedView={handleChangeSelectedView} onChangeSelectedView={handleChangeSelectedView}
onToggleHistrogramVisibility={handleToggleShowHistogram} onToggleHistrogramVisibility={handleToggleShowFrequencyChart}
showHistogram={showHistogram} showFrequencyChart={showFrequencyChart}
/> />
} }
rightActions={<RightToolbarActions onStageRunQuery={handleRunQuery} />} rightActions={<RightToolbarActions onStageRunQuery={handleRunQuery} />}
@ -96,7 +96,7 @@ function LogsExplorer(): JSX.Element {
<div className="logs-explorer-views"> <div className="logs-explorer-views">
<LogsExplorerViews <LogsExplorerViews
selectedView={selectedView} selectedView={selectedView}
showHistogram={showHistogram} showFrequencyChart={showFrequencyChart}
/> />
</div> </div>
</div> </div>