Skip to content

Commit f26d165

Browse files
Fix queries review comments (#717)
* move loader out * Resolve comments * Rename test
1 parent 5e25c95 commit f26d165

19 files changed

+148
-288
lines changed

src/config/theme/theme-light.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const themeLight = {
1414
backgroundSecondary: '#F3F3F3',
1515
backgroundTertiary: '#E8E8E8',
1616
backgroundWarningLight: '#FDF2DC',
17+
backgroundPositive: '#0E8345',
1718
},
1819
} satisfies DeepPartial<MakeExtendable<Theme>>;
1920

src/views/workflow-queries/workflow-queries-loader/__tests__/workflow-queries-loader.test.tsx renamed to src/views/workflow-queries/__tests__/workflow-queries.test.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import { render, screen, act } from '@/test-utils/rtl';
88
import { type FetchWorkflowQueryTypesResponse } from '@/route-handlers/fetch-workflow-query-types/fetch-workflow-query-types.types';
99
import { type QueryWorkflowResponse } from '@/route-handlers/query-workflow/query-workflow.types';
1010

11-
import WorkflowQueriesLoader from '../workflow-queries-loader';
11+
import WorkflowQueries from '../workflow-queries';
1212

13-
jest.mock('../../workflow-queries-tile/workflow-queries-tile', () =>
13+
jest.mock('../workflow-queries-tile/workflow-queries-tile', () =>
1414
jest.fn(({ name, onClick, runQuery }) => (
1515
<div onClick={onClick}>
1616
<div>Mock tile: {name}</div>
@@ -19,18 +19,16 @@ jest.mock('../../workflow-queries-tile/workflow-queries-tile', () =>
1919
))
2020
);
2121

22-
jest.mock(
23-
'../../workflow-queries-result-json/workflow-queries-result-json',
24-
() =>
25-
jest.fn(({ data }) => (
26-
<div>
27-
<div>Mock JSON</div>
28-
<div>{JSON.stringify(data)}</div>
29-
</div>
30-
))
22+
jest.mock('../workflow-queries-result-json/workflow-queries-result-json', () =>
23+
jest.fn(({ data }) => (
24+
<div>
25+
<div>Mock JSON</div>
26+
<div>{JSON.stringify(data)}</div>
27+
</div>
28+
))
3129
);
3230

33-
describe(WorkflowQueriesLoader.name, () => {
31+
describe(WorkflowQueries.name, () => {
3432
it('renders without error and does not show excluded query type', async () => {
3533
await setup({});
3634

@@ -71,11 +69,14 @@ async function setup({ error }: { error?: boolean }) {
7169

7270
render(
7371
<Suspense>
74-
<WorkflowQueriesLoader
75-
domain="mock-domain"
76-
cluster="mock-cluster"
77-
workflowId="mock-workflow-id"
78-
runId="mock-run-id"
72+
<WorkflowQueries
73+
params={{
74+
domain: 'mock-domain',
75+
cluster: 'mock-cluster',
76+
workflowId: 'mock-workflow-id',
77+
runId: 'mock-run-id',
78+
workflowTab: 'queries',
79+
}}
7980
/>
8081
</Suspense>,
8182
{

src/views/workflow-queries/helpers/__tests__/get-workflow-query-status.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ describe(getWorkflowQueryStatus.name, () => {
1111
expected: WorkflowQueryStatus;
1212
}> = [
1313
{
14-
name: 'returns fetching if isFetching is true',
14+
name: 'returns loading if isFetching is true',
1515
status: 'pending',
1616
isFetching: true,
17-
expected: 'fetching',
17+
expected: 'loading',
1818
},
1919
{
2020
name: 'returns success if query status is success',
@@ -29,10 +29,10 @@ describe(getWorkflowQueryStatus.name, () => {
2929
expected: 'error',
3030
},
3131
{
32-
name: 'returns pending if query status is pending',
32+
name: 'returns idle if query status is pending',
3333
status: 'pending',
3434
isFetching: false,
35-
expected: 'pending',
35+
expected: 'idle',
3636
},
3737
];
3838

src/views/workflow-queries/helpers/get-workflow-query-status.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function getWorkflowQueryStatus({
1010
isFetching: boolean;
1111
}): WorkflowQueryStatus {
1212
if (isFetching) {
13-
return 'fetching';
13+
return 'loading';
1414
}
1515

1616
switch (queryStatus) {
@@ -19,6 +19,6 @@ export default function getWorkflowQueryStatus({
1919
case 'success':
2020
return 'success';
2121
case 'pending':
22-
return 'pending';
22+
return 'idle';
2323
}
2424
}

src/views/workflow-queries/workflow-queries-loader/hooks/use-workflow-queries.ts renamed to src/views/workflow-queries/hooks/use-workflow-queries.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ export default function useWorkflowQueries({
2828
RequestError,
2929
QueryWorkflowResponse,
3030
[
31+
'workflow_query',
3132
{ workflowId: string; runId: string; name: string },
3233
string | undefined,
3334
]
3435
>
3536
>((name) => ({
36-
queryKey: [{ workflowId, runId, name }, inputs[name]] as const,
37-
queryFn: ({ queryKey: [{ name }, input] }) =>
37+
queryKey: [
38+
'workflow_query',
39+
{ workflowId, runId, name },
40+
inputs[name],
41+
] as const,
42+
queryFn: ({ queryKey: [_, { name }, input] }) =>
3843
request(
3944
`/api/domains/${domain}/${cluster}/workflows/${workflowId}/${runId}/query/${name}`,
4045
{

src/views/workflow-queries/workflow-queries-loader/workflow-queries-loader.constants.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/views/workflow-queries/workflow-queries-loader/workflow-queries-loader.tsx

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/views/workflow-queries/workflow-queries-result-json/workflow-queries-result-json.styles.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ export const styled = {
44
ViewContainer: createStyled<'div', { $isError: boolean }>(
55
'div',
66
({ $theme, $isError }) => ({
7-
// TODO: revisit this when PageSection is fixed
8-
minHeight: '50vh',
7+
flex: '1 0 150px',
98
alignSelf: 'stretch',
109
display: 'flex',
1110
flexDirection: 'row',

src/views/workflow-queries/workflow-queries-result-json/workflow-queries-result-json.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ export default function WorkflowQueriesResultJson(props: Props) {
4343
content={() => <>Copied</>}
4444
>
4545
<Button
46-
// TODO: Add overrides for the copy button so that
47-
// it sticks to the top right when the window is resized
4846
onClick={() => {
4947
copy(JSON.stringify(content, null, '\t'));
5048
setShowTooltip(true);
Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import React from 'react';
22

3-
import { render } from '@/test-utils/rtl';
3+
import { render, screen } from '@/test-utils/rtl';
44

55
import { type WorkflowQueryStatus } from '../../workflow-queries-tile/workflow-queries-tile.types';
66
import WorkflowQueriesStatusIcon from '../workflow-queries-status-icon';
77

8+
jest.mock('react-icons/md', () => ({
9+
...jest.requireActual('react-icons/md'),
10+
MdWarning: () => <div>Warning Icon</div>,
11+
MdCheckCircle: () => <div>Circle Check Icon</div>,
12+
}));
13+
14+
jest.mock('baseui/spinner', () => ({
15+
Spinner: jest.fn(() => <div>Spinner</div>),
16+
}));
17+
818
describe(WorkflowQueriesStatusIcon.name, () => {
919
afterEach(() => {
1020
jest.clearAllMocks();
@@ -13,33 +23,37 @@ describe(WorkflowQueriesStatusIcon.name, () => {
1323
const tests: Array<{
1424
name: string;
1525
status: WorkflowQueryStatus;
26+
expected: string | null;
1627
}> = [
1728
{
18-
name: 'should render correctly for fetching status',
19-
status: 'fetching',
29+
name: 'should render correctly for loading status',
30+
status: 'loading',
31+
expected: 'Spinner',
2032
},
2133
{
2234
name: 'should render correctly for success status',
2335
status: 'success',
36+
expected: 'Circle Check Icon',
2437
},
2538
{
2639
name: 'should render correctly for error status',
2740
status: 'error',
41+
expected: 'Warning Icon',
2842
},
2943
{
30-
name: 'should render null for pending status',
31-
status: 'pending',
44+
name: 'should render null for idle status',
45+
status: 'idle',
46+
expected: null,
3247
},
3348
];
3449

3550
tests.forEach((test) => {
3651
it(test.name, () => {
37-
const { container } = render(
38-
<WorkflowQueriesStatusIcon status={test.status} />,
39-
{ isSnapshotTest: true }
40-
);
52+
render(<WorkflowQueriesStatusIcon status={test.status} />);
4153

42-
expect(container).toMatchSnapshot();
54+
if (test.expected) {
55+
expect(screen.getByText(test.expected)).toBeInTheDocument();
56+
}
4357
});
4458
});
4559
});

0 commit comments

Comments
 (0)