|
| 1 | +import React from 'react' |
| 2 | +import { |
| 3 | + render, |
| 4 | + screen, |
| 5 | + fireEvent, |
| 6 | + initialStateDefault, |
| 7 | + mockStore, |
| 8 | +} from 'uiSrc/utils/test-utils' |
| 9 | +import { RootState } from 'uiSrc/slices/store' |
| 10 | +import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry' |
| 11 | +import { INSTANCE_ID_MOCK } from 'uiSrc/mocks/handlers/analytics/dbAnalysisHistoryHandlers' |
| 12 | +import { VectorSearchCreateIndex } from './VectorSearchCreateIndex' |
| 13 | +import { SampleDataContent, SampleDataType, SearchIndexType } from './types' |
| 14 | + |
| 15 | +// Mock the telemetry module, so we don't send actual telemetry data during tests |
| 16 | +jest.mock('uiSrc/telemetry', () => ({ |
| 17 | + ...jest.requireActual('uiSrc/telemetry'), |
| 18 | + sendEventTelemetry: jest.fn(), |
| 19 | +})) |
| 20 | + |
| 21 | +const renderVectorSearchCreateIndexComponent = () => { |
| 22 | + const testState: RootState = { |
| 23 | + ...initialStateDefault, |
| 24 | + connections: { |
| 25 | + ...initialStateDefault.connections, |
| 26 | + instances: { |
| 27 | + ...initialStateDefault.connections.instances, |
| 28 | + connectedInstance: { |
| 29 | + ...initialStateDefault.connections.instances.connectedInstance, |
| 30 | + id: INSTANCE_ID_MOCK, |
| 31 | + name: 'test-instance', |
| 32 | + host: 'localhost', |
| 33 | + port: 6379, |
| 34 | + modules: [], |
| 35 | + }, |
| 36 | + }, |
| 37 | + }, |
| 38 | + } |
| 39 | + const store = mockStore(testState) |
| 40 | + |
| 41 | + return render(<VectorSearchCreateIndex />, { store }) |
| 42 | +} |
| 43 | + |
| 44 | +describe('VectorSearchCreateIndex', () => { |
| 45 | + beforeEach(() => { |
| 46 | + jest.clearAllMocks() |
| 47 | + }) |
| 48 | + |
| 49 | + it('should render correctly', () => { |
| 50 | + const { container } = renderVectorSearchCreateIndexComponent() |
| 51 | + |
| 52 | + expect(container).toBeInTheDocument() |
| 53 | + }) |
| 54 | + |
| 55 | + describe('Telemetry', () => { |
| 56 | + it('should send telemetry events on start step', () => { |
| 57 | + renderVectorSearchCreateIndexComponent() |
| 58 | + |
| 59 | + expect(sendEventTelemetry).toHaveBeenCalledTimes(1) |
| 60 | + expect(sendEventTelemetry).toHaveBeenCalledWith({ |
| 61 | + event: TelemetryEvent.VECTOR_SEARCH_ONBOARDING_TRIGGERED, |
| 62 | + eventData: { databaseId: INSTANCE_ID_MOCK }, |
| 63 | + }) |
| 64 | + }) |
| 65 | + |
| 66 | + it('should send telemetry events on index info step', () => { |
| 67 | + renderVectorSearchCreateIndexComponent() |
| 68 | + |
| 69 | + // Select the index type |
| 70 | + const indexTypeRadio = screen.getByText('Redis Query Engine') |
| 71 | + fireEvent.click(indexTypeRadio) |
| 72 | + |
| 73 | + // Select the sample dataset |
| 74 | + const sampleDataRadio = screen.getByText('Pre-set data') |
| 75 | + fireEvent.click(sampleDataRadio) |
| 76 | + |
| 77 | + // Select data content |
| 78 | + const dataContentRadio = screen.getByText('E-commerce Discovery') |
| 79 | + fireEvent.click(dataContentRadio) |
| 80 | + |
| 81 | + // Simulate going to the index info step |
| 82 | + const buttonNext = screen.getByText('Proceed to index') |
| 83 | + fireEvent.click(buttonNext) |
| 84 | + |
| 85 | + expect(sendEventTelemetry).toHaveBeenCalledTimes(2) |
| 86 | + expect(sendEventTelemetry).toHaveBeenNthCalledWith(2, { |
| 87 | + event: TelemetryEvent.VECTOR_SEARCH_ONBOARDING_PROCEED_TO_INDEX_INFO, |
| 88 | + eventData: { |
| 89 | + databaseId: INSTANCE_ID_MOCK, |
| 90 | + indexType: SearchIndexType.REDIS_QUERY_ENGINE, |
| 91 | + sampleDataType: SampleDataType.PRESET_DATA, |
| 92 | + dataContent: SampleDataContent.E_COMMERCE_DISCOVERY, |
| 93 | + }, |
| 94 | + }) |
| 95 | + }) |
| 96 | + |
| 97 | + it('should send telemetry events on create index step', () => { |
| 98 | + renderVectorSearchCreateIndexComponent() |
| 99 | + |
| 100 | + // Simulate going to the index info step |
| 101 | + const buttonNext = screen.getByText('Proceed to index') |
| 102 | + fireEvent.click(buttonNext) |
| 103 | + |
| 104 | + // Simulate creating the index |
| 105 | + const buttonCreateIndex = screen.getByText('Create index') |
| 106 | + fireEvent.click(buttonCreateIndex) |
| 107 | + |
| 108 | + expect(sendEventTelemetry).toHaveBeenCalledTimes(3) |
| 109 | + expect(sendEventTelemetry).toHaveBeenNthCalledWith(3, { |
| 110 | + event: TelemetryEvent.VECTOR_SEARCH_ONBOARDING_PROCEED_TO_QUERIES, |
| 111 | + eventData: { |
| 112 | + databaseId: INSTANCE_ID_MOCK, |
| 113 | + }, |
| 114 | + }) |
| 115 | + }) |
| 116 | + }) |
| 117 | +}) |
0 commit comments