|
1 | 1 | import type {ComponentProps} from 'react';
|
2 | 2 | import {destroyAnnouncer} from '@react-aria/live-announcer';
|
3 | 3 | import {AutofixSetupFixture} from 'sentry-fixture/autofixSetupFixture';
|
| 4 | +import {OrganizationFixture} from 'sentry-fixture/organization'; |
4 | 5 |
|
5 | 6 | import {
|
6 | 7 | act,
|
@@ -948,52 +949,6 @@ describe('SearchQueryBuilder', function () {
|
948 | 949 | expect(screen.getByRole('row', {name: 'browser.name:foo'})).toBeInTheDocument();
|
949 | 950 | });
|
950 | 951 |
|
951 |
| - it('displays ask seer button when searching free text', async function () { |
952 |
| - const mockOnSearch = jest.fn(); |
953 |
| - MockApiClient.addMockResponse({ |
954 |
| - url: '/organizations/org-slug/seer/setup-check/', |
955 |
| - body: AutofixSetupFixture({ |
956 |
| - setupAcknowledgement: { |
957 |
| - orgHasAcknowledged: true, |
958 |
| - userHasAcknowledged: true, |
959 |
| - }, |
960 |
| - }), |
961 |
| - }); |
962 |
| - |
963 |
| - render( |
964 |
| - <SearchQueryBuilder {...defaultProps} enableAISearch onSearch={mockOnSearch} />, |
965 |
| - {organization: {features: ['gen-ai-features', 'gen-ai-explore-traces']}} |
966 |
| - ); |
967 |
| - |
968 |
| - await userEvent.click(getLastInput()); |
969 |
| - await userEvent.type(screen.getByRole('combobox'), 'some free text'); |
970 |
| - |
971 |
| - expect(screen.getByRole('option', {name: /Ask Seer/i})).toBeInTheDocument(); |
972 |
| - }); |
973 |
| - |
974 |
| - it('displays enable ai button when searching free text and user has not given consent', async function () { |
975 |
| - const mockOnSearch = jest.fn(); |
976 |
| - MockApiClient.addMockResponse({ |
977 |
| - url: '/organizations/org-slug/seer/setup-check/', |
978 |
| - body: AutofixSetupFixture({ |
979 |
| - setupAcknowledgement: { |
980 |
| - orgHasAcknowledged: false, |
981 |
| - userHasAcknowledged: false, |
982 |
| - }, |
983 |
| - }), |
984 |
| - }); |
985 |
| - |
986 |
| - render( |
987 |
| - <SearchQueryBuilder {...defaultProps} enableAISearch onSearch={mockOnSearch} />, |
988 |
| - {organization: {features: ['gen-ai-features', 'gen-ai-explore-traces']}} |
989 |
| - ); |
990 |
| - |
991 |
| - await userEvent.click(getLastInput()); |
992 |
| - await userEvent.type(screen.getByRole('combobox'), 'some free text'); |
993 |
| - |
994 |
| - expect(screen.getByRole('option', {name: /Enable Gen AI/})).toBeInTheDocument(); |
995 |
| - }); |
996 |
| - |
997 | 952 | it('can add parens by typing', async function () {
|
998 | 953 | const mockOnChange = jest.fn();
|
999 | 954 | render(<SearchQueryBuilder {...defaultProps} onChange={mockOnChange} />);
|
@@ -4477,4 +4432,141 @@ describe('SearchQueryBuilder', function () {
|
4477 | 4432 | ).toBeInTheDocument();
|
4478 | 4433 | });
|
4479 | 4434 | });
|
| 4435 | + |
| 4436 | + describe('ask seer', function () { |
| 4437 | + it('renders ask seer button when user has given consent', async () => { |
| 4438 | + MockApiClient.addMockResponse({ |
| 4439 | + url: '/organizations/org-slug/seer/setup-check/', |
| 4440 | + body: AutofixSetupFixture({ |
| 4441 | + setupAcknowledgement: { |
| 4442 | + orgHasAcknowledged: true, |
| 4443 | + userHasAcknowledged: true, |
| 4444 | + }, |
| 4445 | + }), |
| 4446 | + }); |
| 4447 | + |
| 4448 | + render(<SearchQueryBuilder {...defaultProps} enableAISearch />, { |
| 4449 | + organization: {features: ['gen-ai-features', 'gen-ai-explore-traces']}, |
| 4450 | + }); |
| 4451 | + |
| 4452 | + await userEvent.click(getLastInput()); |
| 4453 | + |
| 4454 | + const askSeer = await screen.findByRole('option', {name: /Ask Seer/}); |
| 4455 | + expect(askSeer).toBeInTheDocument(); |
| 4456 | + }); |
| 4457 | + |
| 4458 | + it('renders enable ai button when user has not given consent', async () => { |
| 4459 | + MockApiClient.addMockResponse({ |
| 4460 | + url: '/organizations/org-slug/seer/setup-check/', |
| 4461 | + body: AutofixSetupFixture({ |
| 4462 | + setupAcknowledgement: { |
| 4463 | + orgHasAcknowledged: false, |
| 4464 | + userHasAcknowledged: false, |
| 4465 | + }, |
| 4466 | + }), |
| 4467 | + }); |
| 4468 | + |
| 4469 | + render(<SearchQueryBuilder {...defaultProps} enableAISearch />, { |
| 4470 | + organization: {features: ['gen-ai-features', 'gen-ai-explore-traces']}, |
| 4471 | + }); |
| 4472 | + |
| 4473 | + await userEvent.click(getLastInput()); |
| 4474 | + |
| 4475 | + const enableAi = await screen.findByText(/Enable Gen AI/); |
| 4476 | + expect(enableAi).toBeInTheDocument(); |
| 4477 | + }); |
| 4478 | + |
| 4479 | + describe('user clicks on enable gen ai button', () => { |
| 4480 | + it('calls promptsUpdate', async () => { |
| 4481 | + const organization = OrganizationFixture(); |
| 4482 | + MockApiClient.addMockResponse({ |
| 4483 | + url: '/organizations/org-slug/seer/setup-check/', |
| 4484 | + body: AutofixSetupFixture({ |
| 4485 | + setupAcknowledgement: { |
| 4486 | + orgHasAcknowledged: false, |
| 4487 | + userHasAcknowledged: false, |
| 4488 | + }, |
| 4489 | + }), |
| 4490 | + }); |
| 4491 | + |
| 4492 | + const promptsUpdateMock = MockApiClient.addMockResponse({ |
| 4493 | + url: `/organizations/${organization.slug}/prompts-activity/`, |
| 4494 | + method: 'PUT', |
| 4495 | + }); |
| 4496 | + |
| 4497 | + render(<SearchQueryBuilder {...defaultProps} enableAISearch />, { |
| 4498 | + organization: {features: ['gen-ai-features', 'gen-ai-explore-traces']}, |
| 4499 | + }); |
| 4500 | + |
| 4501 | + await userEvent.click(getLastInput()); |
| 4502 | + |
| 4503 | + const enableAi = await screen.findByText(/Enable Gen AI/); |
| 4504 | + expect(enableAi).toBeInTheDocument(); |
| 4505 | + |
| 4506 | + await userEvent.click(enableAi); |
| 4507 | + |
| 4508 | + await waitFor(() => { |
| 4509 | + expect(promptsUpdateMock).toHaveBeenCalledWith( |
| 4510 | + expect.any(String), |
| 4511 | + expect.objectContaining({ |
| 4512 | + data: { |
| 4513 | + feature: 'seer_autofix_setup_acknowledged', |
| 4514 | + organization_id: organization.id, |
| 4515 | + project_id: undefined, |
| 4516 | + status: 'dismissed', |
| 4517 | + }, |
| 4518 | + }) |
| 4519 | + ); |
| 4520 | + }); |
| 4521 | + }); |
| 4522 | + }); |
| 4523 | + |
| 4524 | + describe('free text', function () { |
| 4525 | + it('displays ask seer button when searching free text', async function () { |
| 4526 | + const mockOnSearch = jest.fn(); |
| 4527 | + MockApiClient.addMockResponse({ |
| 4528 | + url: '/organizations/org-slug/seer/setup-check/', |
| 4529 | + body: AutofixSetupFixture({ |
| 4530 | + setupAcknowledgement: { |
| 4531 | + orgHasAcknowledged: true, |
| 4532 | + userHasAcknowledged: true, |
| 4533 | + }, |
| 4534 | + }), |
| 4535 | + }); |
| 4536 | + |
| 4537 | + render( |
| 4538 | + <SearchQueryBuilder {...defaultProps} enableAISearch onSearch={mockOnSearch} />, |
| 4539 | + {organization: {features: ['gen-ai-features', 'gen-ai-explore-traces']}} |
| 4540 | + ); |
| 4541 | + |
| 4542 | + await userEvent.click(getLastInput()); |
| 4543 | + await userEvent.type(screen.getByRole('combobox'), 'some free text'); |
| 4544 | + |
| 4545 | + expect(screen.getByRole('option', {name: /Ask Seer/i})).toBeInTheDocument(); |
| 4546 | + }); |
| 4547 | + }); |
| 4548 | + |
| 4549 | + it('displays enable ai button when searching free text and user has not given consent', async function () { |
| 4550 | + const mockOnSearch = jest.fn(); |
| 4551 | + MockApiClient.addMockResponse({ |
| 4552 | + url: '/organizations/org-slug/seer/setup-check/', |
| 4553 | + body: AutofixSetupFixture({ |
| 4554 | + setupAcknowledgement: { |
| 4555 | + orgHasAcknowledged: false, |
| 4556 | + userHasAcknowledged: false, |
| 4557 | + }, |
| 4558 | + }), |
| 4559 | + }); |
| 4560 | + |
| 4561 | + render( |
| 4562 | + <SearchQueryBuilder {...defaultProps} enableAISearch onSearch={mockOnSearch} />, |
| 4563 | + {organization: {features: ['gen-ai-features', 'gen-ai-explore-traces']}} |
| 4564 | + ); |
| 4565 | + |
| 4566 | + await userEvent.click(getLastInput()); |
| 4567 | + await userEvent.type(screen.getByRole('combobox'), 'some free text'); |
| 4568 | + |
| 4569 | + expect(screen.getByRole('option', {name: /Enable Gen AI/})).toBeInTheDocument(); |
| 4570 | + }); |
| 4571 | + }); |
4480 | 4572 | });
|
0 commit comments