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.6 KB
Raw Blame
import '@testing-library/jest-dom'

import { cleanup, render } from '@testing-library/react'

import { FeatureFlagGroupType, PropertyFilterType, PropertyOperator } from '~/types'

import { ConditionSetSummary } from './ConditionSetSummary'

function group(rolloutPercentage: number | null, withProperties = false): FeatureFlagGroupType {
    return {
        properties: withProperties
            ? [
                  {
                      type: PropertyFilterType.Person,
                      key: 'email',
                      operator: PropertyOperator.IContains,
                      value: 'example.com',
                  },
              ]
            : [],
        rollout_percentage: rolloutPercentage,
        variant: null,
        sort_key: 'group-1',
    }
}

describe('ConditionSetSummary', () => {
    afterEach(() => {
        cleanup()
    })

    it.each<[number | null, string]>([
        [100, 'Condition set will match all users'],
        [null, 'Condition set will match all users'],
        [25, 'Condition set will match 25% of all users'],
        [0, 'Condition set will match no users'],
    ])('summarises a set without criteria at %s%% rollout', (rolloutPercentage, expected) => {
        render(<ConditionSetSummary group={group(rolloutPercentage)} aggregationTargetName="users" />)

        expect(document.body).toHaveTextContent(expected)
    })

    it('summarises a set with criteria', () => {
        render(<ConditionSetSummary group={group(25, true)} aggregationTargetName="users" />)

        expect(document.body).toHaveTextContent('Match users against all criteria')
    })
})