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.

1.5 KB
Raw Blame
import { FilterLogicalOperator, PropertyFilterType, PropertyOperator } from '~/types'

import { buildFilterGroupFromWidgetFilters } from './widgetConfigValidation'

describe('widgetConfigValidation', () => {
    describe('buildFilterGroupFromWidgetFilters', () => {
        it('returns undefined when empty', () => {
            expect(buildFilterGroupFromWidgetFilters(undefined)).toBeUndefined()
            expect(buildFilterGroupFromWidgetFilters({})).toBeUndefined()
        })

        it('builds AND group', () => {
            const filterGroup = buildFilterGroupFromWidgetFilters({
                'qf-1': {
                    filterId: 'qf-1',
                    propertyName: '$browser',
                    optionId: 'opt-1',
                    value: 'Chrome',
                    operator: PropertyOperator.Exact,
                },
            })
            expect(filterGroup).toEqual({
                type: FilterLogicalOperator.And,
                values: [
                    {
                        type: FilterLogicalOperator.And,
                        values: [
                            {
                                type: PropertyFilterType.Event,
                                key: '$browser',
                                operator: PropertyOperator.Exact,
                                value: ['Chrome'],
                            },
                        ],
                    },
                ],
            })
        })
    })
})