Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(homepage): isolate AI input tests (#96141)

Paul D'Ambra5b7fcff210ac
diff --git a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsx b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsx
index 238580526e3c..10265ee90d0f 100644
--- a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsx
+++ b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsx
@@ -1,6 +1,6 @@
import { MOCK_DEFAULT_ORGANIZATION } from 'lib/api.mock'
-import { fireEvent, render, screen, waitFor } from '@testing-library/react'
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { BindLogic } from 'kea'
import { OrganizationMembershipLevel } from 'lib/constants'
@@ -20,7 +20,13 @@ jest.mock('scenes/max/components/SidebarQuestionInput', () => ({
describe('HomepageAiInput', () => {
const APPROVE_LABEL = 'I allow AI analysis in this organization'
- function renderInput(): HTMLElement {
+ function renderInput(membershipLevel: OrganizationMembershipLevel): HTMLElement {
+ initKeaTests(true, undefined, undefined, {
+ ...MOCK_DEFAULT_ORGANIZATION,
+ is_ai_data_processing_approved: false,
+ membership_level: membershipLevel,
+ })
+
const { container } = render(
<BindLogic logic={maxLogic} props={{ panelId: HOMEPAGE_TAB_ID }}>
<HomepageAiInput />
@@ -29,14 +35,6 @@ describe('HomepageAiInput', () => {
return container
}
- function setUpOrganization(membershipLevel: OrganizationMembershipLevel): void {
- initKeaTests(true, undefined, undefined, {
- ...MOCK_DEFAULT_ORGANIZATION,
- is_ai_data_processing_approved: false,
- membership_level: membershipLevel,
- })
- }
-
beforeEach(() => {
useMocks({
patch: {
@@ -52,11 +50,12 @@ describe('HomepageAiInput', () => {
'/api/organizations/:id/request_ai_access/': () => [200, { success: true }],
},
})
- setUpOrganization(OrganizationMembershipLevel.Admin)
})
+ afterEach(cleanup)
+
it('approves AI data processing and swaps in the composer when the button is clicked', async () => {
- const container = renderInput()
+ const container = renderInput(OrganizationMembershipLevel.Admin)
fireEvent.click(screen.getByText(APPROVE_LABEL))
@@ -67,8 +66,7 @@ describe('HomepageAiInput', () => {
})
it('lets a member ask an admin to approve, instead of dead-ending on the disabled reason', async () => {
- setUpOrganization(OrganizationMembershipLevel.Member)
- renderInput()
+ renderInput(OrganizationMembershipLevel.Member)
expect(screen.queryByText(APPROVE_LABEL)).toBeNull()
fireEvent.click(screen.getByText('Request access'))