|
1 | 1 | import {OrganizationFixture} from 'sentry-fixture/organization'; |
2 | 2 |
|
3 | | -import {act, render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary'; |
| 3 | +import { |
| 4 | + act, |
| 5 | + cleanup, |
| 6 | + render, |
| 7 | + screen, |
| 8 | + userEvent, |
| 9 | + waitFor, |
| 10 | +} from 'sentry-test/reactTestingLibrary'; |
4 | 11 |
|
5 | 12 | import {PageFiltersStore} from 'sentry/components/pageFilters/store'; |
| 13 | +import {trackAnalytics} from 'sentry/utils/analytics'; |
6 | 14 |
|
7 | 15 | import {ConversationViewContent} from './conversationView'; |
8 | 16 |
|
| 17 | +jest.mock('sentry/utils/analytics'); |
| 18 | + |
9 | 19 | const CONVERSATION_ID = 'conv-1'; |
10 | 20 | const originalIntersectionObserver = window.IntersectionObserver; |
11 | 21 | let triggerIntersection: ((isIntersecting: boolean) => void) | undefined; |
@@ -258,6 +268,113 @@ describe('ConversationViewContent', () => { |
258 | 268 | expect(nextRequest).toHaveBeenCalledTimes(1); |
259 | 269 | }); |
260 | 270 |
|
| 271 | + it('searches the transcript and selects the span with the match', async () => { |
| 272 | + const onSelectSpan = jest.fn(); |
| 273 | + renderView({onSelectSpan}); |
| 274 | + await screen.findByText('Second answer'); |
| 275 | + |
| 276 | + await userEvent.type( |
| 277 | + screen.getByRole('textbox', {name: 'Search in transcript'}), |
| 278 | + 'second answer{Enter}' |
| 279 | + ); |
| 280 | + |
| 281 | + expect(await screen.findByText('1/1')).toBeInTheDocument(); |
| 282 | + expect(onSelectSpan).toHaveBeenCalledWith('span-b'); |
| 283 | + |
| 284 | + await userEvent.clear(screen.getByRole('textbox', {name: 'Search in transcript'})); |
| 285 | + expect(screen.queryByText('1/1')).not.toBeInTheDocument(); |
| 286 | + }); |
| 287 | + |
| 288 | + it('loads later pages until the search finds a match', async () => { |
| 289 | + MockApiClient.clearMockResponses(); |
| 290 | + mockConversation([CONVERSATION_BODY[0]!], {nextCursor: 'next'}); |
| 291 | + const nextRequest = mockConversation([CONVERSATION_BODY[1]!], {cursor: 'next'}); |
| 292 | + const onSelectSpan = jest.fn(); |
| 293 | + renderView({onSelectSpan}); |
| 294 | + await screen.findByText('First answer'); |
| 295 | + |
| 296 | + await userEvent.type( |
| 297 | + screen.getByRole('textbox', {name: 'Search in transcript'}), |
| 298 | + 'second answer{Enter}' |
| 299 | + ); |
| 300 | + |
| 301 | + expect(await screen.findByText('1/1')).toBeInTheDocument(); |
| 302 | + expect(nextRequest).toHaveBeenCalledTimes(1); |
| 303 | + expect(onSelectSpan).toHaveBeenCalledWith('span-b'); |
| 304 | + }); |
| 305 | + |
| 306 | + it('shows no results once every page is searched', async () => { |
| 307 | + MockApiClient.clearMockResponses(); |
| 308 | + mockConversation([CONVERSATION_BODY[0]!], {nextCursor: 'next'}); |
| 309 | + const nextRequest = mockConversation([CONVERSATION_BODY[1]!], {cursor: 'next'}); |
| 310 | + const onSelectSpan = jest.fn(); |
| 311 | + renderView({onSelectSpan}); |
| 312 | + await screen.findByText('First answer'); |
| 313 | + |
| 314 | + await userEvent.type( |
| 315 | + screen.getByRole('textbox', {name: 'Search in transcript'}), |
| 316 | + 'not in this conversation{Enter}' |
| 317 | + ); |
| 318 | + |
| 319 | + expect(await screen.findByText('No results')).toBeInTheDocument(); |
| 320 | + expect(nextRequest).toHaveBeenCalledTimes(1); |
| 321 | + expect(onSelectSpan).not.toHaveBeenCalled(); |
| 322 | + expect(trackAnalytics).not.toHaveBeenCalledWith( |
| 323 | + 'conversations.detail.span-limit-reached', |
| 324 | + expect.anything() |
| 325 | + ); |
| 326 | + }); |
| 327 | + |
| 328 | + describe('at the span limit', () => { |
| 329 | + afterEach(() => { |
| 330 | + try { |
| 331 | + cleanup(); |
| 332 | + jest.runOnlyPendingTimers(); |
| 333 | + } finally { |
| 334 | + jest.useRealTimers(); |
| 335 | + } |
| 336 | + }); |
| 337 | + |
| 338 | + it('reports when the span limit stops a search', async () => { |
| 339 | + MockApiClient.clearMockResponses(); |
| 340 | + mockConversation([CONVERSATION_BODY[0]!], {nextCursor: 'next'}); |
| 341 | + let page = 1; |
| 342 | + const nextRequest = MockApiClient.addMockResponse({ |
| 343 | + url: `/organizations/org-slug/agents/conversations/${CONVERSATION_ID}/`, |
| 344 | + match: [MockApiClient.matchQuery({cursor: 'next'})], |
| 345 | + body: () => { |
| 346 | + page++; |
| 347 | + return { |
| 348 | + conversationId: CONVERSATION_ID, |
| 349 | + title: null, |
| 350 | + spans: [{...CONVERSATION_BODY[1]!, span_id: `span-${page}`}], |
| 351 | + }; |
| 352 | + }, |
| 353 | + headers: { |
| 354 | + Link: `</organizations/org-slug/agents/conversations/${CONVERSATION_ID}/?cursor=next>; rel="next"; results="true"; cursor="next"`, |
| 355 | + }, |
| 356 | + }); |
| 357 | + jest.useFakeTimers(); |
| 358 | + renderView({onSelectSpan: jest.fn()}); |
| 359 | + await screen.findByText('First answer'); |
| 360 | + |
| 361 | + await userEvent.type( |
| 362 | + screen.getByRole('textbox', {name: 'Search in transcript'}), |
| 363 | + 'not in this conversation{Enter}', |
| 364 | + {delay: null} |
| 365 | + ); |
| 366 | + await act(() => jest.runAllTimersAsync()); |
| 367 | + |
| 368 | + expect(screen.getByText('No results')).toBeInTheDocument(); |
| 369 | + expect(nextRequest).toHaveBeenCalledTimes(99); |
| 370 | + expect(trackAnalytics).toHaveBeenCalledTimes(1); |
| 371 | + expect(trackAnalytics).toHaveBeenCalledWith( |
| 372 | + 'conversations.detail.span-limit-reached', |
| 373 | + expect.objectContaining({organization: expect.anything()}) |
| 374 | + ); |
| 375 | + }); |
| 376 | + }); |
| 377 | + |
261 | 378 | it('does not show the timeline default while a deep link is unresolved', async () => { |
262 | 379 | MockApiClient.clearMockResponses(); |
263 | 380 | mockConversation([CONVERSATION_BODY[0]!], {nextCursor: 'next'}); |
|
0 commit comments