Skip to content

Commit

Permalink
test: Add tests for ToolbarLaunch behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeelaudibert committed Feb 4, 2025
1 parent 6a32519 commit b854805
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
87 changes: 87 additions & 0 deletions frontend/src/scenes/toolbar-launch/ToolbarLaunch.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Meta, StoryFn } from '@storybook/react'
import { useActions, useValues } from 'kea'
import { router } from 'kea-router'
import { useEffect } from 'react'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'

import { mswDecorator, useStorybookMocks } from '~/mocks/browser'
import { TeamPublicType } from '~/types'

import { ToolbarLaunch } from './ToolbarLaunch'

const meta: Meta = {
title: 'Scenes-Other/ToolbarLaunch',
parameters: {
layout: 'fullscreen',
testOptions: {
includeNavigationInSnapshot: true,
},
featureFlags: ['web-experiments', 'web-vitals', 'web-vitals-toolbar'],
viewMode: 'story',
mockDate: '2024-01-01',
},
decorators: [
mswDecorator({
post: {
'/api/environments/:environment_id/query/': () => [
200,
{
results: [
['https://posthog.com', 150],
['https://app.posthog.com', 100],
['https://docs.posthog.com', 75],
],
},
],
},
}),
],
}
export default meta

const Template: StoryFn = () => {
useEffect(() => {
router.actions.push(urls.dashboards())
}, [])

return <ToolbarLaunch />
}

export const Default = Template.bind({})

export const NoUrlsTemplate: StoryFn = () => {
const { currentTeam } = useValues(teamLogic)
const { loadCurrentTeamSuccess } = useActions(teamLogic)

useEffect(() => {
const team = { ...currentTeam, app_urls: [] }
loadCurrentTeamSuccess(team as TeamPublicType)
}, []) // eslint-disable-line react-hooks/exhaustive-deps

return <Template />
}

export const NoSuggestionsTemplate: StoryFn = () => {
useStorybookMocks({
post: { '/api/environments/:environment_id/query/': () => [200, { results: [] }] },
})

return <Template />
}

export const EmptyStateTemplate: StoryFn = () => {
const { currentTeam } = useValues(teamLogic)
const { loadCurrentTeamSuccess } = useActions(teamLogic)

useEffect(() => {
const team = { ...currentTeam, app_urls: [] }
loadCurrentTeamSuccess(team as TeamPublicType)
}, []) // eslint-disable-line react-hooks/exhaustive-deps

useStorybookMocks({
post: { '/api/environments/:environment_id/query/': () => [200, { results: [] }] },
})

return <Template />
}
2 changes: 1 addition & 1 deletion frontend/src/scenes/toolbar-launch/ToolbarLaunch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const scene: SceneExport = {
component: ToolbarLaunch,
}

function ToolbarLaunch(): JSX.Element {
export function ToolbarLaunch(): JSX.Element {
const isExperimentsEnabled = useFeatureFlag('WEB_EXPERIMENTS')
const isWebVitalsEnabled = useFeatureFlag('WEB_VITALS')
const isWebVitalsToolbarEnabled = useFeatureFlag('WEB_VITALS_TOOLBAR')
Expand Down

0 comments on commit b854805

Please sign in to comment.