Skip to content

Commit d6daf14

Browse files
committed
✅ Add in tests for askSeer
1 parent 820a1ff commit d6daf14

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import {useComboBoxState} from '@react-stately/combobox';
2+
import {AutofixSetupFixture} from 'sentry-fixture/autofixSetupFixture';
3+
import {OrganizationFixture} from 'sentry-fixture/organization';
4+
5+
import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
6+
7+
import {AskSeer} from 'sentry/components/searchQueryBuilder/askSeer';
8+
import {SearchQueryBuilderProvider} from 'sentry/components/searchQueryBuilder/context';
9+
import {FieldKind} from 'sentry/utils/fields';
10+
11+
// Mock the useOption hook to avoid the "Unknown list" error
12+
jest.mock('@react-aria/listbox', () => ({
13+
...jest.requireActual('@react-aria/listbox'),
14+
useOption: jest.fn(() => ({
15+
optionProps: {
16+
role: 'option',
17+
'aria-selected': false,
18+
'aria-disabled': false,
19+
},
20+
labelProps: {},
21+
isFocused: false,
22+
isPressed: false,
23+
})),
24+
}));
25+
26+
function MockComboBoxComponent() {
27+
const comboBoxState = useComboBoxState({
28+
items: [{id: 1, name: 'one'}],
29+
disabledKeys: [],
30+
});
31+
32+
return (
33+
<SearchQueryBuilderProvider
34+
filterKeys={{id: {key: 'id', name: 'ID', kind: FieldKind.FIELD}}}
35+
getTagValues={() => Promise.resolve([])}
36+
initialQuery=""
37+
searchSource=""
38+
enableAISearch
39+
>
40+
<AskSeer state={comboBoxState} />
41+
</SearchQueryBuilderProvider>
42+
);
43+
}
44+
45+
describe('AskSeer', () => {
46+
it('renders ask seer button when user has given consent', async () => {
47+
MockApiClient.addMockResponse({
48+
url: '/organizations/org-slug/seer/setup-check/',
49+
body: AutofixSetupFixture({
50+
setupAcknowledgement: {
51+
orgHasAcknowledged: true,
52+
userHasAcknowledged: true,
53+
},
54+
}),
55+
});
56+
57+
render(<MockComboBoxComponent />, {
58+
organization: {features: ['gen-ai-features', 'gen-ai-explore-traces']},
59+
});
60+
61+
const askSeer = await screen.findByRole('option', {name: 'Ask Seer'});
62+
expect(askSeer).toBeInTheDocument();
63+
});
64+
65+
it('renders enable ai button when user has not given consent', async () => {
66+
MockApiClient.addMockResponse({
67+
url: '/organizations/org-slug/seer/setup-check/',
68+
body: AutofixSetupFixture({
69+
setupAcknowledgement: {
70+
orgHasAcknowledged: false,
71+
userHasAcknowledged: false,
72+
},
73+
}),
74+
});
75+
76+
render(<MockComboBoxComponent />, {
77+
organization: {features: ['gen-ai-features', 'gen-ai-explore-traces']},
78+
});
79+
80+
const enableAi = await screen.findByText('Enable Gen AI');
81+
expect(enableAi).toBeInTheDocument();
82+
});
83+
84+
describe('user clicks on enable gen ai button', () => {
85+
it('calls promptsUpdate', async () => {
86+
const organization = OrganizationFixture();
87+
MockApiClient.addMockResponse({
88+
url: '/organizations/org-slug/seer/setup-check/',
89+
body: AutofixSetupFixture({
90+
setupAcknowledgement: {
91+
orgHasAcknowledged: false,
92+
userHasAcknowledged: false,
93+
},
94+
}),
95+
});
96+
97+
const promptsUpdateMock = MockApiClient.addMockResponse({
98+
url: `/organizations/${organization.slug}/prompts-activity/`,
99+
method: 'PUT',
100+
});
101+
102+
render(<MockComboBoxComponent />, {
103+
organization: {features: ['gen-ai-features', 'gen-ai-explore-traces']},
104+
});
105+
106+
const enableAi = await screen.findByText('Enable Gen AI');
107+
expect(enableAi).toBeInTheDocument();
108+
109+
await userEvent.click(enableAi);
110+
111+
await waitFor(() => {
112+
expect(promptsUpdateMock).toHaveBeenCalledWith(
113+
expect.any(String),
114+
expect.objectContaining({
115+
data: {
116+
feature: 'seer_autofix_setup_acknowledged',
117+
organization_id: organization.id,
118+
project_id: undefined,
119+
status: 'dismissed',
120+
},
121+
})
122+
);
123+
});
124+
});
125+
});
126+
});

0 commit comments

Comments
 (0)