mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-04 20:49:54 +00:00
* fix the table query pagination showing incorrect pageSize * added playwright test --------- Co-authored-by: Shrushti Polekar <shrushtipolekar@gmail.com>
This commit is contained in:
parent
77ea2875f7
commit
177dc044e9
@ -281,6 +281,84 @@ test('Verify query duration', async ({ page }) => {
|
|||||||
expect(durationText).toContain('6.199 sec');
|
expect(durationText).toContain('6.199 sec');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Verify Query Pagination', async ({ page, browser }) => {
|
||||||
|
test.slow(true);
|
||||||
|
|
||||||
|
const { apiContext, afterAction } = await createNewPage(browser);
|
||||||
|
|
||||||
|
Array.from({ length: 26 }).forEach(async (_, index) => {
|
||||||
|
await table1.createQuery(
|
||||||
|
apiContext,
|
||||||
|
`select * from table ${table1.entity.name} ${index}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
await redirectToHomePage(page);
|
||||||
|
await table1.visitEntityPageWithCustomSearchBox(page);
|
||||||
|
const queryResponse = page.waitForResponse(
|
||||||
|
'/api/v1/search/query?q=*&index=query_search_index*'
|
||||||
|
);
|
||||||
|
await page.click(`[data-testid="table_queries"]`);
|
||||||
|
await queryResponse;
|
||||||
|
|
||||||
|
await page.waitForSelector('[data-testid="loader"]', {
|
||||||
|
state: 'detached',
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(page.getByTestId('previous')).toBeDisabled();
|
||||||
|
|
||||||
|
const nextResponse = page.waitForResponse(
|
||||||
|
'/api/v1/search/query?q=*&index=query_search_index&from=15&size=15**'
|
||||||
|
);
|
||||||
|
await page.click('[data-testid="next"]');
|
||||||
|
await nextResponse;
|
||||||
|
|
||||||
|
await page.waitForSelector('[data-testid="loader"]', {
|
||||||
|
state: 'detached',
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(page.getByTestId('next')).toBeDisabled();
|
||||||
|
|
||||||
|
const previousResponse = page.waitForResponse(
|
||||||
|
'/api/v1/search/query?q=*&index=query_search_index&from=0&size=15**'
|
||||||
|
);
|
||||||
|
await page.click('[data-testid="previous"]');
|
||||||
|
await previousResponse;
|
||||||
|
|
||||||
|
await page.waitForSelector('[data-testid="loader"]', {
|
||||||
|
state: 'detached',
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(page.getByTestId('previous')).toBeDisabled();
|
||||||
|
|
||||||
|
await expect(page.getByText('15 / page')).toBeVisible();
|
||||||
|
|
||||||
|
// Change page size to 25
|
||||||
|
await page.locator('.ant-pagination-options-size-changer').click();
|
||||||
|
const pageSizeResponse = page.waitForResponse(
|
||||||
|
'/api/v1/search/query?q=*&index=query_search_index&from=0&size=25&query_filter=**'
|
||||||
|
);
|
||||||
|
await page.getByTitle('25 / Page').click();
|
||||||
|
await pageSizeResponse;
|
||||||
|
|
||||||
|
await page.waitForSelector('[data-testid="loader"]', {
|
||||||
|
state: 'detached',
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(page.getByText('25 / page')).toBeVisible();
|
||||||
|
|
||||||
|
// check if the page size list is same as the page size list in the dropdown
|
||||||
|
await page.locator('.ant-pagination-options-size-changer').click();
|
||||||
|
|
||||||
|
// This is to check in the options only 3 sizes are visible.
|
||||||
|
// 15, 25, 50 Derived from locator which is overall and not contain to check the exact text
|
||||||
|
await expect(page.locator('.ant-pagination-options')).toHaveText(
|
||||||
|
'25 / page15255015 / page25 / page50 / page'
|
||||||
|
);
|
||||||
|
|
||||||
|
await afterAction();
|
||||||
|
});
|
||||||
|
|
||||||
test.afterAll(async ({ browser }) => {
|
test.afterAll(async ({ browser }) => {
|
||||||
const { afterAction, apiContext } = await createNewPage(browser);
|
const { afterAction, apiContext } = await createNewPage(browser);
|
||||||
for (const entity of entityData) {
|
for (const entity of entityData) {
|
||||||
|
|||||||
@ -14,11 +14,13 @@
|
|||||||
import {
|
import {
|
||||||
findAllByText,
|
findAllByText,
|
||||||
findByTestId,
|
findByTestId,
|
||||||
|
fireEvent,
|
||||||
render,
|
render,
|
||||||
screen,
|
screen,
|
||||||
} from '@testing-library/react';
|
} from '@testing-library/react';
|
||||||
import { MemoryRouter } from 'react-router-dom';
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import { SearchIndex } from '../../../enums/search.enum';
|
import { SearchIndex } from '../../../enums/search.enum';
|
||||||
|
import { usePaging } from '../../../hooks/paging/usePaging';
|
||||||
import {
|
import {
|
||||||
MOCK_QUERIES,
|
MOCK_QUERIES,
|
||||||
MOCK_QUERIES_ES_DATA,
|
MOCK_QUERIES_ES_DATA,
|
||||||
@ -39,6 +41,16 @@ jest.mock('./TableQueryRightPanel/TableQueryRightPanel.component', () => {
|
|||||||
.fn()
|
.fn()
|
||||||
.mockImplementation(() => <div>TableQueryRightPanel.component</div>);
|
.mockImplementation(() => <div>TableQueryRightPanel.component</div>);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jest.mock('../../PaginationComponent/PaginationComponent', () => {
|
||||||
|
return jest.fn().mockImplementation(({ onChange }) => (
|
||||||
|
<div>
|
||||||
|
PaginationComponent
|
||||||
|
<button onClick={() => onChange(1, 25)}>PaginationComponentButton</button>
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
jest.mock('../../SearchDropdown/SearchDropdown', () => {
|
jest.mock('../../SearchDropdown/SearchDropdown', () => {
|
||||||
return jest
|
return jest
|
||||||
.fn()
|
.fn()
|
||||||
@ -81,6 +93,21 @@ jest.mock('../../../rest/miscAPI', () => ({
|
|||||||
.mockImplementation(() => Promise.resolve({ data: [] })),
|
.mockImplementation(() => Promise.resolve({ data: [] })),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
jest.mock('../../../hooks/paging/usePaging', () => ({
|
||||||
|
usePaging: jest.fn().mockReturnValue({
|
||||||
|
currentPage: 1,
|
||||||
|
pageSize: 25,
|
||||||
|
paging: {
|
||||||
|
currentPage: 1,
|
||||||
|
pageSize: 25,
|
||||||
|
},
|
||||||
|
showPagination: true,
|
||||||
|
handlePageChange: jest.fn(),
|
||||||
|
handlePagingChange: jest.fn(),
|
||||||
|
handlePageSizeChange: jest.fn(),
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
describe('Test TableQueries Component', () => {
|
describe('Test TableQueries Component', () => {
|
||||||
it('Check if TableQueries component has all child elements', async () => {
|
it('Check if TableQueries component has all child elements', async () => {
|
||||||
render(<TableQueries {...mockTableQueriesProp} />, {
|
render(<TableQueries {...mockTableQueriesProp} />, {
|
||||||
@ -132,6 +159,8 @@ describe('Test TableQueries Component', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('If paging count is more than 15, pagination should be visible', async () => {
|
it('If paging count is more than 15, pagination should be visible', async () => {
|
||||||
|
const mockUsePaging = usePaging as jest.Mock;
|
||||||
|
|
||||||
(searchQuery as jest.Mock).mockImplementationOnce(() =>
|
(searchQuery as jest.Mock).mockImplementationOnce(() =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
hits: { total: { value: 16 }, hits: MOCK_QUERIES_ES_DATA },
|
hits: { total: { value: 16 }, hits: MOCK_QUERIES_ES_DATA },
|
||||||
@ -140,8 +169,15 @@ describe('Test TableQueries Component', () => {
|
|||||||
render(<TableQueries {...mockTableQueriesProp} />, {
|
render(<TableQueries {...mockTableQueriesProp} />, {
|
||||||
wrapper: MemoryRouter,
|
wrapper: MemoryRouter,
|
||||||
});
|
});
|
||||||
const pagingComponent = await screen.findByTestId('query-pagination');
|
const pagingComponent = await screen.findByText('PaginationComponent');
|
||||||
|
|
||||||
expect(pagingComponent).toBeInTheDocument();
|
expect(pagingComponent).toBeInTheDocument();
|
||||||
|
|
||||||
|
fireEvent.click(screen.getByText('PaginationComponentButton'));
|
||||||
|
|
||||||
|
const mockHandlePageSizeChange =
|
||||||
|
mockUsePaging.mock.results[0].value.handlePageSizeChange;
|
||||||
|
|
||||||
|
expect(mockHandlePageSizeChange).toHaveBeenCalledWith(25);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -431,10 +431,11 @@ const TableQueries: FC<TableQueriesProp> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const pagingHandler = (currentPage: number) => {
|
const pagingHandler = (currentPage: number, pageSize: number) => {
|
||||||
fetchFilteredQueries({
|
fetchFilteredQueries({
|
||||||
pageNumber: currentPage,
|
pageNumber: currentPage,
|
||||||
});
|
});
|
||||||
|
handlePageSizeChange(pageSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSortFieldChange = (value: string) => {
|
const handleSortFieldChange = (value: string) => {
|
||||||
@ -656,7 +657,6 @@ const TableQueries: FC<TableQueriesProp> = ({
|
|||||||
pageSize={pageSize}
|
pageSize={pageSize}
|
||||||
total={paging.total}
|
total={paging.total}
|
||||||
onChange={pagingHandler}
|
onChange={pagingHandler}
|
||||||
onShowSizeChange={handlePageSizeChange}
|
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user