|
| 1 | +import React from 'react'; |
| 2 | + |
| 3 | +import { render, screen, userEvent } from '@/test-utils/rtl'; |
| 4 | + |
| 5 | +import { mockWorkflowDiagnosticsIssueGroups } from '../../__fixtures__/mock-workflow-diagnostics-issue-groups'; |
| 6 | +import WorkflowDiagnosticsIssue from '../workflow-diagnostics-issue'; |
| 7 | +import { type Props } from '../workflow-diagnostics-issue.types'; |
| 8 | + |
| 9 | +jest.mock( |
| 10 | + '../../workflow-diagnostics-metadata-table/workflow-diagnostics-metadata-table', |
| 11 | + () => { |
| 12 | + return function MockWorkflowDiagnosticsMetadataTable({ metadata }: any) { |
| 13 | + return ( |
| 14 | + <div data-testid="workflow-diagnostics-metadata-table"> |
| 15 | + {JSON.stringify(metadata)} |
| 16 | + </div> |
| 17 | + ); |
| 18 | + }; |
| 19 | + } |
| 20 | +); |
| 21 | + |
| 22 | +const mockIssue = mockWorkflowDiagnosticsIssueGroups[1][1].issues[0]; |
| 23 | +const mockRootCauses = |
| 24 | + mockWorkflowDiagnosticsIssueGroups[1][1].rootCauses.slice(0, 1); |
| 25 | + |
| 26 | +describe(WorkflowDiagnosticsIssue.name, () => { |
| 27 | + afterEach(() => { |
| 28 | + jest.clearAllMocks(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('renders issue header with correct content', () => { |
| 32 | + setup({}); |
| 33 | + |
| 34 | + expect(screen.getByText('Activity Failed')).toBeInTheDocument(); |
| 35 | + expect(screen.getByText('Details')).toBeInTheDocument(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('shows content when expanded', () => { |
| 39 | + setup({ isExpanded: true }); |
| 40 | + |
| 41 | + expect( |
| 42 | + screen.getByText( |
| 43 | + 'The failure is because of an error returned from the service code' |
| 44 | + ) |
| 45 | + ).toBeInTheDocument(); |
| 46 | + }); |
| 47 | + |
| 48 | + it('renders root causes when they exist', () => { |
| 49 | + setup({ isExpanded: true }); |
| 50 | + |
| 51 | + expect(screen.getByText('Root Cause')).toBeInTheDocument(); |
| 52 | + expect( |
| 53 | + screen.getByText( |
| 54 | + 'There is an issue in the worker service that is causing a failure. Check identity for service logs' |
| 55 | + ) |
| 56 | + ).toBeInTheDocument(); |
| 57 | + }); |
| 58 | + |
| 59 | + it('renders multiple root causes with correct label', () => { |
| 60 | + const multipleRootCauses = [ |
| 61 | + mockRootCauses[0], |
| 62 | + { ...mockRootCauses[0], rootCauseType: 'Another root cause' }, |
| 63 | + ]; |
| 64 | + |
| 65 | + setup({ rootCauses: multipleRootCauses, isExpanded: true }); |
| 66 | + |
| 67 | + expect(screen.getByText('Root Causes')).toBeInTheDocument(); |
| 68 | + expect( |
| 69 | + screen.getByText( |
| 70 | + 'There is an issue in the worker service that is causing a failure. Check identity for service logs' |
| 71 | + ) |
| 72 | + ).toBeInTheDocument(); |
| 73 | + expect(screen.getByText('Another root cause')).toBeInTheDocument(); |
| 74 | + }); |
| 75 | + |
| 76 | + it('does not render root causes section when no root causes exist', () => { |
| 77 | + setup({ rootCauses: [] }); |
| 78 | + |
| 79 | + expect(screen.queryByText('Root Cause')).not.toBeInTheDocument(); |
| 80 | + expect(screen.queryByText('Root Causes')).not.toBeInTheDocument(); |
| 81 | + }); |
| 82 | + |
| 83 | + it('renders issue metadata when it exists', () => { |
| 84 | + setup({ isExpanded: true }); |
| 85 | + |
| 86 | + expect(screen.getByText('Metadata')).toBeInTheDocument(); |
| 87 | + expect( |
| 88 | + screen.getByTestId('workflow-diagnostics-metadata-table') |
| 89 | + ).toBeInTheDocument(); |
| 90 | + }); |
| 91 | + |
| 92 | + it('does not render metadata section when issue has no metadata', () => { |
| 93 | + const issueWithoutMetadata = { ...mockIssue, metadata: null }; |
| 94 | + setup({ issue: issueWithoutMetadata, isExpanded: true }); |
| 95 | + |
| 96 | + expect(screen.queryByText('Metadata')).not.toBeInTheDocument(); |
| 97 | + expect( |
| 98 | + screen.queryByTestId('workflow-diagnostics-metadata-table') |
| 99 | + ).not.toBeInTheDocument(); |
| 100 | + }); |
| 101 | + |
| 102 | + it('renders root cause metadata when it exists', () => { |
| 103 | + const rootCauseWithMetadata = { |
| 104 | + ...mockRootCauses[0], |
| 105 | + metadata: { testKey: 'testValue' }, |
| 106 | + }; |
| 107 | + |
| 108 | + setup({ rootCauses: [rootCauseWithMetadata], isExpanded: true }); |
| 109 | + |
| 110 | + const metadataTables = screen.getAllByTestId( |
| 111 | + 'workflow-diagnostics-metadata-table' |
| 112 | + ); |
| 113 | + expect(metadataTables).toHaveLength(2); // One for issue metadata, one for root cause metadata |
| 114 | + }); |
| 115 | + |
| 116 | + it('renders details button with correct text and calls onChangePanel when clicked', async () => { |
| 117 | + const { user, mockOnChangePanel } = setup({}); |
| 118 | + |
| 119 | + const detailsButton = screen.getByText('Details'); |
| 120 | + expect(detailsButton).toBeInTheDocument(); |
| 121 | + |
| 122 | + await user.click(detailsButton); |
| 123 | + |
| 124 | + expect(mockOnChangePanel).toHaveBeenCalledTimes(1); |
| 125 | + }); |
| 126 | +}); |
| 127 | + |
| 128 | +function setup(overrides: Partial<Props>) { |
| 129 | + const user = userEvent.setup(); |
| 130 | + const mockOnChangePanel = jest.fn(); |
| 131 | + |
| 132 | + const props = { |
| 133 | + issue: mockIssue, |
| 134 | + rootCauses: mockRootCauses, |
| 135 | + isExpanded: false, |
| 136 | + onChangePanel: mockOnChangePanel, |
| 137 | + domain: 'test-domain', |
| 138 | + cluster: 'test-cluster', |
| 139 | + workflowId: 'test-workflow-id', |
| 140 | + runId: 'test-run-id', |
| 141 | + ...overrides, |
| 142 | + }; |
| 143 | + |
| 144 | + const renderResult = render(<WorkflowDiagnosticsIssue {...props} />); |
| 145 | + |
| 146 | + return { ...renderResult, mockOnChangePanel, user }; |
| 147 | +} |
0 commit comments