Skip to content

Commit

Permalink
Change impl
Browse files Browse the repository at this point in the history
  • Loading branch information
adhityamamallan committed Nov 25, 2024
1 parent 2c40bae commit 0b7a372
Show file tree
Hide file tree
Showing 23 changed files with 396 additions and 667 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,36 @@ jest.mock('@/components/page-filters/hooks/use-page-filters', () =>
}))
);

jest.mock('../../hooks/use-list-workflows', () =>
jest.fn(() => ({
refetch: jest.fn(),
}))
);

describe(DomainWorkflowsHeader.name, () => {
it('renders segmented control', async () => {
render(<DomainWorkflowsHeader />);
render(
<DomainWorkflowsHeader domain="mock_domain" cluster="mock_cluster" />
);

expect(await screen.findByText('Search')).toBeInTheDocument();
expect(await screen.findByText('Query')).toBeInTheDocument();
});

it('renders page search and filters button when input type is search', async () => {
render(<DomainWorkflowsHeader />);
render(
<DomainWorkflowsHeader domain="mock_domain" cluster="mock_cluster" />
);

expect(await screen.findByText('Filter search')).toBeInTheDocument();
expect(await screen.findByText('Filter toggle')).toBeInTheDocument();
});

it('renders page filters when filter toggle is clicked', async () => {
const user = userEvent.setup();
render(<DomainWorkflowsHeader />);
render(
<DomainWorkflowsHeader domain="mock_domain" cluster="mock_cluster" />
);

const filterToggle = await screen.findByText('Filter toggle');
await user.click(filterToggle);
Expand All @@ -77,14 +89,18 @@ describe(DomainWorkflowsHeader.name, () => {
setQueryParams: mockSetQueryParams,
});

render(<DomainWorkflowsHeader />);
render(
<DomainWorkflowsHeader domain="mock_domain" cluster="mock_cluster" />
);

expect(await screen.findByText('Query')).toBeInTheDocument();
});

it('toggles input type when segmented control is used', async () => {
const user = userEvent.setup();
render(<DomainWorkflowsHeader />);
render(
<DomainWorkflowsHeader domain="mock_domain" cluster="mock_cluster" />
);

const queryButton = await screen.findByText('Search');
await user.click(queryButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import domainPageQueryParamsConfig from '@/views/domain-page/config/domain-page-

import domainWorkflowsFiltersConfig from '../config/domain-workflows-filters.config';
import DomainWorkflowsQueryInput from '../domain-workflows-query-input/domain-workflows-query-input';
import useListWorkflows from '../hooks/use-list-workflows';

import { overrides, styled } from './domain-workflows-header.styles';
import { type Props } from './domain-workflows-header.types';

export default function DomainWorkflowsHeader() {
export default function DomainWorkflowsHeader({ domain, cluster }: Props) {
const [areFiltersShown, setAreFiltersShown] = useState(false);

const { resetAllFilters, activeFiltersCount, queryParams, setQueryParams } =
Expand All @@ -23,6 +25,8 @@ export default function DomainWorkflowsHeader() {
pageQueryParamsConfig: domainPageQueryParamsConfig,
});

const { refetch } = useListWorkflows({ domain, cluster });

return (
<styled.HeaderContainer>
<styled.InputContainer>
Expand Down Expand Up @@ -54,6 +58,7 @@ export default function DomainWorkflowsHeader() {
<DomainWorkflowsQueryInput
value={queryParams.query}
setValue={(v) => setQueryParams({ query: v })}
refetchQuery={refetch}
/>
) : (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ import { type ListWorkflowsRequestQueryParams } from '@/route-handlers/list-work

export type DomainWorkflowsHeaderInputType =
ListWorkflowsRequestQueryParams['inputType'];

export type Props = {
domain: string;
cluster: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,27 @@ describe(DomainWorkflowsQueryInput.name, () => {

expect(mockSetValue).toHaveBeenCalledWith('mock_query');
});

it('calls refetchQuery when the Rerun Query button is clicked', async () => {
const { mockRefetch, user } = setup({ startValue: 'test_query' });

await user.click(await screen.findByText('Rerun Query'));

expect(mockRefetch).toHaveBeenCalled();
});
});

function setup({ startValue }: { startValue?: string }) {
const mockSetValue = jest.fn();
const mockRefetch = jest.fn();
const user = userEvent.setup();
render(
<DomainWorkflowsQueryInput
value={startValue ?? ''}
setValue={mockSetValue}
refetchQuery={mockRefetch}
/>
);

return { mockSetValue, user };
return { mockSetValue, mockRefetch, user };
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { MdPlayArrow, MdCode, MdRefresh } from 'react-icons/md';
import { overrides } from './domain-workflows-query-input.styles';
import { type Props } from './domain-workflows-query-input.types';

export default function DomainWorkflowsQueryInput({ value, setValue }: Props) {
export default function DomainWorkflowsQueryInput({
value,
setValue,
refetchQuery,
}: Props) {
const [queryText, setQueryText] = useState<string>('');

useEffect(() => {
Expand All @@ -30,7 +34,9 @@ export default function DomainWorkflowsQueryInput({ value, setValue }: Props) {
clearOnEscape
/>
<Button
onClick={() => setValue(queryText || undefined)}
onClick={() =>
isQueryUnchanged ? refetchQuery() : setValue(queryText || undefined)
}
overrides={overrides.runButton}
startEnhancer={isQueryUnchanged ? <MdRefresh /> : <MdPlayArrow />}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type Props = {
value: string;
setValue: (v: string | undefined) => void;
refetchQuery: () => void;
};

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0b7a372

Please sign in to comment.