Skip to content

Commit

Permalink
Move table end message to generic component
Browse files Browse the repository at this point in the history
  • Loading branch information
adhityamamallan committed Dec 6, 2024
1 parent fe91339 commit 31cf77b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {

import { render, screen, act, fireEvent } from '@/test-utils/rtl';

import DomainWorkflowsTableEndMessage from '../domain-workflows-table-end-message';
import { type Props } from '../domain-workflows-table-end-message.types';
import TableInfiniteScrollLoader from '../table-infinite-scroll-loader';
import { type Props } from '../table-infinite-scroll-loader.types';

describe(DomainWorkflowsTableEndMessage.name, () => {
describe(TableInfiniteScrollLoader.name, () => {
it('renders loading state while fetching next page', () => {
setup({ isFetchingNextPage: true });

Expand All @@ -29,7 +29,7 @@ describe(DomainWorkflowsTableEndMessage.name, () => {
expect(mockFetchNextPage).toHaveBeenCalled();
});

it('renders loading state with the infinite scroll ref when more workflows can be loaded', () => {
it('renders loading state with the infinite scroll ref when more data can be loaded', () => {
const { mockFetchNextPage } = setup({
hasNextPage: true,
isFetchingNextPage: false,
Expand All @@ -47,13 +47,13 @@ describe(DomainWorkflowsTableEndMessage.name, () => {
});

it('renders end message when there are workflows', () => {
setup({ hasWorkflows: true, hasNextPage: false });
setup({ hasData: true, hasNextPage: false });

expect(screen.getByText('End of results')).toBeInTheDocument();
});

it('renders end message when there are no workflows', () => {
setup({ hasWorkflows: false, hasNextPage: false });
it('renders end message when there is no data', () => {
setup({ hasData: false, hasNextPage: false });

expect(screen.getByText('No results')).toBeInTheDocument();
});
Expand All @@ -62,14 +62,14 @@ describe(DomainWorkflowsTableEndMessage.name, () => {
function setup(overrides: Partial<Props>) {
const mockFetchNextPage = jest.fn();
const defaultProps: Props = {
hasWorkflows: true,
hasData: true,
error: null,
fetchNextPage: mockFetchNextPage,
hasNextPage: true,
isFetchingNextPage: false,
};

render(<DomainWorkflowsTableEndMessage {...defaultProps} {...overrides} />);
render(<TableInfiniteScrollLoader {...defaultProps} {...overrides} />);

return { mockFetchNextPage };
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import React from 'react';
import { Spinner } from 'baseui/spinner';
import { InView } from 'react-intersection-observer';

import { styled } from './domain-workflows-table-end-message.styles';
import { type Props } from './domain-workflows-table-end-message.types';
import { styled } from './table-infinite-scroll-loader.styles';
import { type Props } from './table-infinite-scroll-loader.types';

export default function DomainWorkflowsTableEndMessage(props: Props) {
export default function TableInfiniteScrollLoader(props: Props) {
if (props.isFetchingNextPage) {
return <Spinner data-testid="loading-spinner" />;
}
Expand Down Expand Up @@ -42,7 +42,7 @@ export default function DomainWorkflowsTableEndMessage(props: Props) {
);
}

if (props.hasWorkflows) {
if (props.hasData) {
return (
<styled.EndMessageContainer>End of results</styled.EndMessageContainer>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type Props = {
hasWorkflows: boolean;
hasData: boolean;
error: Error | null;
fetchNextPage: () => void;
hasNextPage: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { HttpResponse } from 'msw';

import { render, screen, userEvent, waitFor } from '@/test-utils/rtl';

import { type Props as LoaderProps } from '@/components/table-infinite-scroll-loader/table-infinite-scroll-loader.types';
import * as usePageQueryParamsModule from '@/hooks/use-page-query-params/use-page-query-params';
import { type ListWorkflowsResponse } from '@/route-handlers/list-workflows/list-workflows.types';

import type { Props as MSWMocksHandlersProps } from '../../../../test-utils/msw-mock-handlers/msw-mock-handlers.types';
import { mockDomainWorkflowsQueryParamsValues } from '../../__fixtures__/domain-workflows-query-params';
import { type DomainWorkflowsHeaderInputType } from '../../domain-workflows-header/domain-workflows-header.types';
import { type Props as EndMessageProps } from '../../domain-workflows-table-end-message/domain-workflows-table-end-message.types';
import DomainWorkflowsTable from '../domain-workflows-table';

jest.mock('@/components/error-panel/error-panel', () =>
Expand Down Expand Up @@ -39,10 +39,10 @@ jest.mock('../helpers/get-workflows-error-panel-props', () =>
);

jest.mock(
'../../domain-workflows-table-end-message/domain-workflows-table-end-message',
'@/components/table-infinite-scroll-loader/table-infinite-scroll-loader',
() =>
jest.fn((props: EndMessageProps) => (
<button data-testid="mock-end-message" onClick={props.fetchNextPage}>
jest.fn((props: LoaderProps) => (
<button data-testid="mock-loader" onClick={props.fetchNextPage}>
Mock end message: {props.error ? 'Error' : 'OK'}
</button>
))
Expand Down Expand Up @@ -74,7 +74,7 @@ describe(DomainWorkflowsTable.name, () => {
).toBeInTheDocument();
});

await user.click(screen.getByTestId('mock-end-message'));
await user.click(screen.getByTestId('mock-loader'));

expect(await screen.findByText('Mock end message: OK')).toBeInTheDocument();
Array(10).forEach((_, index) => {
Expand Down Expand Up @@ -126,13 +126,13 @@ describe(DomainWorkflowsTable.name, () => {
).toBeInTheDocument();
});

await user.click(screen.getByTestId('mock-end-message'));
await user.click(screen.getByTestId('mock-loader'));

expect(
await screen.findByText('Mock end message: Error')
).toBeInTheDocument();

await user.click(screen.getByTestId('mock-end-message'));
await user.click(screen.getByTestId('mock-loader'));

expect(await screen.findByText('Mock end message: OK')).toBeInTheDocument();
Array(10).forEach((_, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import React from 'react';
import ErrorPanel from '@/components/error-panel/error-panel';
import SectionLoadingIndicator from '@/components/section-loading-indicator/section-loading-indicator';
import Table from '@/components/table/table';
import TableInfiniteScrollLoader from '@/components/table-infinite-scroll-loader/table-infinite-scroll-loader';
import usePageQueryParams from '@/hooks/use-page-query-params/use-page-query-params';
import domainPageQueryParamsConfig from '@/views/domain-page/config/domain-page-query-params.config';

import domainWorkflowsQueryTableConfig from '../config/domain-workflows-query-table.config';
import domainWorkflowsSearchTableConfig from '../config/domain-workflows-search-table.config';
import { type Props } from '../domain-workflows-table/domain-workflows-table.types';
import DomainWorkflowsTableEndMessage from '../domain-workflows-table-end-message/domain-workflows-table-end-message';
import getNextSortOrder from '../helpers/get-next-sort-order';
import useListWorkflows from '../hooks/use-list-workflows';

Expand Down Expand Up @@ -64,8 +64,8 @@ export default function DomainWorkflowsTable({ domain, cluster }: Props) {
data={workflows}
shouldShowResults={!isLoading && workflows.length > 0}
endMessage={
<DomainWorkflowsTableEndMessage
hasWorkflows={workflows.length > 0}
<TableInfiniteScrollLoader
hasData={workflows.length > 0}
error={error}
fetchNextPage={fetchNextPage}
hasNextPage={hasNextPage}
Expand Down

0 comments on commit 31cf77b

Please sign in to comment.