Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions openmetadata-ui/src/main/resources/ui/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ module.exports = {
'<rootDir>/src/test/unit/mocks/reactColumnResize.mock.js',
'^.*/Lineage/Layout/ELKUtil/ELKUtil$':
'<rootDir>/src/test/unit/mocks/elkLayout.mock.js',
'^codemirror(/.*)?$': '<rootDir>/src/test/unit/mocks/file.mock.js',
'^react-codemirror2$': '<rootDir>/src/test/unit/mocks/file.mock.js',
Comment thread
satender-kumar-collate marked this conversation as resolved.
'^.*/AppRouter/withSuspenseFallback$':
'<rootDir>/src/test/unit/mocks/withSuspenseFallback.mock.tsx',
// Force every `require('react')` / `require('react-dom')` to resolve to the consumer's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,69 @@ test.describe(
}
);

test.describe(
'Explore Search Count Visibility',
{ tag: ['@explore-search-count'] },
() => {
test.beforeEach(async ({ page }) => {
await redirectToHomePage(page);
await sidebarClick(page, SidebarItem.EXPLORE);
await waitForAllLoadersToDisappear(page);
});

test('Verify count shows with Advanced Search filter', async ({ page }) => {
await test.step('Open Advanced Search', async () => {
await showAdvancedSearchDialog(page);
});

await test.step('Apply Description Contains filter', async () => {
await fillRule(page, {
condition: 'Contains',
field: { id: 'Description', name: 'description' },
searchCriteria: 'test',
index: 1,
});

const searchRes = page.waitForResponse(
'/api/v1/search/query?*index=dataAsset*'
);

await page.getByTestId('apply-btn').click();

await searchRes;
await waitForAllLoadersToDisappear(page);
});

await test.step('Verify count is visible', async () => {
await expect(page.getByTestId('search-results-count')).toBeVisible();
});

await test.step('Clear filters and verify count disappears', async () => {
await page.getByTestId('clear-filters').click();
await waitForAllLoadersToDisappear(page);

await expect(
page.getByTestId('search-results-count')
).not.toBeVisible();
});
});

test('Verify browse mode has no count', async ({ page }) => {
await test.step('Verify no search and no filters are applied', async () => {
await expect(
page.getByTestId('advance-search-filter-container')
).not.toBeVisible();
});

await test.step('Verify count is not visible', async () => {
await expect(
page.getByTestId('search-results-count')
).not.toBeVisible();
});
});
}
);

const COLUMN_TAG_FIELD = {
id: 'Column Tags',
name: 'columns.tags.tagFQN',
Expand Down Expand Up @@ -1016,7 +1079,6 @@ test.describe(
columnTagTable2.create(apiContext),
]);

