Files
zeekay e43ab1afe7 chore: rename all PostHog references to Insights/Hanzo
Bulk rename across 989 files:
- Package names: posthog-js → @hanzo/insights, posthog-node → @hanzo/insights-node, etc.
- Repository URLs: posthog/posthog-js → hanzoai/insights-js
- Brand names: PostHog → Insights
- File renames: 259 reference JSON files, source files, workflow files
- Directory rename: eslint-plugin-posthog-js → eslint-plugin-insights

Remaining: 8 refs to @posthog/rrweb-* (real npm deps, need fork+publish)
2026-03-06 01:41:12 -08:00

93 lines
3.1 KiB
TypeScript

import { autocaptureFromTouchEvent } from '../src/autocapture'
import goodEvent from './data/autocapture-event.json'
import ignoreEvent from './data/autocapture-event-no-capture.json'
describe('Insights React Native', () => {
jest.useRealTimers()
describe('autocapture', () => {
const nativeEvent = { pageX: 1, pageY: 2 }
it('should capture a valid event', () => {
const mockInsights = { autocapture: jest.fn() } as any
autocaptureFromTouchEvent({ _targetInst: goodEvent, nativeEvent }, mockInsights)
expect(mockInsights.autocapture).toHaveBeenCalledTimes(1)
expect(mockInsights.autocapture.mock.calls[0]).toMatchSnapshot()
})
it('should ignore an invalid event', () => {
const mockInsights = { autocapture: jest.fn() } as any
autocaptureFromTouchEvent({ _targetInst: ignoreEvent, nativeEvent }, mockInsights)
expect(mockInsights.autocapture).toHaveBeenCalledTimes(0)
})
it('should handle animated styles without errors', () => {
const mockInsights = { autocapture: jest.fn() } as any
// Mock a Reanimated animated style
const animatedStyle = {
_isReanimatedSharedValue: true,
_value: { opacity: 1 },
__reanimatedHostObjectRef: {},
}
const eventWithAnimatedStyle = {
_targetInst: {
elementType: { name: 'TouchableOpacity' },
memoizedProps: {
style: animatedStyle,
children: 'Test Button',
},
return: null,
},
nativeEvent,
}
// Should not throw error when processing animated styles
expect(() => {
autocaptureFromTouchEvent(eventWithAnimatedStyle, mockInsights)
}).not.toThrow()
// Should still capture the event, just with empty style
expect(mockInsights.autocapture).toHaveBeenCalledTimes(1)
const capturedElement = mockInsights.autocapture.mock.calls[0][1][0]
expect(capturedElement.attr__style).toBe('')
expect(capturedElement.$el_text).toBe('Test Button')
})
it('should handle mixed animated and regular styles', () => {
const mockInsights = { autocapture: jest.fn() } as any
const mixedStyle = [
{ backgroundColor: 'red', padding: 10 },
{
opacity: {
_isReanimatedSharedValue: true,
_value: 1,
},
},
]
const eventWithMixedStyle = {
_targetInst: {
elementType: { name: 'View' },
memoizedProps: {
style: mixedStyle,
testID: 'test-view',
},
return: null,
},
nativeEvent,
}
autocaptureFromTouchEvent(eventWithMixedStyle, mockInsights)
expect(mockInsights.autocapture).toHaveBeenCalledTimes(1)
const capturedElement = mockInsights.autocapture.mock.calls[0][1][0]
// Should capture regular styles but skip animated values
expect(capturedElement.attr__style).toContain('backgroundColor:red')
expect(capturedElement.attr__style).toContain('padding:10')
expect(capturedElement.attr__style).not.toContain('opacity')
})
})
})