Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Apr 4, 2023
1 parent 7819e18 commit 2986eed
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 80 deletions.
109 changes: 109 additions & 0 deletions frontend/src/scenes/funnels/funnelCorrelationFeedbackLogic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import posthog from 'posthog-js'
import { expectLogic } from 'kea-test-utils'
import { initKeaTests } from '~/test/init'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { AvailableFeature, InsightLogicProps, InsightType } from '~/types'
import { useAvailableFeatures } from '~/mocks/features'
import { funnelCorrelationFeedbackLogic } from './funnelCorrelationFeedbackLogic'

describe('funnelCorrelationFeedbackLogic', () => {
let logic: ReturnType<typeof funnelCorrelationFeedbackLogic.build>

beforeEach(() => {
useAvailableFeatures([AvailableFeature.CORRELATION_ANALYSIS])
initKeaTests(false)
})

const defaultProps: InsightLogicProps = {
dashboardItemId: undefined,
cachedInsight: {
short_id: undefined,
filters: {
insight: InsightType.FUNNELS,
actions: [
{ id: '$pageview', order: 0 },
{ id: '$pageview', order: 1 },
],
},
result: [],
},
}

beforeEach(async () => {
logic = funnelCorrelationFeedbackLogic(defaultProps)
logic.mount()
})

it('opens detailed feedback on selecting a valid rating', async () => {
await expectLogic(logic, () => {
logic.actions.setCorrelationFeedbackRating(1)
})
.toMatchValues(logic, {
correlationFeedbackRating: 1,
})
.toDispatchActions(logic, [
(action) =>
action.type === logic.actionTypes.setCorrelationDetailedFeedbackVisible &&
action.payload.visible === true,
])
.toMatchValues(logic, {
correlationDetailedFeedbackVisible: true,
})
})

it('doesnt opens detailed feedback on selecting an invalid rating', async () => {
await expectLogic(logic, () => {
logic.actions.setCorrelationFeedbackRating(0)
})
.toMatchValues(logic, {
correlationFeedbackRating: 0,
})
.toDispatchActions(logic, [
(action) =>
action.type === logic.actionTypes.setCorrelationDetailedFeedbackVisible &&
action.payload.visible === false,
])
.toMatchValues(logic, {
correlationDetailedFeedbackVisible: false,
})
})

it('captures emoji feedback properly', async () => {
jest.spyOn(posthog, 'capture')
await expectLogic(logic, () => {
logic.actions.setCorrelationFeedbackRating(1)
})
.toMatchValues(logic, {
// reset after sending feedback
correlationFeedbackRating: 1,
})
.toDispatchActions(eventUsageLogic, ['reportCorrelationAnalysisFeedback'])

expect(posthog.capture).toBeCalledWith('correlation analysis feedback', { rating: 1 })
})

it('goes away on sending feedback, capturing it properly', async () => {
jest.spyOn(posthog, 'capture')
await expectLogic(logic, () => {
logic.actions.setCorrelationFeedbackRating(2)
logic.actions.setCorrelationDetailedFeedback('tests')
logic.actions.sendCorrelationAnalysisFeedback()
})
.toMatchValues(logic, {
// reset after sending feedback
correlationFeedbackRating: 0,
correlationDetailedFeedback: '',
correlationFeedbackHidden: true,
})
.toDispatchActions(eventUsageLogic, ['reportCorrelationAnalysisDetailedFeedback'])
.toFinishListeners()

await expectLogic(eventUsageLogic).toFinishListeners()

expect(posthog.capture).toBeCalledWith('correlation analysis feedback', { rating: 2 })
expect(posthog.capture).toBeCalledWith('correlation analysis detailed feedback', {
rating: 2,
comments: 'tests',
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const funnelCorrelationFeedbackLogic = kea<funnelCorrelationFeedbackLogic
key(keyForInsightLogicProps('insight_funnel')),
path((key) => ['scenes', 'funnels', 'funnelCorrelationFeedbackLogic', key]),

connect((props) => ({
connect((props: InsightLogicProps) => ({
actions: [funnelLogic(props), ['loadEventCorrelations', 'loadPropertyCorrelations']],
})),

Expand Down
79 changes: 0 additions & 79 deletions frontend/src/scenes/funnels/funnelLogic.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DEFAULT_EXCLUDED_PERSON_PROPERTIES, funnelLogic } from './funnelLogic'
import { MOCK_DEFAULT_TEAM, MOCK_TEAM_ID } from 'lib/api.mock'
import posthog from 'posthog-js'
import { expectLogic, partial } from 'kea-test-utils'
import { initKeaTests } from '~/test/init'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
Expand Down Expand Up @@ -1054,84 +1053,6 @@ describe('funnelLogic', () => {
})
})

describe('Correlation Feedback flow', () => {
beforeEach(async () => {
await initFunnelLogic()
})
it('opens detailed feedback on selecting a valid rating', async () => {
await expectLogic(logic, () => {
logic.actions.setCorrelationFeedbackRating(1)
})
.toMatchValues(logic, {
correlationFeedbackRating: 1,
})
.toDispatchActions(logic, [
(action) =>
action.type === logic.actionTypes.setCorrelationDetailedFeedbackVisible &&
action.payload.visible === true,
])
.toMatchValues(logic, {
correlationDetailedFeedbackVisible: true,
})
})

it('doesnt opens detailed feedback on selecting an invalid rating', async () => {
await expectLogic(logic, () => {
logic.actions.setCorrelationFeedbackRating(0)
})
.toMatchValues(logic, {
correlationFeedbackRating: 0,
})
.toDispatchActions(logic, [
(action) =>
action.type === logic.actionTypes.setCorrelationDetailedFeedbackVisible &&
action.payload.visible === false,
])
.toMatchValues(logic, {
correlationDetailedFeedbackVisible: false,
})
})

it('Captures emoji feedback properly', async () => {
jest.spyOn(posthog, 'capture')
await expectLogic(logic, () => {
logic.actions.setCorrelationFeedbackRating(1)
})
.toMatchValues(logic, {
// reset after sending feedback
correlationFeedbackRating: 1,
})
.toDispatchActions(eventUsageLogic, ['reportCorrelationAnalysisFeedback'])

expect(posthog.capture).toBeCalledWith('correlation analysis feedback', { rating: 1 })
})

it('goes away on sending feedback, capturing it properly', async () => {
jest.spyOn(posthog, 'capture')
await expectLogic(logic, () => {
logic.actions.setCorrelationFeedbackRating(2)
logic.actions.setCorrelationDetailedFeedback('tests')
logic.actions.sendCorrelationAnalysisFeedback()
})
.toMatchValues(logic, {
// reset after sending feedback
correlationFeedbackRating: 0,
correlationDetailedFeedback: '',
correlationFeedbackHidden: true,
})
.toDispatchActions(eventUsageLogic, ['reportCorrelationAnalysisDetailedFeedback'])
.toFinishListeners()

await expectLogic(eventUsageLogic).toFinishListeners()

expect(posthog.capture).toBeCalledWith('correlation analysis feedback', { rating: 2 })
expect(posthog.capture).toBeCalledWith('correlation analysis detailed feedback', {
rating: 2,
comments: 'tests',
})
})
})

describe('funnel simple vs. advanced mode', () => {
beforeEach(async () => {
await initFunnelLogic()
Expand Down

0 comments on commit 2986eed

Please sign in to comment.