|
| 1 | +import {LocationFixture} from 'sentry-fixture/locationFixture'; |
| 2 | + |
| 3 | +import {initializeOrg} from 'sentry-test/initializeOrg'; |
| 4 | +import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary'; |
| 5 | + |
| 6 | +import ProjectsStore from 'sentry/stores/projectsStore'; |
| 7 | +import {LogsAnalyticsPageSource} from 'sentry/utils/analytics/logsAnalyticsEvent'; |
| 8 | +import {useLocation} from 'sentry/utils/useLocation'; |
| 9 | +import { |
| 10 | + LOGS_FIELDS_KEY, |
| 11 | + LOGS_QUERY_KEY, |
| 12 | + LogsPageParamsProvider, |
| 13 | +} from 'sentry/views/explore/contexts/logs/logsPageParams'; |
| 14 | +import {LOGS_SORT_BYS_KEY} from 'sentry/views/explore/contexts/logs/sortBys'; |
| 15 | +import {LogsTable} from 'sentry/views/explore/logs/logsTable'; |
| 16 | +import {OurLogKnownFieldKey} from 'sentry/views/explore/logs/types'; |
| 17 | +import type {UseExploreLogsTableResult} from 'sentry/views/explore/logs/useLogsQuery'; |
| 18 | + |
| 19 | +jest.mock('sentry/utils/useLocation'); |
| 20 | +const mockUseLocation = jest.mocked(useLocation); |
| 21 | + |
| 22 | +jest.mock('sentry/utils/useRelease', () => ({ |
| 23 | + useRelease: jest.fn().mockReturnValue({ |
| 24 | + data: { |
| 25 | + id: 10, |
| 26 | + lastCommit: { |
| 27 | + id: '1e5a9462e6ac23908299b218e18377837297bda1', |
| 28 | + }, |
| 29 | + }, |
| 30 | + }), |
| 31 | +})); |
| 32 | + |
| 33 | +jest.mock('sentry/components/events/interfaces/frame/useStacktraceLink', () => ({ |
| 34 | + __esModule: true, |
| 35 | + default: jest.fn().mockReturnValue({ |
| 36 | + data: { |
| 37 | + sourceUrl: 'https://some-stacktrace-link', |
| 38 | + integrations: [], |
| 39 | + }, |
| 40 | + error: null, |
| 41 | + isPending: false, |
| 42 | + }), |
| 43 | +})); |
| 44 | + |
| 45 | +describe('LogsTable', function () { |
| 46 | + const {organization, project} = initializeOrg({ |
| 47 | + organization: { |
| 48 | + features: ['ourlogs'], |
| 49 | + }, |
| 50 | + }); |
| 51 | + ProjectsStore.loadInitialData([project]); |
| 52 | + |
| 53 | + const tableData = { |
| 54 | + data: [ |
| 55 | + { |
| 56 | + 'sentry.item_id': '0196a1bc022d76d3bff2106ebbf65f49', |
| 57 | + 'project.id': project.id, |
| 58 | + trace: '32986bcdac1f43ed87445a2021b0099c', |
| 59 | + severity_number: 9, |
| 60 | + severity: 'info', |
| 61 | + timestamp: '2025-05-05T18:36:15+00:00', |
| 62 | + message: |
| 63 | + '10.5.55.212 - - [05/May/2025:18:36:15 +0000] "POST /v1/automation/autofix/state HTTP/1.1" 200 293642 "-" "python-requests/2.32.3"', |
| 64 | + 'sentry.release': '985bae16edc2f3f8132e346a4f6c5a559f7c968b', |
| 65 | + 'code.file.path': '/usr/local/lib/python3.11/dist-packages/gunicorn/glogging.py', |
| 66 | + 'tags[sentry.timestamp_precise,number]': 1.7464701752771756e18, |
| 67 | + }, |
| 68 | + { |
| 69 | + 'sentry.item_id': '0196a1bc00e3720f8d47c84c53131891', |
| 70 | + 'project.id': project.id, |
| 71 | + trace: '6141dca24986471398232d340a4fd588', |
| 72 | + severity_number: 9, |
| 73 | + severity: 'info', |
| 74 | + timestamp: '2025-05-05T18:36:14+00:00', |
| 75 | + message: |
| 76 | + '10.5.58.189 - - [05/May/2025:18:36:14 +0000] "POST /v0/issues/similar-issues HTTP/1.1" 200 131 "-" "python-urllib3/2.2.2"', |
| 77 | + 'sentry.release': '985bae16edc2f3f8132e346a4f6c5a559f7c968b', |
| 78 | + 'code.file.path': '/usr/local/lib/python3.11/dist-packages/gunicorn/glogging.py', |
| 79 | + 'tags[sentry.timestamp_precise,number]': 1.746470174947077e18, |
| 80 | + }, |
| 81 | + { |
| 82 | + 'sentry.item_id': '0196a1bc007c7dfbbe099b6328e41d12', |
| 83 | + 'project.id': project.id, |
| 84 | + trace: '6141dca24986471398232d340a4fd588', |
| 85 | + severity_number: 9, |
| 86 | + severity: 'info', |
| 87 | + timestamp: '2025-05-05T18:36:14+00:00', |
| 88 | + message: |
| 89 | + '10.5.62.140 - - [05/May/2025:18:36:14 +0000] "POST /v0/issues/similar-issues HTTP/1.1" 200 586 "-" "python-urllib3/2.2.2"', |
| 90 | + 'sentry.release': '985bae16edc2f3f8132e346a4f6c5a559f7c968b', |
| 91 | + 'code.file.path': '/usr/local/lib/python3.11/dist-packages/gunicorn/glogging.py', |
| 92 | + 'tags[sentry.timestamp_precise,number]': 1.7464701748443016e18, |
| 93 | + }, |
| 94 | + ], |
| 95 | + meta: { |
| 96 | + fields: { |
| 97 | + 'sentry.item_id': 'string', |
| 98 | + 'project.id': 'string', |
| 99 | + trace: 'string', |
| 100 | + severity_number: 'integer', |
| 101 | + severity: 'string', |
| 102 | + timestamp: 'string', |
| 103 | + message: 'string', |
| 104 | + 'sentry.release': 'string', |
| 105 | + 'code.file.path': 'string', |
| 106 | + 'tags[sentry.timestamp_precise,number]': 'number', |
| 107 | + }, |
| 108 | + }, |
| 109 | + isLoading: false, |
| 110 | + isPending: false, |
| 111 | + isError: false, |
| 112 | + error: null, |
| 113 | + pageLinks: undefined, |
| 114 | + } as unknown as UseExploreLogsTableResult; |
| 115 | + |
| 116 | + const visibleColumnFields = [ |
| 117 | + 'message', |
| 118 | + 'trace', |
| 119 | + 'severity_number', |
| 120 | + 'severity', |
| 121 | + 'timestamp', |
| 122 | + 'sentry.release', |
| 123 | + 'code.file.path', |
| 124 | + ]; |
| 125 | + const frozenColumnFields = [OurLogKnownFieldKey.TIMESTAMP, OurLogKnownFieldKey.MESSAGE]; |
| 126 | + |
| 127 | + beforeEach(function () { |
| 128 | + MockApiClient.clearMockResponses(); |
| 129 | + mockUseLocation.mockReturnValue( |
| 130 | + LocationFixture({ |
| 131 | + pathname: `/organizations/${organization.slug}/explore/logs/?end=2025-04-10T20%3A04%3A51&project=${project.id}&start=2025-04-10T14%3A37%3A55`, |
| 132 | + query: { |
| 133 | + [LOGS_FIELDS_KEY]: visibleColumnFields, |
| 134 | + [LOGS_SORT_BYS_KEY]: '-timestamp', |
| 135 | + [LOGS_QUERY_KEY]: 'severity:error', |
| 136 | + }, |
| 137 | + }) |
| 138 | + ); |
| 139 | + |
| 140 | + MockApiClient.addMockResponse({ |
| 141 | + url: `/organizations/${organization.slug}/releases/stats/`, |
| 142 | + method: 'GET', |
| 143 | + body: {}, |
| 144 | + }); |
| 145 | + }); |
| 146 | + |
| 147 | + it('should be interactable', async () => { |
| 148 | + render( |
| 149 | + <LogsPageParamsProvider analyticsPageSource={LogsAnalyticsPageSource.EXPLORE_LOGS}> |
| 150 | + <LogsTable tableData={tableData} showHeader /> |
| 151 | + </LogsPageParamsProvider> |
| 152 | + ); |
| 153 | + |
| 154 | + const allTreeRows = await screen.findAllByTestId('log-table-row'); |
| 155 | + expect(allTreeRows).toHaveLength(3); |
| 156 | + for (const row of allTreeRows) { |
| 157 | + for (const field of visibleColumnFields) { |
| 158 | + const cell = await within(row).findByTestId(`log-table-cell-${field}`); |
| 159 | + await userEvent.hover(cell); |
| 160 | + const actionsButton = within(cell).queryByRole('button', { |
| 161 | + name: 'Actions', |
| 162 | + }); |
| 163 | + if (field === 'timestamp') { |
| 164 | + expect(actionsButton).toBeNull(); |
| 165 | + } else { |
| 166 | + expect(actionsButton).toBeInTheDocument(); |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + }); |
| 171 | + |
| 172 | + it('should not be interactable on embedded views', async () => { |
| 173 | + render( |
| 174 | + <LogsPageParamsProvider |
| 175 | + analyticsPageSource={LogsAnalyticsPageSource.EXPLORE_LOGS} |
| 176 | + isTableFrozen |
| 177 | + > |
| 178 | + <LogsTable tableData={tableData} showHeader /> |
| 179 | + </LogsPageParamsProvider> |
| 180 | + ); |
| 181 | + |
| 182 | + const allTreeRows = await screen.findAllByTestId('log-table-row'); |
| 183 | + expect(allTreeRows).toHaveLength(3); |
| 184 | + for (const row of allTreeRows) { |
| 185 | + for (const field of frozenColumnFields) { |
| 186 | + const cell = await within(row).findByTestId(`log-table-cell-${field}`); |
| 187 | + await userEvent.hover(cell); |
| 188 | + const actionsButton = within(cell).queryByRole('button', { |
| 189 | + name: 'Actions', |
| 190 | + }); |
| 191 | + expect(actionsButton).not.toBeInTheDocument(); |
| 192 | + } |
| 193 | + } |
| 194 | + }); |
| 195 | +}); |
0 commit comments