// table1 column gets tag1; table2 column gets tag2
await columnTagTable1.patch({
apiContext,
patchData: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ export class UserClass {
userName = this.data.email,
password = this.data.password
) {
await page.goto('/');
await page.goto('/', { waitUntil: 'domcontentloaded' });
try {
await page.waitForURL('**/signin', { timeout: 5000 });
} catch {
await page.context().clearCookies();
await page.goto('/signin');
await page.goto('/signin', { waitUntil: 'domcontentloaded' });
await page.waitForURL('**/signin');
}
await page.waitForLoadState('domcontentloaded');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { AdminClass } from '../support/user/AdminClass';
import { getAuthContext, getToken, redirectToHomePage } from './common';

export const authenticateAdminPage = async (page: Page) => {
await page.goto('/');
await page.goto('/', { waitUntil: 'domcontentloaded' });
await page.waitForURL((url) => {
return (
url.pathname.includes('/my-data') || url.pathname.includes('/signin')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ const ExploreV1: React.FC<ExploreProps> = ({
() => Boolean(searchQueryParam),
[searchQueryParam]
);
const hasActiveFilters = useMemo(
() => Boolean(queryFilter || quickFilters || sqlQuery || searchQueryParam),
[queryFilter, quickFilters, sqlQuery, searchQueryParam]
);
const pageResultCount = useMemo(
() => searchResults?.hits?.hits?.length ?? 0,
[searchResults]
Expand Down Expand Up @@ -652,12 +656,13 @@ const ExploreV1: React.FC<ExploreProps> = ({
<Card className="h-full tw:flex-1 explore-main-card">
{!loading && !isElasticSearchIssue ? (
<SearchedData
isFilterSelected
data={searchResults?.hits.hits ?? []}
filter={parsedSearch}
handleSummaryPanelDisplay={handleSummaryPanelDisplay}
isFilterSelected={hasActiveFilters}
isSummaryPanelVisible={showSummaryPanel}
selectedEntityId={entityDetails?.id || ''}
showResultCount={hasActiveFilters}
totalValue={searchResults?.hits.total.value ?? 0}
onPaginationChange={onChangePage}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
waitFor,
within,
} from '@testing-library/react';
import { useAdvanceSearch } from '../../components/Explore/AdvanceSearchProvider/AdvanceSearchProvider.component';
import { SearchIndex } from '../../enums/search.enum';
import {
exportSearchResultsCsvStream,
Expand All @@ -29,6 +30,7 @@ import {
} from '../Explore/Explore.mock';
import { ExploreSearchIndex } from '../Explore/ExplorePage.interface';
import ExploreTree from '../Explore/ExploreTree/ExploreTree';
import SearchedData from '../SearchedData/SearchedData';
import ExploreV1 from './ExploreV1.component';

jest.mock('@openmetadata/ui-core-components', () => {
Expand Down Expand Up @@ -568,4 +570,54 @@ describe('ExploreV1', () => {
).toBeInTheDocument();
expect(exportButton).toBeDisabled();
});

it('passes showResultCount=true to SearchedData when quickFilters is active', () => {
render(<ExploreV1 {...props} />, { wrapper: Wrapper });

const lastCall = (SearchedData as jest.Mock).mock.calls.at(-1)?.[0];

expect(lastCall).toEqual(
expect.objectContaining({ showResultCount: true })
);
});

it('passes showResultCount=false to SearchedData when no filters are active', () => {
(useAdvanceSearch as jest.Mock).mockReturnValueOnce({
toggleModal: jest.fn(),
sqlQuery: '',
queryFilter: undefined,
onResetAllFilters: jest.fn(),
});

render(<ExploreV1 {...props} quickFilters={undefined} />, {
wrapper: Wrapper,
});

const lastCall = (SearchedData as jest.Mock).mock.calls.at(-1)?.[0];

expect(lastCall).toEqual(
expect.objectContaining({ showResultCount: false })
);
});

it('passes showResultCount=true to SearchedData when advanced search queryFilter is active', () => {
(useAdvanceSearch as jest.Mock).mockImplementation(() => ({
toggleModal: jest.fn(),
sqlQuery: '',
queryFilter: {
query: { bool: { must: [{ term: { 'owner.name': 'alice' } }] } },
},
onResetAllFilters: jest.fn(),
}));

render(<ExploreV1 {...props} quickFilters={undefined} />, {
wrapper: Wrapper,
});

const lastCall = (SearchedData as jest.Mock).mock.calls.at(-1)?.[0];

expect(lastCall).toEqual(
expect.objectContaining({ showResultCount: true })
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ export const GlobalSearchBar = () => {

const handleClear = () => {
setSearchValue('');
if (pathname.startsWith('/explore')) {
navigate(getExplorePath({ search: '', isPersistFilters: true }));
}
};

const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import {
getAllByTestId,
getByTestId,
getByText,
queryByTestId,
render,
} from '@testing-library/react';
import { PropsWithChildren } from 'react';
import { MemoryRouter } from 'react-router';
import { MAX_RESULT_HITS } from '../../constants/explore.constants';
import { TAG_CONSTANT } from '../../constants/Tag.constants';
import { SearchIndex } from '../../enums/search.enum';
import SearchedData from './SearchedData';
Expand Down Expand Up @@ -237,4 +239,49 @@ describe('Test SearchedData Component', () => {
'label.matches:1 label.in-lowercase Name,1 label.in-lowercase Display Name'
);
});

it('Should not show result count when showResultCount is false', () => {
const { container } = render(
<SearchedData {...MOCK_PROPS} isFilterSelected showResultCount={false} />,
{ wrapper: TestWrapper }
);

expect(
queryByTestId(container, 'search-results-count')
).not.toBeInTheDocument();
});

it('Should show result count when showResultCount is true and isFilterSelected is true', () => {
const { container } = render(
<SearchedData
{...MOCK_PROPS}
isFilterSelected
showResultCount
totalValue={42}
/>,
{ wrapper: TestWrapper }
);

const countEl = getByTestId(container, 'search-results-count');

expect(countEl).toBeInTheDocument();
expect(countEl).toHaveTextContent('42 results');
});

it('Should show "About X results" when totalValue equals MAX_RESULT_HITS', () => {
const { container } = render(
<SearchedData
{...MOCK_PROPS}
isFilterSelected
showResultCount
totalValue={MAX_RESULT_HITS}
/>,
{ wrapper: TestWrapper }
);

const countEl = getByTestId(container, 'search-results-count');

expect(countEl).toBeInTheDocument();
expect(countEl).toHaveTextContent(`About ${MAX_RESULT_HITS} results`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@ const SearchedData: React.FC<SearchedDataProps> = ({
const resultCount = useMemo(() => {
if (isFilterSelected || filter?.quickFilter) {
if (MAX_RESULT_HITS === totalValue) {
return <div>{`About ${totalValue} results`}</div>;
return (
<div data-testid="search-results-count">{`About ${totalValue} results`}</div>
);
} else {
return <div>{pluralize(totalValue, 'result')}</div>;
return (
<div data-testid="search-results-count">
{pluralize(totalValue, 'result')}
</div>
);
}
} else {
return null;
Expand Down
Loading