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.

fix(customer-analytics): gate expanded-row account snapshots on expansion content (#68004)

Arthur Moreira de Deus893ea9626916
diff --git a/products/customer_analytics/frontend/components/Accounts/AccountBillingExpansion.tsx b/products/customer_analytics/frontend/components/Accounts/AccountBillingExpansion.tsx
index 8e56d6ca50f2..42694d999510 100644
--- a/products/customer_analytics/frontend/components/Accounts/AccountBillingExpansion.tsx
+++ b/products/customer_analytics/frontend/components/Accounts/AccountBillingExpansion.tsx
@@ -13,7 +13,10 @@ import { AccountBillingKind, accountBillingLogic } from './accountBillingLogic'
function BillingInsightNotFound({ kind }: { kind: AccountBillingKind }): JSX.Element {
const Hog = kind === 'spend' ? BurningMoneyHog : HedgehogMagnifyingGlass
return (
- <div className="flex flex-col items-center justify-center gap-2 p-8 text-center">
+ <div
+ className="flex flex-col items-center justify-center gap-2 p-8 text-center"
+ data-attr="account-billing-insight-not-found"
+ >
<Hog className="w-24 h-24" />
<h4 className="mb-0">No billing {kind} insight here</h4>
<p className="text-secondary max-w-sm mb-0">
diff --git a/products/customer_analytics/frontend/components/Accounts/AccountNotebooksExpansion.tsx b/products/customer_analytics/frontend/components/Accounts/AccountNotebooksExpansion.tsx
index a51f8f0b7538..9cf402eba5fd 100644
--- a/products/customer_analytics/frontend/components/Accounts/AccountNotebooksExpansion.tsx
+++ b/products/customer_analytics/frontend/components/Accounts/AccountNotebooksExpansion.tsx
@@ -177,7 +177,10 @@ export function AccountNotebooksExpansion({
]
return (
- <div className="sticky left-0 w-[100cqw] max-w-full overflow-x-hidden p-3 bg-bg-light">
+ <div
+ className="sticky left-0 w-[100cqw] max-w-full overflow-x-hidden p-3 bg-bg-light"
+ data-attr="account-expansion"
+ >
<div className="flex gap-4">
<div className="w-fit shrink-0">
<UsefulLinks accountId={accountId} />
diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsTab.stories.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsTab.stories.tsx
index 27a1f8df3f7f..3679d9ccbd25 100644
--- a/products/customer_analytics/frontend/components/Accounts/AccountsTab.stories.tsx
+++ b/products/customer_analytics/frontend/components/Accounts/AccountsTab.stories.tsx
@@ -201,6 +201,13 @@ async function expandAndOpenTab(canvasElement: HTMLElement, tab: 'Usage' | 'Spen
await userEvent.click(await canvas.findByRole('tab', { name: tab }))
}
+// The snapshot fires well after `play` (page-ready waits, forced reflows, a dispatched resize),
+// and the meta-level waitForSelector is satisfied by a collapsed table. Gating the snapshot on the
+// expanded-row content turns a lost expansion into a retry instead of a flaky collapsed capture.
+const EXPANDED_ROW_TEST_OPTIONS = {
+ waitForSelector: ['[data-attr="accounts-refresh"]', '[data-attr="account-expansion"]'],
+}
+
function mockAccountsQuery(rows: AccountRow[]): (info: MockResolverInfo) => Promise<[number, unknown] | undefined> {
return async ({ request }) => {
const body = (await request.json()) as { query?: { kind?: string } }
@@ -269,6 +276,7 @@ export const FeatureGateOff: Story = {
export const RowExpandedEmpty: Story = {
render: () => <App />,
+ parameters: { testOptions: EXPANDED_ROW_TEST_OPTIONS },
decorators: [
mswDecorator({
get: {
@@ -287,6 +295,7 @@ export const RowExpandedEmpty: Story = {
export const RowExpandedWithNote: Story = {
render: () => <App />,
+ parameters: { testOptions: EXPANDED_ROW_TEST_OPTIONS },
decorators: [
mswDecorator({
get: {
@@ -337,6 +346,7 @@ export const RowExpandedWithNote: Story = {
export const RowExpandedLinksDisabled: Story = {
render: () => <App />,
+ parameters: { testOptions: EXPANDED_ROW_TEST_OPTIONS },
decorators: [
mswDecorator({
get: {
@@ -355,6 +365,11 @@ export const RowExpandedLinksDisabled: Story = {
export const RowExpandedUsageNotFound: Story = {
render: () => <App />,
+ parameters: {
+ testOptions: {
+ waitForSelector: ['[data-attr="accounts-refresh"]', '[data-attr="account-billing-insight-not-found"]'],
+ },
+ },
decorators: billingTabDecorators(EMPTY_INSIGHTS, mockAccountsQuery(SINGLE_ROW)),
play: async ({ canvasElement }) => {
await expandAndOpenTab(canvasElement, 'Usage')