: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { expectLogic } from 'kea-test-utils'
import { productSetupStatusLogic } from 'lib/components/ProductEmptyState/productSetupStatusLogic'
import { ProductKey } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
import * as generatedApi from '../generated/api'
import { notebooksSetupLogic } from './notebooksSetupLogic'
// Guards the mapping into the app-wide setup-status layer: if it breaks, the scene
// empty-state gate strands on its spinner or shows the wrong surface.
describe('notebooksSetupLogic', () => {
let listSpy: jest.SpyInstance
beforeEach(() => {
listSpy = jest.spyOn(generatedApi, 'notebooksList')
initKeaTests()
})
afterEach(() => {
listSpy.mockRestore()
})
it.each([
[0, 'needs-setup'],
[1, 'has-data'],
[23, 'has-data'],
])('pushes a notebook count of %i as status %s', async (count, expected) => {
listSpy.mockResolvedValue({ count, results: [] })
const logic = notebooksSetupLogic()
logic.mount()
await expectLogic(logic).toFinishAllListeners()
expect(productSetupStatusLogic({ productKey: ProductKey.NOTEBOOKS }).values.status).toBe(expected)
})
it('fails open to unknown when the count query fails before any answer', async () => {
listSpy.mockRejectedValue(new Error('network down'))
const logic = notebooksSetupLogic()
logic.mount()
await expectLogic(logic).toFinishAllListeners()
expect(productSetupStatusLogic({ productKey: ProductKey.NOTEBOOKS }).values.status).toBe('unknown')
})
})