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(frontend): clear the ByRole name-query backlog, flip semgrep rule to blocking (#68740)

Paul D'Ambra23f060a2b209
diff --git a/.github/workflows/ci-security.yaml b/.github/workflows/ci-security.yaml
index 7c8994268e08..6d6884471133 100644
--- a/.github/workflows/ci-security.yaml
+++ b/.github/workflows/ci-security.yaml
@@ -293,7 +293,7 @@ jobs:
--metrics=off \
--verbose \
--timeout 300 \
- bin/ common/ ee/ frontend/ posthog/ products/
+ bin/ common/ ee/ frontend/ packages/ posthog/ products/
# Pass 2: enforce ERROR-severity rules. Any finding fails the
# job — regression guards live here.
@@ -309,7 +309,7 @@ jobs:
--metrics=off \
--verbose \
--timeout 300 \
- bin/ common/ ee/ frontend/ posthog/ products/
+ bin/ common/ ee/ frontend/ packages/ posthog/ products/
semgrep-test-rules:
runs-on: ubuntu-latest
diff --git a/.semgrep/rules/devex/jest-no-byrole-name-queries.yaml b/.semgrep/rules/devex/jest-no-byrole-name-queries.yaml
index 412eabc8d46d..7de483eb4398 100644
--- a/.semgrep/rules/devex/jest-no-byrole-name-queries.yaml
+++ b/.semgrep/rules/devex/jest-no-byrole-name-queries.yaml
@@ -17,12 +17,12 @@ rules:
• `getByLabelText(...)` when the element is identified by aria-label
• scope with `within(<small container>)` if a role query is genuinely needed
- This rule is informational, not blocking: role+name queries on small
- DOMs (a single button, a dialog) are fine, and are sometimes chosen
- deliberately for resilience to markup changes. If yours is one of
- those, add `// nosemgrep: jest-no-byrole-name-queries` with a short
- reason — but check the suite's runtime first.
- severity: WARNING
+ Role+name queries on small DOMs (a single button, a dialog) are
+ sometimes chosen deliberately, e.g. to assert a component's
+ accessibility contract or to survive a markup swap. If yours is one
+ of those, add `// nosemgrep: jest-no-byrole-name-queries` with a
+ short reason — but check the suite's runtime first.
+ severity: ERROR
languages: [typescript, javascript]
paths:
include:
diff --git a/frontend/src/exporter/Exporter.test.tsx b/frontend/src/exporter/Exporter.test.tsx
index dccd8a1be1b5..f11237140ce5 100644
--- a/frontend/src/exporter/Exporter.test.tsx
+++ b/frontend/src/exporter/Exporter.test.tsx
@@ -46,11 +46,11 @@ describe('Exporter (shared dashboard)', () => {
})
it('shows auto refresh text in header', () => {
- const { getAllByRole, getAllByText } = render(<Exporter {...makeDashboardExport()} />)
+ const { getAllByText } = render(<Exporter {...makeDashboardExport()} />)
// The dashboard header can be rendered multiple times depending on internal
// export layout/portal behavior.
- const headings = getAllByRole('heading', { name: 'My shared dashboard' })
+ const headings = getAllByText('My shared dashboard')
expect(headings.length).toBeGreaterThan(0)
expect(getAllByText(/Auto refresh every/i).length).toBeGreaterThan(0)
})
diff --git a/frontend/src/lib/components/DatePicker/DatePicker.test.tsx b/frontend/src/lib/components/DatePicker/DatePicker.test.tsx
index e0e32d8939e4..4d6426f92da7 100644
--- a/frontend/src/lib/components/DatePicker/DatePicker.test.tsx
+++ b/frontend/src/lib/components/DatePicker/DatePicker.test.tsx
@@ -101,8 +101,8 @@ describe('DatePicker', () => {
await userEvent.click(within(container).getByText('January 15, 2023'))
// Accessible queries (role + name), not implementation-specific CSS classes / data-attrs,
// so this survives the eventual swap of the backing calendar.
- await userEvent.click(await screen.findByRole('button', { name: '20' }))
- await userEvent.click(screen.getByRole('button', { name: 'Apply' }))
+ await userEvent.click(await screen.findByRole('button', { name: '20' })) // nosemgrep: jest-no-byrole-name-queries
+ await userEvent.click(screen.getByRole('button', { name: 'Apply' })) // nosemgrep: jest-no-byrole-name-queries
expect(onChange).toHaveBeenCalledTimes(1)
expect(onChange.mock.calls[0][0].format('YYYY-MM-DD')).toBe('2023-01-20')
@@ -184,7 +184,7 @@ describe('DatePicker', () => {
])('maps %s onto the Quill panel time props', async (_name, props, showTime, showTimeToggle) => {
const { container } = renderDatePicker(dayjs('2023-01-15'), props)
- await userEvent.click(within(container).getByRole('button', { name: /January 15, 2023/ }))
+ await userEvent.click(within(container).getByRole('button', { name: /January 15, 2023/ })) // nosemgrep: jest-no-byrole-name-queries
expect(mockQuillPanelProps.showTime).toBe(showTime)
expect(mockQuillPanelProps.showTimeToggle).toBe(showTimeToggle)
@@ -206,15 +206,14 @@ describe('DatePicker', () => {
showTimeToggle: true,
})
- const trigger = within(container).getByRole('button', { name: /January 15, 2023/ })
+ const trigger = within(container).getByRole('button', { name: /January 15, 2023/ }) // nosemgrep: jest-no-byrole-name-queries
expect(trigger.textContent).toBe('January 15, 2023')
await userEvent.click(trigger)
await userEvent.click(await screen.findByText('stub-time-on'))
- expect(within(container).getByRole('button', { name: /January 15, 2023/ }).textContent).toBe(
- 'January 15, 2023 09:30'
- )
+ const updatedTrigger = within(container).getByRole('button', { name: /January 15, 2023/ }) // nosemgrep: jest-no-byrole-name-queries
+ expect(updatedTrigger.textContent).toBe('January 15, 2023 09:30')
expect(mockQuillPanelProps.showTime).toBe(true)
})
diff --git a/frontend/src/lib/components/MarkdownEditor/inline/inlineMarkdownSlashCommands.test.tsx b/frontend/src/lib/components/MarkdownEditor/inline/inlineMarkdownSlashCommands.test.tsx
index 44973a8c6b5b..b10d1367c0b0 100644
--- a/frontend/src/lib/components/MarkdownEditor/inline/inlineMarkdownSlashCommands.test.tsx
+++ b/frontend/src/lib/components/MarkdownEditor/inline/inlineMarkdownSlashCommands.test.tsx
@@ -101,8 +101,8 @@ describe('InlineMarkdownSlashMenu', () => {
/>
)
- expect(screen.getByRole('button', { name: /Bold/i })).toBeInTheDocument()
- expect(screen.queryByRole('button', { name: /Image/i })).not.toBeInTheDocument()
+ expect(screen.getByText('Bold')).toBeInTheDocument()
+ expect(screen.queryByText('Image')).not.toBeInTheDocument()
})
it('hides the Image row when slash image upload is disabled on the host ref', () => {
@@ -123,7 +123,7 @@ describe('InlineMarkdownSlashMenu', () => {
/>
)
- expect(screen.queryByRole('button', { name: /Image/i })).not.toBeInTheDocument()
+ expect(screen.queryByText('Image')).not.toBeInTheDocument()
})
it('disables Image when object storage is not available', () => {
@@ -146,7 +146,7 @@ describe('InlineMarkdownSlashMenu', () => {
/>
)
- const imageRow = screen.getByRole('button', { name: /Image/i })
+ const imageRow = screen.getByText('Image').closest('button')
expect(imageRow).toHaveAttribute('aria-disabled', 'true')
})
@@ -210,7 +210,7 @@ describe('InlineMarkdownSlashMenu', () => {
})
}
- expect(screen.getByRole('button', { name: /Image/i })).toHaveClass('LemonButton--active')
+ expect(screen.getByText('Image').closest('button')).toHaveClass('LemonButton--active')
slashImageHostRef.current.showSlashImageUpload = false
rerender(
@@ -224,8 +224,8 @@ describe('InlineMarkdownSlashMenu', () => {
/>
)
- expect(screen.queryByRole('button', { name: /Image/i })).not.toBeInTheDocument()
- expect(screen.getByRole('button', { name: /Gamma/i })).toHaveClass('LemonButton--active')
+ expect(screen.queryByText('Image')).not.toBeInTheDocument()
+ expect(screen.getByText('Gamma').closest('button')).toHaveClass('LemonButton--active')
})
it('choosing Image deletes the slash range and opens the host picker', () => {
@@ -255,7 +255,7 @@ describe('InlineMarkdownSlashMenu', () => {
/>
)
- fireEvent.click(screen.getByRole('button', { name: /Image/i }))
+ fireEvent.click(screen.getByText('Image'))
expect(deleteRun).toHaveBeenCalled()
expect(onClose).toHaveBeenCalled()
@@ -291,7 +291,7 @@ describe('InlineMarkdownSlashMenu', () => {
/>
)
- fireEvent.click(screen.getByRole('button', { name: /Link/i }))
+ fireEvent.click(screen.getByText('Link'))
expect(deleteRun).toHaveBeenCalled()
expect(onClose).toHaveBeenCalled()
diff --git a/frontend/src/lib/components/MarkdownEditor/rich/RichMarkdownEditor.test.tsx b/frontend/src/lib/components/MarkdownEditor/rich/RichMarkdownEditor.test.tsx
index db88ee45c666..f43b334e9002 100644
--- a/frontend/src/lib/components/MarkdownEditor/rich/RichMarkdownEditor.test.tsx
+++ b/frontend/src/lib/components/MarkdownEditor/rich/RichMarkdownEditor.test.tsx
@@ -113,7 +113,7 @@ describe('RichMarkdownEditor', () => {
/>
)
- expect(screen.getByRole('button', { name: 'Strikethrough' })).toBeInTheDocument()
+ expect(screen.getByLabelText('Strikethrough')).toBeInTheDocument()
})
it('invokes toggleStrike when Strikethrough toolbar button is clicked', () => {
@@ -135,7 +135,7 @@ describe('RichMarkdownEditor', () => {
/>
)
- fireEvent.click(screen.getByRole('button', { name: 'Strikethrough' }))
+ fireEvent.click(screen.getByLabelText('Strikethrough'))
expect(toggleStrike).toHaveBeenCalled()
expect(run).toHaveBeenCalled()
@@ -152,7 +152,7 @@ describe('RichMarkdownEditor', () => {
/>
)
- fireEvent.click(screen.getAllByRole('tab', { name: 'Preview' })[0])
+ fireEvent.click(screen.getAllByText('Preview')[0])
expect(screen.getByText('Custom Preview Render')).toBeInTheDocument()
})
diff --git a/frontend/src/lib/components/PropertiesTable/PropertiesTable.test.tsx b/frontend/src/lib/components/PropertiesTable/PropertiesTable.test.tsx
index a23445d8b4a6..9a51d9b8c9ef 100644
--- a/frontend/src/lib/components/PropertiesTable/PropertiesTable.test.tsx
+++ b/frontend/src/lib/components/PropertiesTable/PropertiesTable.test.tsx
@@ -61,7 +61,11 @@ const openMenu = async (container: HTMLElement): Promise<void> => {
}
const clickMenuItem = (label: string): void => {
- fireEvent.click(screen.getByRole('menuitem', { name: label }))
+ const item = screen.getAllByRole('menuitem').find((el) => el.textContent === label)
+ if (!item) {
+ throw new Error(`menu item "${label}" not found`)
+ }
+ fireEvent.click(item)
}
const typeAndSave = (input: HTMLInputElement, newText: string): void => {
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilterPinning.test.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilterPinning.test.tsx
index df0aabeddce5..ba772759a21d 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilterPinning.test.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilterPinning.test.tsx
@@ -125,7 +125,7 @@ describe('TaxonomicFilter pinning', () => {
await userEvent.hover(screen.getByTestId('prop-filter-event_properties-0'))
await waitFor(() => {
- const pinButtons = screen.queryAllByRole('button', { name: /pin/i })
+ const pinButtons = screen.queryAllByTestId('definition-popover-pin')
expect(pinButtons.length).toBeGreaterThan(0)
})
})
diff --git a/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.test.tsx b/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.test.tsx
index 4c7396daa4a8..0eab232be7a6 100644
--- a/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.test.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.test.tsx
@@ -100,6 +100,18 @@ function rowTexts(): string[] {
)
}
+// The category Select popup portal — scoping option lookups here avoids matching
+// row badges/labels that repeat the option text (e.g. "Recent", "Pinned").
+async function openedCategoryPopup(): Promise<HTMLElement> {
+ return await waitFor(() => {
+ const popup = document.querySelector<HTMLElement>('[data-slot="select-content"]')
+ if (!popup) {
+ throw new Error('category select popup not open')
+ }
+ return popup
+ })
+}
+
describe('MenuFilterCombobox', () => {
beforeEach(() => {
__clearTaxonomicResourceCache()
@@ -536,8 +548,8 @@ describe('MenuFilterCombobox', () => {
groupTypes: [TaxonomicFilterGroupType.EventProperties, TaxonomicFilterGroupType.PageviewUrls],
})
- await user.click(screen.getByRole('combobox', { name: 'Filter category' }))
- expect(screen.queryByRole('option', { name: 'Pageview URLs' })).not.toBeInTheDocument()
+ await user.click(screen.getByLabelText('Filter category'))
+ expect(within(await openedCategoryPopup()).queryByText('Pageview URLs')).not.toBeInTheDocument()
})
it('commits the typed query as the value so it becomes $current_url contains <query>', async () => {
@@ -600,7 +612,7 @@ describe('MenuFilterCombobox', () => {
// (pageview_urls is not a navigable option) and the All-surface
// content must render rather than an empty hidden-category list.
await waitFor(() => expect(rowTexts().some((t) => t.includes('$browser'))).toBe(true))
- expect(screen.getByRole('combobox', { name: 'Filter category' })).toHaveTextContent('All')
+ expect(screen.getByLabelText('Filter category')).toHaveTextContent('All')
// The committed selection stays reachable via the selected-entry prepend.
expect(rowTexts().some((t) => t.includes('checkout'))).toBe(true)
})
@@ -631,7 +643,7 @@ describe('MenuFilterCombobox', () => {
await waitFor(() => expect(rowTexts().some((t) => t.includes('recent_signup'))).toBe(true))
expect(rowTexts().some((t) => t.includes('pinned_purchase'))).toBe(true)
- expect(screen.getByRole('combobox', { name: 'Filter category' })).toHaveTextContent('All')
+ expect(screen.getByLabelText('Filter category')).toHaveTextContent('All')
})
it('opens focused on All, not the selected item category, when an event is already selected', async () => {
@@ -655,7 +667,7 @@ describe('MenuFilterCombobox', () => {
</Provider>
)
- const category = await screen.findByRole('combobox', { name: 'Filter category' })
+ const category = await screen.findByLabelText('Filter category')
// Wait for the Select to paint its active-category label before asserting.
await waitFor(() => expect(category.textContent || '').toMatch(/All|Events/))
expect(category).toHaveTextContent('All')
@@ -785,9 +797,10 @@ describe('MenuFilterCombobox', () => {
pinnedEntries: [makeEntry(TaxonomicFilterGroupType.EventProperties, 'p', 'Event properties')],
})
- await user.click(screen.getByRole('combobox', { name: 'Filter category' }))
- expect(await screen.findByRole('option', { name: 'Recent' })).toBeInTheDocument()
- expect(screen.getByRole('option', { name: 'Pinned' })).toBeInTheDocument()
+ await user.click(screen.getByLabelText('Filter category'))
+ const popup = await openedCategoryPopup()
+ expect(await within(popup).findByText('Recent')).toBeInTheDocument()
+ expect(within(popup).getByText('Pinned')).toBeInTheDocument()
})
it('forwards row selection context on commit and does not emit the legacy event itself', async () => {
@@ -962,7 +975,7 @@ describe('MenuFilterCombobox', () => {
)
const callsBeforeOptIn = apiGet.mock.calls.length
- await user.click(await screen.findByRole('button', { name: 'Include stale events' }))
+ await user.click(await screen.findByText('Include stale events'))
// Opting in emits the legacy toggle event…
expect(captureMock).toHaveBeenCalledWith(
@@ -988,10 +1001,10 @@ describe('MenuFilterCombobox', () => {
})
// Narrow to a single category so the cross-category jump becomes relevant
- await user.click(screen.getByRole('combobox', { name: 'Filter category' }))
- await user.click(await screen.findByRole('option', { name: 'Cohorts' }))
+ await user.click(screen.getByLabelText('Filter category'))
+ await user.click(await within(await openedCategoryPopup()).findByText('Cohorts'))
- const jumpButton = await screen.findByRole('button', { name: 'Check for results in other categories' })
+ const jumpButton = await screen.findByText('Check for results in other categories')
await user.click(jumpButton)
expect(captureMock).toHaveBeenCalledWith(
@@ -1000,10 +1013,8 @@ describe('MenuFilterCombobox', () => {
)
// Back on the All scope, the jump no longer applies
await waitFor(() => {
- expect(screen.getByRole('combobox', { name: 'Filter category' })).toHaveTextContent('All')
- expect(
- screen.queryByRole('button', { name: 'Check for results in other categories' })
- ).not.toBeInTheDocument()
+ expect(screen.getByLabelText('Filter category')).toHaveTextContent('All')
+ expect(screen.queryByText('Check for results in other categories')).not.toBeInTheDocument()
})
})
@@ -1016,7 +1027,7 @@ describe('MenuFilterCombobox', () => {
})
await waitFor(() => expect(screen.getByTestId('menu-filter-empty')).toBeInTheDocument())
- expect(screen.queryByRole('button', { name: 'Check for results in other categories' })).not.toBeInTheDocument()
+ expect(screen.queryByText('Check for results in other categories')).not.toBeInTheDocument()
})
describe('reveal barrier', () => {
@@ -1062,7 +1073,7 @@ describe('MenuFilterCombobox', () => {
// Change query: the refetch is in flight. `keepPreviousData` means the stale
// `alpha_prop` is still in the list data, but the barrier must hide it behind a
// skeleton rather than leaking it (the bug this ports the legacy barrier to fix).
- await user.click(screen.getByRole('button', { name: 'change-query' }))
+ await user.click(screen.getByText('change-query'))
await waitFor(() => expect(screen.getByTestId('menu-filter-loading')).toBeInTheDocument())
expect(rowTexts().some((t) => t.includes('alpha_prop'))).toBe(false)
diff --git a/frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.inputTrigger.test.tsx b/frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.inputTrigger.test.tsx
index 9cbbf0fd37be..b5d4bff6ebf9 100644
--- a/frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.inputTrigger.test.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.inputTrigger.test.tsx
@@ -78,13 +78,13 @@ describe('TaxonomicFilterMenu input trigger', () => {
expect(screen.getByTestId('taxonomic-filter-menu-input')).toBeInTheDocument()
expect(screen.getByRole('textbox')).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Open filter menu' })).toBeInTheDocument()
+ expect(screen.getByLabelText('Open filter menu')).toBeInTheDocument()
})
it('opens the dropdown menu (without a redundant "New filter…" item) when the filter icon is clicked', async () => {
renderInputTriggerMenu()
- await userEvent.click(screen.getByRole('button', { name: 'Open filter menu' }))
+ await userEvent.click(screen.getByLabelText('Open filter menu'))
// The menu opens — its always-present "HogQL expression" entry confirms it.
await waitFor(() => {
@@ -124,7 +124,7 @@ describe('TaxonomicFilterMenu input trigger', () => {
expect(screen.queryByTestId('taxonomic-filter-menu-input')).not.toBeInTheDocument()
// The search field renders in the trigger row beside the filter-icon
// button (chrome opens around it), not adrift in the popover.
- const iconButton = screen.getByRole('button', { name: 'Open filter menu' })
+ const iconButton = screen.getByLabelText('Open filter menu')
const searchInput = screen.getByTestId('menu-filter-search')
expect(iconButton.closest('.LemonInput')).toContainElement(searchInput)
})
diff --git a/frontend/src/lib/components/TaxonomicPopover/TaxonomicPopoverMenu.inputTrigger.test.tsx b/frontend/src/lib/components/TaxonomicPopover/TaxonomicPopoverMenu.inputTrigger.test.tsx
index c4ca4bdd0cd2..299bec9a6f31 100644
--- a/frontend/src/lib/components/TaxonomicPopover/TaxonomicPopoverMenu.inputTrigger.test.tsx
+++ b/frontend/src/lib/components/TaxonomicPopover/TaxonomicPopoverMenu.inputTrigger.test.tsx
@@ -74,13 +74,13 @@ describe('TaxonomicPopoverMenu input trigger (lazy placeholder)', () => {
renderInputTriggerPopoverMenu()
expect(screen.getByTestId('taxonomic-filter-menu-input')).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Open filter menu' })).toBeInTheDocument()
+ expect(screen.getByLabelText('Open filter menu')).toBeInTheDocument()
})
it('arms to the dropdown menu (not the combobox) when the filter icon is clicked from the resting trigger', async () => {
renderInputTriggerPopoverMenu()
- await userEvent.click(screen.getByRole('button', { name: 'Open filter menu' }))
+ await userEvent.click(screen.getByLabelText('Open filter menu'))
// The icon arms straight to the menu — its "HogQL expression" entry confirms it.
await waitFor(() => {
diff --git a/frontend/src/lib/lemon-ui/LemonButton/LemonButton.test.tsx b/frontend/src/lib/lemon-ui/LemonButton/LemonButton.test.tsx
index c8ad26e453d9..976e3422ff12 100644
--- a/frontend/src/lib/lemon-ui/LemonButton/LemonButton.test.tsx
+++ b/frontend/src/lib/lemon-ui/LemonButton/LemonButton.test.tsx
@@ -52,7 +52,7 @@ describe('LemonButton', () => {
</form>
)
- await user.click(screen.getByRole('button', { name: label }))
+ await user.click(screen.getByRole('button'))
expect(fn).not.toHaveBeenCalled()
})
@@ -67,7 +67,7 @@ describe('LemonButton', () => {
</LemonButton>
)
- await user.click(screen.getByRole('button', { name: 'Go' }))
+ await user.click(screen.getByRole('button'))
expect(onClick).not.toHaveBeenCalled()
})
@@ -96,7 +96,7 @@ describe('LemonButton', () => {
</form>
)
- const input = screen.getByRole('textbox', { name: 'Field' })
+ const input = screen.getByLabelText('Field')
input.focus()
expect(input).toHaveFocus()
await user.keyboard('{Enter}')
@@ -114,7 +114,7 @@ describe('LemonButton', () => {
</form>
)
- await user.click(screen.getByRole('button', { name: 'Save' }))
+ await user.click(screen.getByRole('button'))
expect(onSubmit).toHaveBeenCalledTimes(1)
})
diff --git a/frontend/src/lib/lemon-ui/LemonDialog/LemonDialog.test.tsx b/frontend/src/lib/lemon-ui/LemonDialog/LemonDialog.test.tsx
index 5b9c65f68d04..e8b2e0b67afc 100644
--- a/frontend/src/lib/lemon-ui/LemonDialog/LemonDialog.test.tsx
+++ b/frontend/src/lib/lemon-ui/LemonDialog/LemonDialog.test.tsx
@@ -45,7 +45,7 @@ describe('LemonFormDialog', () => {
}
const submitViaButton = async (): Promise<void> => {
- await userEvent.click(screen.getByRole('button', { name: 'Submit' }))
+ await userEvent.click(screen.getByText('Submit'))
}
const submitViaEnter = async (): Promise<void> => {
@@ -64,7 +64,7 @@ describe('LemonFormDialog', () => {
await waitFor(() => expect(onSubmit).toHaveBeenCalled())
// Dialog stays open so the user can correct and retry.
- expect(screen.getByRole('button', { name: 'Submit' })).toBeInTheDocument()
+ expect(screen.getByText('Submit')).toBeInTheDocument()
})
it.each([
@@ -78,7 +78,7 @@ describe('LemonFormDialog', () => {
await submitViaButton()
await waitFor(() => expect(onSubmit).toHaveBeenCalled())
- expect(screen.getByRole('button', { name: 'Submit' })).toBeInTheDocument()
+ expect(screen.getByText('Submit')).toBeInTheDocument()
if (shouldCapture) {
expect(captureException).toHaveBeenCalledWith(error)
} else {
@@ -92,7 +92,7 @@ describe('LemonFormDialog', () => {
renderDialog(onSubmit)
await submitViaButton()
- await waitForElementToBeRemoved(() => screen.queryByRole('button', { name: 'Submit' }))
+ await waitForElementToBeRemoved(() => screen.queryByText('Submit'))
expect(onSubmit).toHaveBeenCalled()
expect(captureException).not.toHaveBeenCalled()
})
diff --git a/frontend/src/lib/lemon-ui/LemonDropdown/LemonDropdown.test.tsx b/frontend/src/lib/lemon-ui/LemonDropdown/LemonDropdown.test.tsx
index b0acfd0573ff..b0d5783a62ee 100644
--- a/frontend/src/lib/lemon-ui/LemonDropdown/LemonDropdown.test.tsx
+++ b/frontend/src/lib/lemon-ui/LemonDropdown/LemonDropdown.test.tsx
@@ -30,7 +30,7 @@ describe('LemonDropdown', () => {
</LemonDropdown>
)
- const trigger = screen.getByRole('button', { name: 'Open' })
+ const trigger = screen.getByText('Open')
const overlay = document.querySelector('.Popover')
expect(overlay).toBeInTheDocument()
diff --git a/frontend/src/lib/lemon-ui/LemonMenu/LemonMenu.test.tsx b/frontend/src/lib/lemon-ui/LemonMenu/LemonMenu.test.tsx
index f1813e32fcd0..a131c8b84888 100644
--- a/frontend/src/lib/lemon-ui/LemonMenu/LemonMenu.test.tsx
+++ b/frontend/src/lib/lemon-ui/LemonMenu/LemonMenu.test.tsx
@@ -29,7 +29,7 @@ describe('LemonMenu', () => {
// The ref must land on the real trigger button, not on the (DOM-less) LemonMenu component.
expect(resolvedNode).toBeInstanceOf(HTMLButtonElement)
- expect(resolvedNode).toBe(screen.getByRole('button', { name: 'Open' }))
+ expect(resolvedNode).toBe(screen.getByRole('button'))
})
it('clicking the ref-driven trigger opens the menu', async () => {
@@ -50,7 +50,7 @@ describe('LemonMenu', () => {
expect(screen.queryByText('First')).not.toBeInTheDocument()
// Triggering a click through the forwarded ref (as <Shortcut /> does) must open the menu.
- await userEvent.click(screen.getByRole('button', { name: 'Trigger via ref' }))
+ await userEvent.click(screen.getByText('Trigger via ref'))
expect(screen.getByText('First')).toBeInTheDocument()
})
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/PieChart.test.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Charts/PieChart.test.tsx
index da568c538000..1964f89636ad 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/PieChart.test.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/PieChart.test.tsx
@@ -53,6 +53,6 @@ describe('PieChart wrapper', () => {
render(<PieChart {...props} />)
// The quill PieChart canvas carries this accessible name; the legacy chart.js path does not.
- expect(await screen.findByRole('img', { name: /pie chart with/i }, { timeout: 5000 })).toBeInTheDocument()
+ expect(await screen.findByLabelText(/pie chart with/i, {}, { timeout: 5000 })).toBeInTheDocument()
})
})
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlBarGraph.test.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlBarGraph.test.tsx
index 85e0823c83fc..8b9cf6df6cba 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlBarGraph.test.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlBarGraph.test.tsx
@@ -17,8 +17,8 @@ import {
import { ChartDisplayType } from '~/types'
// Neither timeout is set globally (jest.setup leaves asyncUtilTimeout at 1s, jest.config has no
-// testTimeout → 5s): this heavy ~7-logic mount needs findByRole headroom beyond 1s on CI, and
-// sqlChart.hoverTooltip's internal waits (findByRole + tooltip poll) can sum past the 5s default.
+// testTimeout → 5s): this heavy ~7-logic mount needs findBy* headroom beyond 1s on CI, and
+// sqlChart.hoverTooltip's internal waits (findBy* + tooltip poll) can sum past the 5s default.
configure({ asyncUtilTimeout: 5000 })
jest.setTimeout(15000)
@@ -76,7 +76,7 @@ describe('SqlBarGraph', () => {
])('renders both series in the $name layout', async ({ display, extra }) => {
renderBar(display, { yAxis: [{ column: 'a' }, { column: 'b' }], ...extra }, twoSeries())
- await screen.findByRole('img', { name: /chart with 2 data series/i })
+ await screen.findByLabelText(/chart with 2 data series/i)
await waitFor(() => expect(getHogChart().yTicks().length).toBeGreaterThan(0))
})
@@ -87,7 +87,7 @@ describe('SqlBarGraph', () => {
twoSeries()
)
- await screen.findByRole('img', { name: /chart with 2 data series/i })
+ await screen.findByLabelText(/chart with 2 data series/i)
await waitFor(() => expect(getHogChart().yTicks().length).toBeGreaterThan(0))
for (const tick of getHogChart().yTicks()) {
expect(tick).toMatch(/%$/)
@@ -105,7 +105,7 @@ describe('SqlBarGraph', () => {
barFixture([{ name: 'a', valueAt: (i) => (i + 1) * 1000 }])
)
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
const tooltip = await sqlChart.hoverTooltip(HOVER, MONTHS.length)
expect(tooltip.value('a')).toBe('3,000')
@@ -125,7 +125,7 @@ describe('SqlBarGraph', () => {
twoSeries()
)
- await screen.findByRole('img', { name: /chart with 2 data series/i })
+ await screen.findByLabelText(/chart with 2 data series/i)
const labels = [...getLegend(container).querySelectorAll('button')].map((b) => b.textContent)
expect(labels).toEqual(['a', 'b'])
})
@@ -137,7 +137,7 @@ describe('SqlBarGraph', () => {
twoSeries()
)
- await screen.findByRole('img', { name: /chart with 2 data series/i })
+ await screen.findByLabelText(/chart with 2 data series/i)
const bButton = [...getLegend(container).querySelectorAll('button')].find((b) =>
b.textContent?.includes('b')
)!
@@ -155,7 +155,7 @@ describe('SqlBarGraph', () => {
barFixture([{ name: 'a', valueAt: (i) => (i + 1) * 100 }])
)
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
const lines = getHogChart().referenceLines()
expect(lines.map((l) => l.label)).toEqual(['Target'])
expect(lines[0].orientation).toBe('horizontal')
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlLineGraph.test.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlLineGraph.test.tsx
index 20ed143d0275..518e14ce4cb3 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlLineGraph.test.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlLineGraph.test.tsx
@@ -23,8 +23,8 @@ import { SqlLineGraph } from './SqlLineGraph'
// Some blocks below mount the full DataVisualization tree (~7 logics). Neither timeout is set
// globally (jest.setup leaves asyncUtilTimeout at 1s, jest.config has no testTimeout → 5s): the
-// heavy mount needs findByRole headroom beyond 1s on CI, and sqlChart.hoverTooltip's internal
-// waits (findByRole + tooltip poll) can sum past the 5s default.
+// heavy mount needs findBy* headroom beyond 1s on CI, and sqlChart.hoverTooltip's internal
+// waits (findBy* + tooltip poll) can sum past the 5s default.
configure({ asyncUtilTimeout: 5000 })
jest.setTimeout(15000)
@@ -78,7 +78,7 @@ const props = (overrides: Partial<LineGraphProps>): LineGraphProps => ({
const renderChart = async (overrides: Partial<LineGraphProps>): Promise<void> => {
renderWithInsights({ component: <SqlLineGraph {...props(overrides)} /> })
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
}
const lowestTick = (ticks: string[]): number => Math.min(...ticks.map((t) => parseFloat(t.replace(/[^0-9.eE+-]/g, ''))))
@@ -196,7 +196,7 @@ describe('SqlLineGraph', () => {
it('shows one row per series with its own value', async () => {
renderLine({ yAxis: [{ column: 'a' }, { column: 'b' }] }, twoSeries())
- await screen.findByRole('img', { name: /chart with 2 data series/i })
+ await screen.findByLabelText(/chart with 2 data series/i)
const tooltip = await sqlChart.hoverTooltip(HOVER, MONTHS.length)
expect(tooltip.rows()).toEqual(['a', 'b'])
@@ -229,7 +229,7 @@ describe('SqlLineGraph', () => {
])('$name', async ({ showTotalRow, expectedTotal }) => {
renderLine({ yAxis: [{ column: 'a' }, { column: 'b' }], showTotalRow }, twoSeries())
- await screen.findByRole('img', { name: /chart with 2 data series/i })
+ await screen.findByLabelText(/chart with 2 data series/i)
const tooltip = await sqlChart.hoverTooltip(HOVER, MONTHS.length)
expect(tooltip.total()).toBe(expectedTotal)
@@ -248,7 +248,7 @@ describe('SqlLineGraph', () => {
twoSeries()
)
- await screen.findByRole('img', { name: /chart with 2 data series/i })
+ await screen.findByLabelText(/chart with 2 data series/i)
const tooltip = await sqlChart.hoverTooltip(HOVER, MONTHS.length)
expect(tooltip.swatchColors()).toEqual(['rgb(255, 0, 0)', 'rgb(0, 255, 0)'])
@@ -265,7 +265,7 @@ describe('SqlLineGraph', () => {
twoSeries()
)
- await screen.findByRole('img', { name: /chart with 2 data series/i })
+ await screen.findByLabelText(/chart with 2 data series/i)
const labels = [...getLegend(container).querySelectorAll('button')].map((b) => b.textContent)
expect(labels).toEqual(['a', 'b'])
})
@@ -273,7 +273,7 @@ describe('SqlLineGraph', () => {
it('renders no legend by default', async () => {
const { container } = renderLine({ yAxis: [{ column: 'a' }, { column: 'b' }] }, twoSeries())
- await screen.findByRole('img', { name: /chart with 2 data series/i })
+ await screen.findByLabelText(/chart with 2 data series/i)
expect(container.querySelector('[data-attr="hog-chart-timeseries-line-legend"]')).not.toBeInTheDocument()
})
@@ -283,7 +283,7 @@ describe('SqlLineGraph', () => {
twoSeries()
)
- await screen.findByRole('img', { name: /chart with 2 data series/i })
+ await screen.findByLabelText(/chart with 2 data series/i)
const bButton = [...getLegend(container).querySelectorAll('button')].find((b) =>
b.textContent?.includes('b')
)!
@@ -310,7 +310,7 @@ describe('SqlLineGraph', () => {
lineFixture([{ name: 'pageviews', valueAt: (i) => (i + 1) * 100 }])
)
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
expect(getHogChart().xAxisLabel()).toBe(expectedX)
expect(getHogChart().yAxisLabel()).toBe(expectedY)
})
@@ -323,7 +323,7 @@ describe('SqlLineGraph', () => {
lineFixture([{ name: 'pageviews', valueAt: (i) => (i + 1) * 100 }])
)
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
await waitFor(() => expect(getHogChart().xTicks().length).toBeGreaterThan(0))
// Date-axis tick formatter renders month names (year shown at the Jan boundary).
expect(getHogChart().xTicks()).toEqual(expect.arrayContaining(['October', 'November', 'December']))
@@ -335,7 +335,7 @@ describe('SqlLineGraph', () => {
lineFixture([{ name: 'pageviews', valueAt: (i) => (i + 1) * 100 }])
)
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
expect(getHogChart().xTicks()).toHaveLength(0)
})
})
@@ -347,7 +347,7 @@ describe('SqlLineGraph', () => {
lineFixture([{ name: 'a', valueAt: (i) => (i + 1) * 100 }])
)
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
await waitFor(() => expect(getHogChart().yTicks().length).toBeGreaterThan(0))
// A log axis lays out ticks per power of ten (10, 20, … 100, 200, …) rather than evenly.
expect(getHogChart().yTicks()).toEqual(expect.arrayContaining(['10', '100']))
@@ -390,7 +390,7 @@ describe('SqlLineGraph', () => {
lineFixture([{ name: 'a', valueAt: (i) => (i + 1) * 100 }])
)
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
const lines = getHogChart().referenceLines()
expect(lines.map((l) => l.label)).toEqual(expectedLabels)
expect(lines.map((l) => l.orientation)).toEqual(expectedLabels.map(() => 'horizontal'))
@@ -407,7 +407,7 @@ describe('SqlLineGraph', () => {
response: twoSeries(),
})
- await screen.findByRole('img', { name: /chart with 2 data series/i })
+ await screen.findByLabelText(/chart with 2 data series/i)
const tooltip = await sqlChart.hoverTooltip(HOVER, MONTHS.length)
expect(tooltip.value('a')).toBe('300')
})
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlPieGraph.test.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlPieGraph.test.tsx
index 7b126c896bc0..6709a7aa4a98 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlPieGraph.test.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlPieGraph.test.tsx
@@ -58,7 +58,7 @@ function sliceLabelLines(): string[][] {
}
async function waitForSlices(): Promise<void> {
- await screen.findByRole('img', { name: /pie chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/pie chart with/i, {}, { timeout: 5000 })
await waitFor(
() => {
if (sliceLabelLines().length === 0) {
@@ -144,7 +144,7 @@ describe('SqlPieGraph', () => {
it('renders nothing on slices when slice content is none', async () => {
render(<SqlPieGraph {...baseProps({ pie: { sliceContent: 'none' } }, [40, 30, 20, 10])} />)
- await screen.findByRole('img', { name: /pie chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/pie chart with/i, {}, { timeout: 5000 })
expect(sliceLabelLines()).toEqual([])
})
diff --git a/frontend/src/queries/nodes/InsightViz/EditorFilters.test.tsx b/frontend/src/queries/nodes/InsightViz/EditorFilters.test.tsx
index 8bc6d0275018..335b62158b20 100644
--- a/frontend/src/queries/nodes/InsightViz/EditorFilters.test.tsx
+++ b/frontend/src/queries/nodes/InsightViz/EditorFilters.test.tsx
@@ -180,7 +180,7 @@ describe('EditorFilters', () => {
it('expands advanced options section on click', async () => {
setupAndRender(makeFunnelsQuery())
- const advancedButton = screen.getByRole('button', { name: /Advanced options/ })
+ const advancedButton = screen.getByText('Advanced options').closest('button')!
expect(advancedButton).toHaveAttribute('title', 'Show more')
await userEvent.click(advancedButton)
@@ -191,7 +191,7 @@ describe('EditorFilters', () => {
it('disables query-time person properties for data warehouse insights', async () => {
setupAndRender(makeDataWarehouseTrendsQuery())
- await userEvent.click(screen.getByRole('button', { name: /Advanced options/ }))
+ await userEvent.click(screen.getByText('Advanced options'))
const disabledArea = screen.getByText('Use person properties from query time').closest('.LemonDisabledArea')
expect(disabledArea).toHaveAttribute('aria-disabled', 'true')
@@ -207,7 +207,7 @@ describe('EditorFilters', () => {
it('shows funnel settings collapsed by default and expandable', async () => {
setupAndRender(makeFunnelsQuery())
- const settingsButton = screen.getByRole('button', { name: /Funnel settings/ })
+ const settingsButton = screen.getByText('Funnel settings').closest('button')!
expect(settingsButton).toBeInTheDocument()
expect(settingsButton).toHaveAttribute('title', 'Show more')
diff --git a/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx b/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx
index 6672a5ccfa85..04907042073c 100644
--- a/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx
+++ b/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx
@@ -75,7 +75,7 @@ function getSectionTitles(): string[] {
}
async function openOptionsMenu(): Promise<void> {
- const optionsButtons = screen.getAllByRole('button', { name: /Options/ })
+ const optionsButtons = screen.getAllByLabelText('Options')
await userEvent.click(optionsButtons[0])
}
@@ -350,7 +350,7 @@ describe('InsightDisplayConfig', () => {
it('removes axis label option count after clearing a committed label', async () => {
setupAndRender(makeTrendsQuery(ChartDisplayType.ActionsLineGraph, { xAxisLabel: 'Signup date' }))
- const optionsButton = screen.getAllByRole('button', { name: /Options/ })[0]
+ const optionsButton = screen.getAllByLabelText('Options')[0]
expect(optionsButton).toHaveTextContent(/\(1\)/)
await openOptionsMenu()
diff --git a/frontend/src/scenes/cohorts/CohortEdit.test.tsx b/frontend/src/scenes/cohorts/CohortEdit.test.tsx
index 5d832fe8b5c2..c35985cdb3d1 100644
--- a/frontend/src/scenes/cohorts/CohortEdit.test.tsx
+++ b/frontend/src/scenes/cohorts/CohortEdit.test.tsx
@@ -342,7 +342,7 @@ describe('cohortEditLogic', () => {
// Verify Retry button is shown as the primary action in the error banner
// LemonBanner renders action buttons - find the one with "Retry" text
- const retryButtons = screen.getAllByRole('button', { name: 'Retry' })
+ const retryButtons = screen.getAllByText('Retry')
expect(retryButtons.length).toBeGreaterThan(0)
const retryButton = retryButtons[0]
diff --git a/frontend/src/scenes/debug/Modifiers.test.tsx b/frontend/src/scenes/debug/Modifiers.test.tsx
index 2c46a54a71b4..68a5858b6456 100644
--- a/frontend/src/scenes/debug/Modifiers.test.tsx
+++ b/frontend/src/scenes/debug/Modifiers.test.tsx
@@ -120,8 +120,8 @@ describe('Modifiers', () => {
)
expect(screen.getByText('Connection ID:')).toBeInTheDocument()
- await screen.findByRole('option', { name: 'analytics-db (Postgres)' })
- await screen.findByRole('option', { name: 'orders-db (MySQL)' })
+ await screen.findByText('analytics-db (Postgres)')
+ await screen.findByText('orders-db (MySQL)')
await userEvent.selectOptions(screen.getByLabelText('Connection ID:'), 'postgres-connection-id')
diff --git a/frontend/src/scenes/experiments/ExperimentForm/SelectExistingFeatureFlagModal.test.tsx b/frontend/src/scenes/experiments/ExperimentForm/SelectExistingFeatureFlagModal.test.tsx
index f6ef1a135b56..9f17d1455a4e 100644
--- a/frontend/src/scenes/experiments/ExperimentForm/SelectExistingFeatureFlagModal.test.tsx
+++ b/frontend/src/scenes/experiments/ExperimentForm/SelectExistingFeatureFlagModal.test.tsx
@@ -149,7 +149,7 @@ describe('SelectExistingFeatureFlagModal', () => {
render(<SelectExistingFeatureFlagModal onClose={mockOnClose} onSelect={mockOnSelect} />)
- const selectButtons = await screen.findAllByRole('button', { name: 'Select' })
+ const selectButtons = await screen.findAllByText('Select')
await userEvent.click(selectButtons[0])
expect(mockOnSelect).toHaveBeenCalledWith(mockFeatureFlags[0])
@@ -164,7 +164,7 @@ describe('SelectExistingFeatureFlagModal', () => {
render(<SelectExistingFeatureFlagModal onClose={mockOnClose} onSelect={mockOnSelect} />)
- const closeButton = screen.getByRole('button', { name: /close/i })
+ const closeButton = screen.getByLabelText(/close/i)
await userEvent.click(closeButton)
expect(resetFiltersSpy).toHaveBeenCalled()
diff --git a/frontend/src/scenes/experiments/ExperimentForm/VariantDistributionEditor.test.tsx b/frontend/src/scenes/experiments/ExperimentForm/VariantDistributionEditor.test.tsx
index bf7b456ffb82..bd095d251abb 100644
--- a/frontend/src/scenes/experiments/ExperimentForm/VariantDistributionEditor.test.tsx
+++ b/frontend/src/scenes/experiments/ExperimentForm/VariantDistributionEditor.test.tsx
@@ -160,12 +160,13 @@ describe('VariantDistributionEditor', () => {
it('does not show "Add variant" button', () => {
renderEditor()
+ // nosemgrep: jest-no-byrole-name-queries - negative assertion needs the role+name dimension; text-only would pass if the button is gone but the label appears in other copy
expect(screen.queryByRole('button', { name: /add variant/i })).not.toBeInTheDocument()
})
it('does not show pencil icon (customize split toggle)', () => {
renderEditor()
- expect(screen.queryByRole('button', { name: /customize split/i })).not.toBeInTheDocument()
+ expect(screen.queryByLabelText(/customize split/i)).not.toBeInTheDocument()
})
it('does not show rollout percentage slider', () => {
diff --git a/frontend/src/scenes/experiments/ExperimentForm/VariantsPanelCreateFeatureFlag.test.tsx b/frontend/src/scenes/experiments/ExperimentForm/VariantsPanelCreateFeatureFlag.test.tsx
index 2da3ef210601..72a67296d441 100644
--- a/frontend/src/scenes/experiments/ExperimentForm/VariantsPanelCreateFeatureFlag.test.tsx
+++ b/frontend/src/scenes/experiments/ExperimentForm/VariantsPanelCreateFeatureFlag.test.tsx
@@ -103,7 +103,7 @@ describe('VariantsPanelCreateFeatureFlag', () => {
it('renders add variant button', () => {
renderComponent(defaultExperiment)
- expect(screen.getByRole('button', { name: /add variant/i })).toBeInTheDocument()
+ expect(screen.getByText(/add variant/i)).toBeInTheDocument()
})
it('renders experience continuity checkbox', () => {
@@ -118,7 +118,7 @@ describe('VariantsPanelCreateFeatureFlag', () => {
it('adds a new variant when clicking add button', async () => {
renderComponent(defaultExperiment)
- const addButton = screen.getByRole('button', { name: /add variant/i })
+ const addButton = screen.getByText(/add variant/i)
await userEvent.click(addButton)
expect(mockOnChange).toHaveBeenCalledWith({
@@ -135,7 +135,7 @@ describe('VariantsPanelCreateFeatureFlag', () => {
it('redistributes percentages equally when adding variant', async () => {
renderComponent(defaultExperiment)
- const addButton = screen.getByRole('button', { name: /add variant/i })
+ const addButton = screen.getByText(/add variant/i)
await userEvent.click(addButton)
expect(mockOnChange).toHaveBeenCalledWith({
@@ -181,7 +181,7 @@ describe('VariantsPanelCreateFeatureFlag', () => {
const { container } = renderComponent(defaultExperiment)
// Click pencil button to enable custom split editing
- await userEvent.click(screen.getByRole('button', { name: /customize split/i }))
+ await userEvent.click(screen.getByLabelText(/customize split/i))
const percentageInputs = container.querySelectorAll(
'[data-attr="experiment-variant-rollout-percentage-input"]'
@@ -313,7 +313,7 @@ describe('VariantsPanelCreateFeatureFlag', () => {
async ({ inputValue, expectedControl, expectedTest }) => {
const { container } = renderComponent(defaultExperiment)
- const customizeButton = screen.getByRole('button', { name: /customize split/i })
+ const customizeButton = screen.getByLabelText(/customize split/i)
await userEvent.click(customizeButton)
const percentageInputs = container.querySelectorAll(
@@ -345,7 +345,7 @@ describe('VariantsPanelCreateFeatureFlag', () => {
const { container } = renderComponent(threeVariantExperiment)
- const customizeButton = screen.getByRole('button', { name: /customize split/i })
+ const customizeButton = screen.getByLabelText(/customize split/i)
await userEvent.click(customizeButton)
const percentageInputs = container.querySelectorAll(
@@ -439,7 +439,7 @@ describe('VariantsPanelCreateFeatureFlag', () => {
renderComponent(experimentWithRollout)
- const addButton = screen.getByRole('button', { name: /add variant/i })
+ const addButton = screen.getByText(/add variant/i)
await userEvent.click(addButton)
const lastCall = mockOnChange.mock.calls[mockOnChange.mock.calls.length - 1][0]
@@ -553,7 +553,7 @@ describe('VariantsPanelCreateFeatureFlag', () => {
renderComponent(experimentWithMaxVariants)
- const addButton = screen.queryByRole('button', { name: /add variant/i })
+ const addButton = screen.queryByText(/add variant/i)
expect(addButton).not.toBeInTheDocument()
})
})
diff --git a/frontend/src/scenes/experiments/ExperimentForm/VariantsPanelLinkFeatureFlag.test.tsx b/frontend/src/scenes/experiments/ExperimentForm/VariantsPanelLinkFeatureFlag.test.tsx
index 669c0ef39965..706008991bf8 100644
--- a/frontend/src/scenes/experiments/ExperimentForm/VariantsPanelLinkFeatureFlag.test.tsx
+++ b/frontend/src/scenes/experiments/ExperimentForm/VariantsPanelLinkFeatureFlag.test.tsx
@@ -93,7 +93,7 @@ describe('VariantsPanelLinkFeatureFlag', () => {
/>
)
- const selectButton = screen.getByRole('button', { name: 'Select Feature Flag' })
+ const selectButton = screen.getByText('Select Feature Flag')
expect(selectButton).toBeInTheDocument()
})
@@ -105,7 +105,7 @@ describe('VariantsPanelLinkFeatureFlag', () => {
/>
)
- const selectButton = screen.getByRole('button', { name: 'Select Feature Flag' })
+ const selectButton = screen.getByText('Select Feature Flag')
await userEvent.click(selectButton)
expect(mockSetShowFeatureFlagSelector).toHaveBeenCalledTimes(1)
@@ -133,7 +133,7 @@ describe('VariantsPanelLinkFeatureFlag', () => {
/>
)
- const link = screen.getByRole('link', { name: /view feature flag/i })
+ const link = screen.getByTitle('View feature flag')
expect(link).toHaveAttribute('href', `/project/${MOCK_DEFAULT_PROJECT.id}/feature_flags/1`)
expect(link).toHaveAttribute('target', '_blank')
})
@@ -146,7 +146,7 @@ describe('VariantsPanelLinkFeatureFlag', () => {
/>
)
- const changeButton = screen.getByRole('button', { name: 'Change' })
+ const changeButton = screen.getByText('Change')
expect(changeButton).toBeInTheDocument()
})
@@ -158,7 +158,7 @@ describe('VariantsPanelLinkFeatureFlag', () => {
/>
)
- const changeButton = screen.getByRole('button', { name: 'Change' })
+ const changeButton = screen.getByText('Change')
await userEvent.click(changeButton)
expect(mockSetShowFeatureFlagSelector).toHaveBeenCalledTimes(1)
diff --git a/frontend/src/scenes/feature-flags/projects-grid/ProjectsGrid.test.tsx b/frontend/src/scenes/feature-flags/projects-grid/ProjectsGrid.test.tsx
index a30f6499673d..a50ca6e09902 100644
--- a/frontend/src/scenes/feature-flags/projects-grid/ProjectsGrid.test.tsx
+++ b/frontend/src/scenes/feature-flags/projects-grid/ProjectsGrid.test.tsx
@@ -124,7 +124,7 @@ describe('ProjectsGrid', () => {
it('links each flag row to that flag in its own project', async () => {
render(<ProjectsGrid />)
- const link = await screen.findByRole('link', { name: /Cross Project Flag/i })
+ const link = (await screen.findByText(/Cross Project Flag/i)).closest('a')
expect(link).toHaveAttribute('href', `/project/${FLAG_TEAM_ID}/feature_flags/42`)
})
})
diff --git a/frontend/src/scenes/max/components/InputFormArea.test.tsx b/frontend/src/scenes/max/components/InputFormArea.test.tsx
index a339183d0b63..30421eeb4cfd 100644
--- a/frontend/src/scenes/max/components/InputFormArea.test.tsx
+++ b/frontend/src/scenes/max/components/InputFormArea.test.tsx
@@ -62,7 +62,7 @@ describe('MultiQuestionFormInput', () => {
fireEvent.click(screen.getByText('Activation'))
expect(screen.getByText('Which area should I focus on?')).toBeInTheDocument()
- fireEvent.click(screen.getAllByRole('button', { name: 'Skip question' }).at(-1)!)
+ fireEvent.click(screen.getAllByText('Skip question').at(-1)!)
expect(continueAfterForm).toHaveBeenCalledWith({ goal: 'Activation' })
})
@@ -86,7 +86,7 @@ describe('MultiQuestionFormInput', () => {
it('dismisses the form when requested', () => {
render(<MultiQuestionFormInput form={form} />)
- fireEvent.click(screen.getAllByRole('button', { name: 'Dismiss form' }).at(-1)!)
+ fireEvent.click(screen.getAllByLabelText('Dismiss form').at(-1)!)
expect(continueAfterFormDismissal).toHaveBeenCalledTimes(1)
expect(screen.getByText('Dismissing form...')).toBeInTheDocument()
@@ -123,7 +123,7 @@ describe('MultiQuestionFormInput', () => {
// Add a custom entry
const input = screen.getByPlaceholderText('Add your own option...')
fireEvent.change(input, { target: { value: 'Custom insight' } })
- fireEvent.click(screen.getByRole('button', { name: /Add/ }))
+ fireEvent.click(screen.getByText('Add'))
// Click Next to submit the multi_select answer (button says "Next" because
// the parent answers state hasn't been updated with this question's value yet)
diff --git a/frontend/src/scenes/notebooks/Notebook/MarkdownNotebookV2RendererUI.test.tsx b/frontend/src/scenes/notebooks/Notebook/MarkdownNotebookV2RendererUI.test.tsx
index ae24c02626da..0966b2086d8b 100644
--- a/frontend/src/scenes/notebooks/Notebook/MarkdownNotebookV2RendererUI.test.tsx
+++ b/frontend/src/scenes/notebooks/Notebook/MarkdownNotebookV2RendererUI.test.tsx
@@ -104,11 +104,11 @@ describe('MarkdownNotebookV2Renderer UI', () => {
)
}
- const { container, getByRole } = render(<ControlledMarkdownNotebookWithHeader />)
+ const { container, getByText } = render(<ControlledMarkdownNotebookWithHeader />)
expect(container.querySelector('.MarkdownNotebook__debug-drawer')).toBeInstanceOf(HTMLElement)
- fireEvent.click(getByRole('button', { name: /kernel/i }))
+ fireEvent.click(getByText('Kernel'))
expect(onDebugOpenChange).not.toHaveBeenCalled()
expect(settingsLogic.values.showKernelInfo).toBe(true)
diff --git a/frontend/src/scenes/session-recordings/playlist/Playlist.test.tsx b/frontend/src/scenes/session-recordings/playlist/Playlist.test.tsx
index c164280c8c96..ae3db275351e 100644
--- a/frontend/src/scenes/session-recordings/playlist/Playlist.test.tsx
+++ b/frontend/src/scenes/session-recordings/playlist/Playlist.test.tsx
@@ -82,7 +82,7 @@ describe('Playlist', () => {
})
// LemonBanner renders the action twice (wide and narrow responsive variants)
- userEvent.click(screen.getAllByRole('button', { name: 'Show all recordings' })[0])
+ userEvent.click(screen.getAllByText('Show all recordings')[0])
await waitFor(() => {
expect(logic.values.filters.session_ids).toBeUndefined()
diff --git a/frontend/src/scenes/settings/project/ProjectMove.test.tsx b/frontend/src/scenes/settings/project/ProjectMove.test.tsx
index e5a1ce59bb96..d0c411bdd2e3 100644
--- a/frontend/src/scenes/settings/project/ProjectMove.test.tsx
+++ b/frontend/src/scenes/settings/project/ProjectMove.test.tsx
@@ -76,8 +76,8 @@ describe('<ProjectMove />', () => {
it('disables target organizations the user is not an admin of', () => {
const { container } = render(<ProjectMove />)
- expect(screen.getByRole('option', { name: 'Admin Target Org' })).toBeEnabled()
- expect(screen.getByRole('option', { name: 'Member Target Org' })).toBeDisabled()
+ expect(screen.getByText('Admin Target Org')).toBeEnabled()
+ expect(screen.getByText('Member Target Org')).toBeDisabled()
// No org picked yet, so the Move button is blocked.
expect(container.querySelector('[data-attr="move-project-button"]')).toHaveAttribute('aria-disabled', 'true')
})
diff --git a/frontend/src/scenes/settings/user/RealtimeNotificationPreferences.test.tsx b/frontend/src/scenes/settings/user/RealtimeNotificationPreferences.test.tsx
index f08825bd57d2..9423841a48f1 100644
--- a/frontend/src/scenes/settings/user/RealtimeNotificationPreferences.test.tsx
+++ b/frontend/src/scenes/settings/user/RealtimeNotificationPreferences.test.tsx
@@ -39,7 +39,7 @@ describe('<RealtimeNotificationPreferences />', () => {
it('toggling a single type dispatches updateRealtimeNotificationForTeam', async () => {
render(<RealtimeNotificationPreferences />)
- const checkbox = screen.getAllByRole('checkbox', { name: /Comment mentions/i })[0]
+ const checkbox = screen.getAllByLabelText(/Comment mentions/i)[0]
await expectLogic(userLogic, () => userEvent.click(checkbox)).toDispatchActions([
userLogic.actionCreators.updateRealtimeNotificationForTeam('comment_mention', 1, false),
])
@@ -47,7 +47,7 @@ describe('<RealtimeNotificationPreferences />', () => {
it('clicking a project parent dispatches updateRealtimeNotificationForProject with disable', async () => {
render(<RealtimeNotificationPreferences />)
- const projectCheckbox = screen.getAllByRole('checkbox', { name: /Project A/i })[0]
+ const projectCheckbox = screen.getAllByLabelText(/Project A/i)[0]
await expectLogic(userLogic, () => userEvent.click(projectCheckbox)).toDispatchActions([
userLogic.actionCreators.updateRealtimeNotificationForProject(1, ['comment_mention'], false),
])
diff --git a/frontend/src/scenes/surveys/QuickSurveyModal.test.tsx b/frontend/src/scenes/surveys/QuickSurveyModal.test.tsx
index 2a4a155ce4db..93bc91d83e99 100644
--- a/frontend/src/scenes/surveys/QuickSurveyModal.test.tsx
+++ b/frontend/src/scenes/surveys/QuickSurveyModal.test.tsx
@@ -67,7 +67,7 @@ describe('QuickSurveyForm API payloads', () => {
render(<QuickSurveyForm context={{ type: QuickSurveyType.FEATURE_FLAG, flag: mockFlag }} />)
- await userEvent.click(screen.getByRole('button', { name: /create & launch/i }))
+ await userEvent.click(screen.getByText(/create & launch/i))
await waitFor(() => {
expect(capturedRequest).not.toBeUndefined()
@@ -92,7 +92,7 @@ describe('QuickSurveyForm API payloads', () => {
render(<QuickSurveyForm context={{ type: QuickSurveyType.FUNNEL, funnel: mockFunnel }} />)
- await userEvent.click(screen.getByRole('button', { name: /create & launch/i }))
+ await userEvent.click(screen.getByText(/create & launch/i))
await waitFor(() => {
expect(capturedRequest).not.toBeUndefined()
diff --git a/frontend/src/scenes/surveys/SurveyEventTrigger.test.tsx b/frontend/src/scenes/surveys/SurveyEventTrigger.test.tsx
index 318346d8a8e6..6e8c1b479f64 100644
--- a/frontend/src/scenes/surveys/SurveyEventTrigger.test.tsx
+++ b/frontend/src/scenes/surveys/SurveyEventTrigger.test.tsx
@@ -100,7 +100,7 @@ describe('Survey event trigger property filters', () => {
).toBeInTheDocument()
expect(screen.getByText('Property filters for signed_up')).toBeInTheDocument()
- await userEvent.click(screen.getByRole('button', { name: 'Apply property filter' }))
+ await userEvent.click(screen.getByText('Apply property filter'))
await waitFor(() => {
if (!logic.values.survey.conditions?.events?.values?.[0].propertyFilters?.plan) {
diff --git a/frontend/src/toolbar/web-vitals/WebVitalsToolbarMenu.test.tsx b/frontend/src/toolbar/web-vitals/WebVitalsToolbarMenu.test.tsx
index a66306839bba..c6b1eba16dc0 100644
--- a/frontend/src/toolbar/web-vitals/WebVitalsToolbarMenu.test.tsx
+++ b/frontend/src/toolbar/web-vitals/WebVitalsToolbarMenu.test.tsx
@@ -23,7 +23,7 @@ describe('WebVitalsToolbarMenu', () => {
it('uses the PostHog ui host for the settings link', () => {
render(<WebVitalsToolbarMenu />)
- const settingsLink = screen.getByRole('link', { name: 'settings page' })
+ const settingsLink = screen.getByText('settings page').closest('a')
expect(settingsLink).toHaveAttribute('href', 'https://us.posthog.com/settings/project')
expect(settingsLink).toHaveAttribute('target', '_blank')
})
diff --git a/packages/quill/packages/components/src/date-picker.test.tsx b/packages/quill/packages/components/src/date-picker.test.tsx
index 017f0ba086fc..a06b506b1d28 100644
--- a/packages/quill/packages/components/src/date-picker.test.tsx
+++ b/packages/quill/packages/components/src/date-picker.test.tsx
@@ -42,6 +42,7 @@ describe('DatePicker', () => {
const onApply = jest.fn()
render(<DatePicker value={VALUE} maxDate={MAX} showTime onApply={onApply} />)
+ // nosemgrep: jest-no-byrole-name-queries - small DOM, asserts accessibility contract of the toggle
await userEvent.click(screen.getByRole('switch', { name: 'Include time' })) // turn time off
await userEvent.click(screen.getByLabelText('Apply date'))
@@ -57,7 +58,7 @@ describe('DatePicker', () => {
])('renders the include-time toggle %s', (_name, props, expected) => {
render(<DatePicker value={VALUE} maxDate={MAX} onApply={jest.fn()} {...props} />)
- expect(!!screen.queryByRole('switch', { name: 'Include time' })).toBe(expected)
+ expect(!!screen.queryByRole('switch', { name: 'Include time' })).toBe(expected) // nosemgrep: jest-no-byrole-name-queries - small DOM, asserts accessibility contract of the toggle
})
it('keeps time with no toggle when showTimeToggle is false', async () => {
@@ -83,7 +84,7 @@ describe('DatePicker', () => {
/>
)
- await userEvent.click(screen.getByRole('switch', { name: 'Include time' }))
+ await userEvent.click(screen.getByRole('switch', { name: 'Include time' })) // nosemgrep: jest-no-byrole-name-queries - small DOM, asserts accessibility contract of the toggle
expect(onIncludeTimeChange).toHaveBeenCalledWith(false)
})
diff --git a/products/dashboards/frontend/components/DashboardWidgetItem/DashboardWidgetItem.test.tsx b/products/dashboards/frontend/components/DashboardWidgetItem/DashboardWidgetItem.test.tsx
index 9ec60faf5338..c8a7e05cbb11 100644
--- a/products/dashboards/frontend/components/DashboardWidgetItem/DashboardWidgetItem.test.tsx
+++ b/products/dashboards/frontend/components/DashboardWidgetItem/DashboardWidgetItem.test.tsx
@@ -187,18 +187,19 @@ describe('DashboardWidgetItem', () => {
/>
)
- await userEvent.click(screen.getByRole('button', { name: /more/i }))
+ await userEvent.click(screen.getByLabelText('more'))
- expect(screen.getByRole('link', { name: 'View' })).toHaveAttribute('href', '/project/997/error_tracking')
+ expect(screen.getByText('View').closest('a')).toHaveAttribute('href', '/project/997/error_tracking')
expect(
screen
- .getAllByRole('button', { name: 'Edit' })
- .find((button: HTMLElement) => button.classList.contains('LemonButton--full-width'))
+ .getAllByText('Edit')
+ .map((label) => label.closest('button'))
+ .find((button) => button?.classList.contains('LemonButton--full-width'))
).toBeTruthy()
- expect(screen.getByRole('button', { name: 'Duplicate' })).toBeInTheDocument()
+ expect(screen.getByText('Duplicate')).toBeInTheDocument()
expect(screen.getByText('Dashboard')).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Hide description' })).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Remove from dashboard' })).toBeInTheDocument()
+ expect(screen.getByText('Hide description')).toBeInTheDocument()
+ expect(screen.getByText('Remove from dashboard')).toBeInTheDocument()
const refreshTrigger = document.querySelector('[data-attr="dashboard-tile-refresh-data"]') as HTMLElement
expect(refreshTrigger).toBeInTheDocument()
expect(screen.getByText(/Last computed/i)).toBeInTheDocument()
@@ -223,8 +224,8 @@ describe('DashboardWidgetItem', () => {
/>
)
- await userEvent.click(within(container).getByRole('button', { name: /more/i }))
- await userEvent.click(await screen.findByRole('button', { name: 'Remove from dashboard' }))
+ await userEvent.click(within(container).getByLabelText('more'))
+ await userEvent.click(await screen.findByText('Remove from dashboard'))
expect(onRemove).toHaveBeenCalledTimes(1)
expect(
@@ -265,11 +266,11 @@ describe('DashboardWidgetItem', () => {
/>
)
- await userEvent.click(within(container).getByRole('button', { name: /more/i }))
- await userEvent.click(screen.getByRole('button', { name: 'Add description' }))
+ await userEvent.click(within(container).getByLabelText('more'))
+ await userEvent.click(screen.getByText('Add description'))
expect(toggleShowDescription).toHaveBeenCalledTimes(1)
- expect(await screen.findByRole('dialog', { name: 'Widget settings' })).toBeInTheDocument()
+ expect(await screen.findByLabelText('Widget settings')).toBeInTheDocument()
})
it('opens widget settings with title and description fields from edit menu', async () => {
@@ -286,13 +287,13 @@ describe('DashboardWidgetItem', () => {
/>
)
- await userEvent.click(within(container).getByRole('button', { name: /more/i }))
+ await userEvent.click(within(container).getByLabelText('more'))
await waitFor(() => {
expect(document.querySelector('[data-attr="dashboard-widget-edit"]')).toBeInTheDocument()
})
await userEvent.click(document.querySelector('[data-attr="dashboard-widget-edit"]') as HTMLElement)
- const dialog = await screen.findByRole('dialog', { name: 'Widget settings' })
+ const dialog = await screen.findByLabelText('Widget settings')
expect(within(dialog).getByPlaceholderText('Top issues')).toBeInTheDocument()
expect(within(dialog).getByPlaceholderText('Enter description (optional)')).toBeInTheDocument()
})
diff --git a/products/dashboards/frontend/components/WidgetCard/WidgetCardBody.test.tsx b/products/dashboards/frontend/components/WidgetCard/WidgetCardBody.test.tsx
index b954c0575c5e..0b3666815902 100644
--- a/products/dashboards/frontend/components/WidgetCard/WidgetCardBody.test.tsx
+++ b/products/dashboards/frontend/components/WidgetCard/WidgetCardBody.test.tsx
@@ -46,7 +46,7 @@ describe('WidgetCardBody', () => {
</WidgetCardBody>
)
- const refreshButton = screen.getByRole('button', { name: 'Refresh data' })
+ const refreshButton = screen.getByText('Refresh data')
expect(refreshButton).toBeInTheDocument()
refreshButton.click()
expect(onRefresh).toHaveBeenCalledTimes(1)
diff --git a/products/dashboards/frontend/components/WidgetCard/WidgetCardHeader.test.tsx b/products/dashboards/frontend/components/WidgetCard/WidgetCardHeader.test.tsx
index 9fd7768c528e..42a9e59b3bc4 100644
--- a/products/dashboards/frontend/components/WidgetCard/WidgetCardHeader.test.tsx
+++ b/products/dashboards/frontend/components/WidgetCard/WidgetCardHeader.test.tsx
@@ -98,7 +98,7 @@ describe('WidgetCardHeader', () => {
/>
)
- expect(screen.getByRole('link', { name: /Top issues/i })).toHaveAttribute('href', '/error_tracking')
+ expect(screen.getByText('Top issues').closest('a')).toHaveAttribute('href', '/error_tracking')
})
it('does not link the title in dashboard edit mode even when titleHref is set', () => {
@@ -112,8 +112,7 @@ describe('WidgetCardHeader', () => {
/>
)
- expect(screen.queryByRole('link', { name: /Top issues/i })).not.toBeInTheDocument()
- expect(screen.getByText('Top issues')).toBeInTheDocument()
+ expect(screen.getByText('Top issues').closest('a')).toBeNull()
})
it('links the title in view mode when editing controls are shown', () => {
@@ -126,7 +125,7 @@ describe('WidgetCardHeader', () => {
/>
)
- expect(screen.getByRole('link', { name: /Top issues/i })).toHaveAttribute('href', '/error_tracking')
+ expect(screen.getByText('Top issues').closest('a')).toHaveAttribute('href', '/error_tracking')
})
it('forwards the hover refresh control into the dashboard_tile header', () => {
@@ -148,7 +147,7 @@ describe('WidgetCardHeader', () => {
const { container } = render(<WidgetCardHeader layout="simple" title="My widget" showEditingControls={false} />)
expect(container.querySelector('.WidgetCard__header h3')).toHaveTextContent('My widget')
- expect(screen.queryByRole('button', { name: 'Refresh' })).not.toBeInTheDocument()
+ expect(screen.queryByText('Refresh')).not.toBeInTheDocument()
expect(container.querySelector('.CardMeta--compact')).toBeNull()
})
diff --git a/products/dashboards/frontend/components/WidgetRuntimeAvailabilityGuard/WidgetRuntimeAvailabilityGuard.test.tsx b/products/dashboards/frontend/components/WidgetRuntimeAvailabilityGuard/WidgetRuntimeAvailabilityGuard.test.tsx
index 5717ddb5d0b0..ff1fe1228028 100644
--- a/products/dashboards/frontend/components/WidgetRuntimeAvailabilityGuard/WidgetRuntimeAvailabilityGuard.test.tsx
+++ b/products/dashboards/frontend/components/WidgetRuntimeAvailabilityGuard/WidgetRuntimeAvailabilityGuard.test.tsx
@@ -45,7 +45,7 @@ describe('WidgetRuntimeAvailabilityGuard', () => {
)
expect(screen.getByText("You haven't captured any exceptions")).toBeInTheDocument()
- expect(screen.getByRole('link', { name: 'Enable exception autocapture' })).toBeInTheDocument()
+ expect(screen.getByText('Enable exception autocapture').closest('a')).toBeInTheDocument()
expect(screen.queryByText('Widget body')).not.toBeInTheDocument()
})
diff --git a/products/dashboards/frontend/widgets/AddWidgetModal.test.tsx b/products/dashboards/frontend/widgets/AddWidgetModal.test.tsx
index 84b886631527..bce741c054ce 100644
--- a/products/dashboards/frontend/widgets/AddWidgetModal.test.tsx
+++ b/products/dashboards/frontend/widgets/AddWidgetModal.test.tsx
@@ -75,15 +75,15 @@ describe('AddWidgetModal', () => {
expect(
screen.getByText(/Bring context from your different PostHog products into one dashboard/i)
).toBeInTheDocument()
- expect(screen.getByRole('heading', { name: 'Error tracking' })).toBeInTheDocument()
- expect(screen.getByRole('checkbox', { name: 'Top issues' })).toBeInTheDocument()
+ expect(screen.getByText('Error tracking')).toBeInTheDocument()
+ expect(screen.getByLabelText('Top issues')).toBeInTheDocument()
expect(screen.getByText(/Ranked list of the most impactful error tracking issues/i)).toBeInTheDocument()
})
it('allows multi-select checkbox behavior within grouped layout', async () => {
renderAddWidgetModal()
- const topIssuesCard = screen.getByRole('checkbox', { name: 'Top issues' })
+ const topIssuesCard = screen.getByLabelText('Top issues')
expect(topIssuesCard).toHaveAttribute('aria-checked', 'false')
@@ -100,8 +100,8 @@ describe('AddWidgetModal', () => {
renderAddWidgetModal({ onAdd, onClose })
- await userEvent.click(screen.getByRole('checkbox', { name: 'Top issues' }))
- await userEvent.click(screen.getByRole('button', { name: 'Add widget' }))
+ await userEvent.click(screen.getByLabelText('Top issues'))
+ await userEvent.click(screen.getByTestId('add-widget-submit'))
expect(onAdd).toHaveBeenCalledWith([expect.objectContaining({ widgetType: 'error_tracking_list' })])
expect(onClose).toHaveBeenCalled()
@@ -117,7 +117,7 @@ describe('AddWidgetModal', () => {
it('shows a group-level product nudge when the setup requirement is unmet', () => {
renderAddWidgetModal()
- expect(screen.getByRole('link', { name: /Explore error tracking/i })).toHaveAttribute(
+ expect(screen.getByText(/Explore error tracking/i).closest('a')).toHaveAttribute(
'href',
'https://posthog.com/docs/error-tracking'
)
@@ -127,31 +127,31 @@ describe('AddWidgetModal', () => {
initKeaTests(true, { ...MOCK_DEFAULT_TEAM, autocapture_exceptions_opt_in: true })
renderAddWidgetModal()
- expect(screen.queryByRole('link', { name: /Explore error tracking/i })).not.toBeInTheDocument()
+ expect(screen.queryByText(/Explore error tracking/i)).not.toBeInTheDocument()
})
it('does not nudge for product areas without a setup requirement', () => {
renderAddWidgetModal()
- expect(screen.queryByRole('link', { name: /Explore experiments/i })).not.toBeInTheDocument()
+ expect(screen.queryByText(/Explore experiments/i)).not.toBeInTheDocument()
})
it('collapses and expands a section when its header is clicked', async () => {
renderAddWidgetModal()
- expect(screen.getByRole('checkbox', { name: 'Top issues' })).toBeInTheDocument()
+ expect(screen.getByLabelText('Top issues')).toBeInTheDocument()
- await userEvent.click(screen.getByRole('button', { name: /Error tracking/i }))
- expect(screen.queryByRole('checkbox', { name: 'Top issues' })).not.toBeInTheDocument()
+ await userEvent.click(screen.getByText('Error tracking'))
+ expect(screen.queryByLabelText('Top issues')).not.toBeInTheDocument()
- await userEvent.click(screen.getByRole('button', { name: /Error tracking/i }))
- expect(screen.getByRole('checkbox', { name: 'Top issues' })).toBeInTheDocument()
+ await userEvent.click(screen.getByText('Error tracking'))
+ expect(screen.getByLabelText('Top issues')).toBeInTheDocument()
})
it('resets collapsed sections when the modal is reopened', async () => {
const logic = renderAddWidgetModal()
- await userEvent.click(screen.getByRole('button', { name: /Error tracking/i }))
+ await userEvent.click(screen.getByText('Error tracking'))
expect(logic.values.addWidgetCollapsedGroups).toContain('error_tracking')
logic.actions.setAddWidgetModalOpen(true)
diff --git a/products/dashboards/frontend/widgets/AddWidgetModal.tsx b/products/dashboards/frontend/widgets/AddWidgetModal.tsx
index 11411412eff7..f7c64408f1f4 100644
--- a/products/dashboards/frontend/widgets/AddWidgetModal.tsx
+++ b/products/dashboards/frontend/widgets/AddWidgetModal.tsx
@@ -123,6 +123,7 @@ export function AddWidgetModal({ isOpen, onClose, loading, onAdd }: AddWidgetMod
loading={loading}
disabledReason={getAddWidgetDisabledReason(loading, selectedCount)}
onClick={handleAddWidgets}
+ data-attr="add-widget-submit"
>
{getAddButtonLabel(selectedCount)}
</LemonButton>
diff --git a/products/dashboards/frontend/widgets/WidgetTypePickerCard.test.tsx b/products/dashboards/frontend/widgets/WidgetTypePickerCard.test.tsx
index c4b7d0f93dc1..a28164d148d0 100644
--- a/products/dashboards/frontend/widgets/WidgetTypePickerCard.test.tsx
+++ b/products/dashboards/frontend/widgets/WidgetTypePickerCard.test.tsx
@@ -21,7 +21,7 @@ describe('WidgetTypePickerCard', () => {
/>
)
- let checkbox = screen.getByRole('checkbox', { name: 'Error tracking' })
+ let checkbox = screen.getByLabelText('Error tracking')
expect(checkbox).toHaveAttribute('aria-checked', 'false')
let indicator = checkbox.querySelector('[aria-hidden="true"]')
@@ -38,7 +38,7 @@ describe('WidgetTypePickerCard', () => {
/>
)
- checkbox = screen.getByRole('checkbox', { name: 'Error tracking' })
+ checkbox = screen.getByLabelText('Error tracking')
expect(checkbox).toHaveAttribute('aria-checked', 'true')
indicator = checkbox.querySelector('[aria-hidden="true"]')
expect(indicator?.querySelector('svg')).toBeInTheDocument()
@@ -64,12 +64,12 @@ describe('WidgetTypePickerCard', () => {
render(<TogglePicker />)
- expect(screen.getByRole('checkbox', { name: 'Logs widget' })).toHaveAttribute('aria-checked', 'true')
+ expect(screen.getByLabelText('Logs widget')).toHaveAttribute('aria-checked', 'true')
expect(screen.getByTestId('selected-state')).toHaveTextContent('selected')
- await userEvent.click(screen.getByRole('checkbox', { name: 'Logs widget' }))
+ await userEvent.click(screen.getByLabelText('Logs widget'))
- expect(screen.getByRole('checkbox', { name: 'Logs widget' })).toHaveAttribute('aria-checked', 'false')
+ expect(screen.getByLabelText('Logs widget')).toHaveAttribute('aria-checked', 'false')
expect(screen.getByTestId('selected-state')).toHaveTextContent('deselected')
})
@@ -85,7 +85,7 @@ describe('WidgetTypePickerCard', () => {
/>
)
- const checkbox = screen.getByRole('checkbox', { name: 'Logs widget' })
+ const checkbox = screen.getByLabelText('Logs widget')
await userEvent.click(checkbox)
expect(onSelect).toHaveBeenCalledTimes(1)
diff --git a/products/dashboards/frontend/widgets/activity/EditActivityEventsWidgetModal.test.tsx b/products/dashboards/frontend/widgets/activity/EditActivityEventsWidgetModal.test.tsx
index d636554a1d93..e08d0b38d169 100644
--- a/products/dashboards/frontend/widgets/activity/EditActivityEventsWidgetModal.test.tsx
+++ b/products/dashboards/frontend/widgets/activity/EditActivityEventsWidgetModal.test.tsx
@@ -49,7 +49,7 @@ describe('EditActivityEventsWidgetModal', () => {
)
const dialog = screen.getByRole('dialog')
- await userEvent.click(within(dialog).getByRole('button', { name: 'Save' }))
+ await userEvent.click(within(dialog).getByText('Save'))
expect(onSave).toHaveBeenCalledWith(
expect.objectContaining({
@@ -78,7 +78,7 @@ describe('EditActivityEventsWidgetModal', () => {
await userEvent.type(limitInput, '60')
expect(screen.getByText('Too big: expected number to be <=50')).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Save' })).toHaveAttribute('aria-disabled', 'true')
+ expect(screen.getByText('Save').closest('button')).toHaveAttribute('aria-disabled', 'true')
expect(onSave).not.toHaveBeenCalled()
})
})
diff --git a/products/dashboards/frontend/widgets/error_tracking/EditErrorTrackingWidgetModal.test.tsx b/products/dashboards/frontend/widgets/error_tracking/EditErrorTrackingWidgetModal.test.tsx
index 87e7ef92be8b..d20c4bc75d48 100644
--- a/products/dashboards/frontend/widgets/error_tracking/EditErrorTrackingWidgetModal.test.tsx
+++ b/products/dashboards/frontend/widgets/error_tracking/EditErrorTrackingWidgetModal.test.tsx
@@ -58,7 +58,7 @@ describe('EditErrorTrackingWidgetModal', () => {
await userEvent.type(limitInput, '30')
expect(screen.getByText('Too big: expected number to be <=25')).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Save' })).toHaveAttribute('aria-disabled', 'true')
+ expect(screen.getByText('Save').closest('button')).toHaveAttribute('aria-disabled', 'true')
expect(onSave).not.toHaveBeenCalled()
})
@@ -80,7 +80,7 @@ describe('EditErrorTrackingWidgetModal', () => {
await userEvent.type(screen.getByPlaceholderText('Top issues'), 'Critical crashes')
await userEvent.type(screen.getByPlaceholderText('Enter description (optional)'), 'Top crashes this week')
const dialog = screen.getByRole('dialog')
- await userEvent.click(within(dialog).getByRole('button', { name: 'Save' }))
+ await userEvent.click(within(dialog).getByText('Save'))
expect(onSave).toHaveBeenCalledTimes(1)
expect(onSave).toHaveBeenCalledWith(
@@ -112,9 +112,9 @@ describe('EditErrorTrackingWidgetModal', () => {
/>
)
- await userEvent.click(screen.getByRole('switch', { name: /Filter out internal and test users/i }))
+ await userEvent.click(screen.getByLabelText(/Filter out internal and test users/i))
const dialog = screen.getByRole('dialog')
- await userEvent.click(within(dialog).getByRole('button', { name: 'Save' }))
+ await userEvent.click(within(dialog).getByText('Save'))
expect(onSave).toHaveBeenCalledWith(
expect.objectContaining({
@@ -143,13 +143,13 @@ describe('EditErrorTrackingWidgetModal', () => {
)
const dialog = screen.getByRole('dialog')
- await userEvent.click(within(dialog).getByRole('button', { name: 'Save' }))
+ await userEvent.click(within(dialog).getByText('Save'))
- expect(within(dialog).getByRole('button', { name: 'Save' })).toHaveAttribute('aria-disabled', 'true')
- expect(within(dialog).getByRole('button', { name: 'Cancel' })).toHaveAttribute('aria-disabled', 'true')
+ expect(within(dialog).getByText('Save').closest('button')).toHaveAttribute('aria-disabled', 'true')
+ expect(within(dialog).getByText('Cancel').closest('button')).toHaveAttribute('aria-disabled', 'true')
resolveSave?.()
- await within(dialog).findByRole('button', { name: 'Save' })
+ await within(dialog).findByText('Save')
})
it('hides issue settings when exception ingestion is not configured', () => {
diff --git a/products/dashboards/frontend/widgets/error_tracking/ErrorTrackingWidget.test.tsx b/products/dashboards/frontend/widgets/error_tracking/ErrorTrackingWidget.test.tsx
index 49076c21f476..27d03923c1b1 100644
--- a/products/dashboards/frontend/widgets/error_tracking/ErrorTrackingWidget.test.tsx
+++ b/products/dashboards/frontend/widgets/error_tracking/ErrorTrackingWidget.test.tsx
@@ -83,7 +83,7 @@ describe('ErrorTrackingWidget', () => {
render(<ErrorTrackingWidget tileId={1} config={{ limit: 10 }} loading={false} result={{ results: [issue] }} />)
expect(await screen.findByText("You haven't captured any exceptions")).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Enable exception autocapture' })).toBeInTheDocument()
+ expect(screen.getByText('Enable exception autocapture').closest('button')).toBeInTheDocument()
expect(screen.queryByText('Issue list')).not.toBeInTheDocument()
})
})
diff --git a/products/dashboards/frontend/widgets/session_replay/EditSessionReplayWidgetModal.test.tsx b/products/dashboards/frontend/widgets/session_replay/EditSessionReplayWidgetModal.test.tsx
index 4753da12698f..85c6ce638e0e 100644
--- a/products/dashboards/frontend/widgets/session_replay/EditSessionReplayWidgetModal.test.tsx
+++ b/products/dashboards/frontend/widgets/session_replay/EditSessionReplayWidgetModal.test.tsx
@@ -51,7 +51,7 @@ describe('EditSessionReplayWidgetModal', () => {
)
const dialog = screen.getByRole('dialog')
- await userEvent.click(within(dialog).getByRole('button', { name: 'Save' }))
+ await userEvent.click(within(dialog).getByText('Save'))
expect(onSave).toHaveBeenCalledWith(
expect.objectContaining({
@@ -82,7 +82,7 @@ describe('EditSessionReplayWidgetModal', () => {
await userEvent.type(limitInput, '30')
expect(screen.getByText('Too big: expected number to be <=25')).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Save' })).toHaveAttribute('aria-disabled', 'true')
+ expect(screen.getByText('Save').closest('button')).toHaveAttribute('aria-disabled', 'true')
expect(onSave).not.toHaveBeenCalled()
})
})
diff --git a/products/error_tracking/frontend/components/ErrorTrackingIssueList/ErrorTrackingIssueList.test.tsx b/products/error_tracking/frontend/components/ErrorTrackingIssueList/ErrorTrackingIssueList.test.tsx
index d26b880cd383..ff0c67589f52 100644
--- a/products/error_tracking/frontend/components/ErrorTrackingIssueList/ErrorTrackingIssueList.test.tsx
+++ b/products/error_tracking/frontend/components/ErrorTrackingIssueList/ErrorTrackingIssueList.test.tsx
@@ -46,7 +46,7 @@ describe('ErrorTrackingIssueListRow', () => {
</Provider>
)
- expect(screen.queryByRole('button', { name: /Unassigned/i })).not.toBeInTheDocument()
+ expect(screen.getByText(/Unassigned/i).closest('button, [role="button"]')).toBeNull()
expect(screen.getAllByRole('link')).toHaveLength(1)
})
@@ -58,8 +58,8 @@ describe('ErrorTrackingIssueListRow', () => {
)
expect(screen.getAllByRole('link')).toHaveLength(1)
- const link = screen.getByRole('link', { name: /TypeError: undefined is not a function/i })
- expect(link.getAttribute('href')).toMatch(
+ const link = screen.getByText(/TypeError: undefined is not a function/i).closest('a')
+ expect(link?.getAttribute('href')).toMatch(
/\/error_tracking\/issue-abc\?timestamp=2026-05-26T08%3A00%3A00\.000Z$/
)
})
@@ -90,6 +90,6 @@ describe('ErrorTrackingIssueList', () => {
</Provider>
)
- expect(screen.getByRole('link', { name: /TypeError: undefined is not a function/i })).toBeInTheDocument()
+ expect(screen.getByText(/TypeError: undefined is not a function/i).closest('a')).toBeInTheDocument()
})
})
diff --git a/products/posthog_ai/frontend/components/Approval.test.tsx b/products/posthog_ai/frontend/components/Approval.test.tsx
index 8a237748bbb3..7606c2a598c9 100644
--- a/products/posthog_ai/frontend/components/Approval.test.tsx
+++ b/products/posthog_ai/frontend/components/Approval.test.tsx
@@ -140,7 +140,7 @@ describe('Sandbox approval input area', () => {
fireEvent.click(screen.getByText("Explain what you'd like instead."))
const input = screen.getByPlaceholderText('Type your answer...')
fireEvent.change(input, { target: { value: 'Use a funnel instead' } })
- fireEvent.click(screen.getByRole('button', { name: 'Send' }))
+ fireEvent.click(screen.getByText('Send'))
expect(respondToPermission).toHaveBeenCalledWith({
requestId: 'req-1',
diff --git a/products/posthog_ai/frontend/components/GitArtifacts.test.tsx b/products/posthog_ai/frontend/components/GitArtifacts.test.tsx
index d619d306faf6..a022b90344c8 100644
--- a/products/posthog_ai/frontend/components/GitArtifacts.test.tsx
+++ b/products/posthog_ai/frontend/components/GitArtifacts.test.tsx
@@ -30,6 +30,6 @@ describe('sandbox git artifacts', () => {
render(<PullRequestCard prUrl={PR_URL} branch="feat/x" />)
expect(screen.getByText('Pull request opened')).toBeInTheDocument()
expect(screen.getByText('feat/x')).toBeInTheDocument()
- expect(screen.getByRole('link', { name: /Open on GitHub/ })).toHaveAttribute('href', PR_URL)
+ expect(screen.getByText(/Open on GitHub/).closest('a')).toHaveAttribute('href', PR_URL)
})
})
diff --git a/products/posthog_ai/frontend/components/QuestionField.test.tsx b/products/posthog_ai/frontend/components/QuestionField.test.tsx
index e247d555f808..a0413499687b 100644
--- a/products/posthog_ai/frontend/components/QuestionField.test.tsx
+++ b/products/posthog_ai/frontend/components/QuestionField.test.tsx
@@ -104,7 +104,7 @@ describe('QuestionField', () => {
/>
)
expect(screen.getByPlaceholderText('Add your own option...')).toBeInTheDocument()
- expect(screen.getByRole('button', { name: /Add/ })).toBeInTheDocument()
+ expect(screen.getByText('Add')).toBeInTheDocument()
})
it('multi_select hides custom entry input when allow_custom_answer is false', () => {
@@ -147,7 +147,7 @@ describe('QuestionField', () => {
const input = screen.getByPlaceholderText('Add your own option...')
fireEvent.change(input, { target: { value: 'Custom value' } })
- fireEvent.click(screen.getByRole('button', { name: /Add/ }))
+ fireEvent.click(screen.getByText('Add'))
// onChange should be called with the new selection
expect(onChange).toHaveBeenCalledWith(['Custom value'])
@@ -192,7 +192,7 @@ describe('QuestionField', () => {
const input = screen.getByPlaceholderText('Add your own option...')
fireEvent.change(input, { target: { value: ' ' } })
- fireEvent.click(screen.getByRole('button', { name: /Add/ }))
+ fireEvent.click(screen.getByText('Add'))
// Should still only have the 2 predefined checkboxes
expect(screen.getAllByRole('checkbox')).toHaveLength(2)
@@ -217,7 +217,7 @@ describe('QuestionField', () => {
const input = screen.getByPlaceholderText('Add your own option...')
fireEvent.change(input, { target: { value: 'alpha' } })
- fireEvent.click(screen.getByRole('button', { name: /Add/ }))
+ fireEvent.click(screen.getByText('Add'))
// Should call onChange with the matched predefined option
expect(onChange).toHaveBeenCalledWith(['Alpha'])
@@ -295,7 +295,7 @@ describe('QuestionField', () => {
/>
)
- fireEvent.click(screen.getByRole('button', { name: 'Skip question' }))
+ fireEvent.click(screen.getByText('Skip question'))
expect(onSkip).toHaveBeenCalledTimes(1)
})
@@ -373,7 +373,7 @@ describe('QuestionField', () => {
/>
)
- fireEvent.click(screen.getAllByRole('button', { name: 'Skip question' }).at(-1)!)
+ fireEvent.click(screen.getAllByText('Skip question').at(-1)!)
expect(onSkip).toHaveBeenCalledTimes(1)
})
diff --git a/products/posthog_ai/frontend/components/QuestionInput.test.tsx b/products/posthog_ai/frontend/components/QuestionInput.test.tsx
index 5f78cb451dbe..e21cd984b8d1 100644
--- a/products/posthog_ai/frontend/components/QuestionInput.test.tsx
+++ b/products/posthog_ai/frontend/components/QuestionInput.test.tsx
@@ -97,7 +97,7 @@ describe('QuestionInput', () => {
fireEvent.click(screen.getByText('Insights'))
fireEvent.click(screen.getByText('Flags'))
- fireEvent.click(screen.getByRole('button', { name: 'Submit' }))
+ fireEvent.click(screen.getByText('Submit'))
expect(respondToPermission).toHaveBeenCalledWith({
requestId: 'req-1',
@@ -113,7 +113,7 @@ describe('QuestionInput', () => {
// Open the custom "Type your answer" field, type, and submit.
fireEvent.click(screen.getByText("Explain what you'd like instead."))
fireEvent.change(screen.getByPlaceholderText('Type your answer...'), { target: { value: 'Cut churn' } })
- fireEvent.click(screen.getByRole('button', { name: 'Submit' }))
+ fireEvent.click(screen.getByText('Submit'))
expect(respondToPermission).toHaveBeenCalledWith({
requestId: 'req-1',
@@ -132,7 +132,7 @@ describe('QuestionInput', () => {
}
render(<QuestionInput streamKey="conv-1" request={makeRequest([productsQuestion])} />)
- fireEvent.click(screen.getByRole('button', { name: 'Submit' }))
+ fireEvent.click(screen.getByText('Submit'))
expect(screen.getByText('Select at least one option')).toBeInTheDocument()
expect(respondToPermission).not.toHaveBeenCalled()
diff --git a/products/posthog_ai/frontend/components/RunComposer.test.tsx b/products/posthog_ai/frontend/components/RunComposer.test.tsx
index 5defb0987df7..9e694a200bba 100644
--- a/products/posthog_ai/frontend/components/RunComposer.test.tsx
+++ b/products/posthog_ai/frontend/components/RunComposer.test.tsx
@@ -22,8 +22,7 @@ describe('RunComposer', () => {
const getSendButton = (container: HTMLElement): HTMLButtonElement =>
container.querySelector('[data-attr="sandbox-composer-send"]') as HTMLButtonElement
- const getTextArea = (): HTMLTextAreaElement =>
- screen.getByRole('textbox', { name: undefined }) as HTMLTextAreaElement
+ const getTextArea = (): HTMLTextAreaElement => screen.getByRole('textbox') as HTMLTextAreaElement
it('shows the placeholder when empty and hides it once there is a value', () => {
const { rerender } = renderComposer({ placeholder: 'Send a follow-up message…' })
diff --git a/products/posthog_ai/frontend/components/tool/posthogCodeToolRenderers.test.tsx b/products/posthog_ai/frontend/components/tool/posthogCodeToolRenderers.test.tsx
index 248f9dc66229..0e9b5fd3e392 100644
--- a/products/posthog_ai/frontend/components/tool/posthogCodeToolRenderers.test.tsx
+++ b/products/posthog_ai/frontend/components/tool/posthogCodeToolRenderers.test.tsx
@@ -52,13 +52,13 @@ describe('posthog-code tool renderers', () => {
expect(screen.getByText('Signed commits · 2 commits')).toBeInTheDocument()
expect(screen.getByText('fix(api): handle null series')).toBeInTheDocument()
// The commit links live in the collapsed accordion, not always-visible — reveal them first.
- expect(screen.queryByRole('link', { name: /a1b2c3d/ })).not.toBeInTheDocument()
+ expect(screen.queryByText(/a1b2c3d/)).not.toBeInTheDocument()
fireEvent.click(screen.getByRole('button'))
- expect(screen.getByRole('link', { name: /a1b2c3d/ })).toHaveAttribute(
+ expect(screen.getByText(/a1b2c3d/).closest('a')).toHaveAttribute(
'href',
'https://github.com/posthog/posthog/commit/a1b2c3dabcdef'
)
- expect(screen.getByRole('link', { name: /e4f5a6b/ })).toHaveAttribute(
+ expect(screen.getByText(/e4f5a6b/).closest('a')).toHaveAttribute(
'href',
'https://github.com/posthog/posthog/commit/e4f5a6babcdef'
)
@@ -106,7 +106,7 @@ describe('posthog-code tool renderers', () => {
expect(screen.getByText('List repositories · 2')).toBeInTheDocument()
fireEvent.click(screen.getByRole('button'))
expect(screen.getByText('Product analytics platform')).toBeInTheDocument()
- expect(screen.getByRole('link', { name: /posthog-js/ })).toHaveAttribute(
+ expect(screen.getByText(/posthog-js/).closest('a')).toHaveAttribute(
'href',
'https://github.com/posthog/posthog-js'
)
@@ -128,7 +128,7 @@ describe('posthog-code tool renderers', () => {
/>
)
expect(screen.getByText('Clone repository')).toBeInTheDocument()
- expect(screen.getByRole('link', { name: /posthog\/posthog/ })).toHaveAttribute(
+ expect(screen.getByText(/posthog\/posthog/).closest('a')).toHaveAttribute(
'href',
'https://github.com/posthog/posthog'
)
diff --git a/products/posthog_ai/frontend/messages/AssistantFailureMessage.test.tsx b/products/posthog_ai/frontend/messages/AssistantFailureMessage.test.tsx
index 6d4bfb3cbeb4..3f29289fcd59 100644
--- a/products/posthog_ai/frontend/messages/AssistantFailureMessage.test.tsx
+++ b/products/posthog_ai/frontend/messages/AssistantFailureMessage.test.tsx
@@ -22,6 +22,6 @@ describe('AssistantFailureMessage', () => {
it('renders an optional action', () => {
render(<AssistantFailureMessage id="failure-1" content="Failed" action={<button>Try again</button>} />)
- expect(screen.getByRole('button', { name: 'Try again' })).toBeInTheDocument()
+ expect(screen.getByText('Try again')).toBeInTheDocument()
})
})
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/RepositorySelector.test.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/RepositorySelector.test.tsx
index 8b1922e9b2e8..aec91a575147 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/RepositorySelector.test.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/RepositorySelector.test.tsx
@@ -58,12 +58,12 @@ describe('RepositorySelector', () => {
// Repo list still loading: the disabled fallback shows, not the interactive branch combobox.
// (Quill's Button marks itself non-interactive with aria-disabled, not the native disabled attribute.)
- expect(await screen.findByRole('button', { name: 'Branch' })).toHaveAttribute('aria-disabled', 'true')
+ expect(await screen.findByLabelText('Branch')).toHaveAttribute('aria-disabled', 'true')
expect(screen.queryByTestId('branch-combobox')).not.toBeInTheDocument()
// Repo list loaded: the interactive branch combobox replaces the fallback.
releaseRepos()
expect(await screen.findByTestId('branch-combobox')).toBeInTheDocument()
- expect(screen.queryByRole('button', { name: 'Branch' })).not.toBeInTheDocument()
+ expect(screen.queryByLabelText('Branch')).not.toBeInTheDocument()
})
})
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx
index e56297122235..8263c848509c 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx
+++ b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx
@@ -156,7 +156,7 @@ describe('FunnelLineChart', () => {
query: buildFunnelsQuery({ funnelsFilter: { showValuesOnSeries: true } }),
})
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
await waitFor(() => {
const texts = getHogChart()
.valueLabels()
@@ -175,7 +175,7 @@ describe('FunnelLineChart', () => {
}),
})
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
await waitFor(() => {
const lines = getHogChart().referenceLines()
// value→pixel isn't recoverable from the DOM; assert the line is labelled,
@@ -219,7 +219,7 @@ describe('FunnelLineChart', () => {
}),
})
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
const legend = await screen.findByTestId('hog-chart-timeseries-line-legend')
const labels = Array.from(legend.children).map((el) => el.textContent?.trim())
expect(labels).toEqual(['Spike', 'Bramble'])
@@ -246,7 +246,7 @@ describe('FunnelLineChart', () => {
])('omits the legend when $desc', async ({ query }) => {
renderInsight({ query })
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
expect(screen.queryByTestId('hog-chart-timeseries-line-legend')).not.toBeInTheDocument()
})
@@ -258,7 +258,7 @@ describe('FunnelLineChart', () => {
}),
})
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
const legend = await screen.findByTestId('hog-chart-timeseries-line-legend')
// The label span also carries an inline style now (max-width), so keep only the colored swatches.
const swatchColors = Array.from(legend.querySelectorAll<HTMLElement>('span[style]'))
@@ -295,7 +295,7 @@ describe('FunnelLineChart', () => {
expect(document.querySelectorAll('.AnnotationsBadge').length).toBeGreaterThan(0)
})
} else {
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
expect(document.querySelectorAll('.AnnotationsBadge')).toHaveLength(0)
}
}
@@ -326,7 +326,7 @@ describe('FunnelLineChart', () => {
expect(document.querySelectorAll('.AnnotationsBadge').length).toBeGreaterThan(0)
})
} else {
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
expect(document.querySelectorAll('.AnnotationsBadge')).toHaveLength(0)
}
}
diff --git a/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/StickinessBarChart.test.tsx b/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/StickinessBarChart.test.tsx
index 456f6dfb071e..efb6f58e04c0 100644
--- a/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/StickinessBarChart.test.tsx
+++ b/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/StickinessBarChart.test.tsx
@@ -59,7 +59,7 @@ describe('StickinessBarChart', () => {
await waitFor(
() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
},
{ timeout: 5000 }
)
@@ -68,7 +68,7 @@ describe('StickinessBarChart', () => {
it('y-axis: renders percent ticks (legacy `${value.toFixed(1)}%` parity)', async () => {
renderInsight({ query: stickinessBar() })
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
await waitFor(() => {
const ticks = getHogChart().yTicks()
expect(ticks.length).toBeGreaterThan(0)
@@ -100,7 +100,7 @@ describe('StickinessBarChart', () => {
},
{ timeout: 5000 }
)
- expect(screen.queryByRole('img', { name: /chart with/i })).not.toBeInTheDocument()
+ expect(screen.queryByLabelText(/chart with/i)).not.toBeInTheDocument()
})
it('click → persons modal: opens with a "stickiness on {interval} {day}" title', async () => {
@@ -156,7 +156,7 @@ describe('StickinessBarChart', () => {
const { container } = renderInsight({ query: twoSeriesBar, featureFlags: quillLegendFlag })
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
const legendEl = getInChartLegend(container)
diff --git a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.test.tsx b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.test.tsx
index 9b8a77c7030f..e7d5c4dab3ce 100644
--- a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.test.tsx
+++ b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.test.tsx
@@ -35,7 +35,7 @@ describe('StickinessLineChart', () => {
it('renders the chart from a StickinessQuery with one series', async () => {
renderInsight({ query: buildStickinessQuery() })
- await screen.findByRole('img', { name: /chart with 1 data series/i })
+ await screen.findByLabelText(/chart with 1 data series/i)
})
})
@@ -43,7 +43,7 @@ describe('StickinessLineChart', () => {
it('renders percent ticks (legacy `${value.toFixed(1)}%` parity)', async () => {
renderInsight({ query: buildStickinessQuery() })
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
await waitFor(() => {
const ticks = getHogChart().yTicks()
expect(ticks.length).toBeGreaterThan(0)
@@ -85,7 +85,7 @@ describe('StickinessLineChart', () => {
await waitFor(() => {
expect(screen.getByTestId('insight-empty-state')).toBeInTheDocument()
})
- expect(screen.queryByRole('img', { name: /chart with/i })).not.toBeInTheDocument()
+ expect(screen.queryByLabelText(/chart with/i)).not.toBeInTheDocument()
})
})
@@ -159,7 +159,7 @@ describe('StickinessLineChart', () => {
const { container } = renderInsight({ query: twoSeriesLine, featureFlags: quillLegendFlag })
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
const legendEl = getInChartLegend(container)
diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
index 47eccfeb8792..df6ad614111a 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
@@ -62,11 +62,7 @@ describe('TrendsBarChart (ActionsBar)', () => {
await waitFor(
() => {
- expect(
- screen.getByRole('img', {
- name: new RegExp(`chart with ${expected} data series`, 'i'),
- })
- ).toBeInTheDocument()
+ expect(screen.getByLabelText(new RegExp(`chart with ${expected} data series`, 'i'))).toBeInTheDocument()
},
{ timeout: 5000 }
)
@@ -74,7 +70,7 @@ describe('TrendsBarChart (ActionsBar)', () => {
it('shows the series value in the tooltip on hover', async () => {
renderInsight({ query: trendsBar() })
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
const tooltip = await chart.hoverTooltip(2)
expect(tooltip.row('Pageview')).toContain('134')
@@ -99,7 +95,7 @@ describe('TrendsBarChart (ActionsBar)', () => {
],
}),
})
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
const tooltip = await chart.hoverTooltip(2)
@@ -110,7 +106,7 @@ describe('TrendsBarChart (ActionsBar)', () => {
it('shows a date header in the tooltip', async () => {
renderInsight({ query: trendsBar() })
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
const tooltip = await chart.hoverTooltip(2)
expect(tooltip.title()).toMatch(/Jun/)
@@ -118,7 +114,7 @@ describe('TrendsBarChart (ActionsBar)', () => {
it('opens the persons modal on click for a single series', async () => {
renderInsight({ query: trendsBar() })
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
await chart.clickAtIndex(2)
@@ -143,7 +139,7 @@ describe('TrendsBarChart (ActionsBar)', () => {
it('clicking a bar does not open the persons modal', async () => {
renderInsight({ query: trendsBar(), inSharedMode: true })
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
await chart.clickAtIndex(2)
@@ -171,7 +167,7 @@ describe('TrendsBarChart (ActionsBar)', () => {
},
{ timeout: 5000 }
)
- expect(screen.queryByRole('img', { name: /chart with/i })).not.toBeInTheDocument()
+ expect(screen.queryByLabelText(/chart with/i)).not.toBeInTheDocument()
})
it('shows current and previous period rows in compare mode', async () => {
@@ -181,11 +177,7 @@ describe('TrendsBarChart (ActionsBar)', () => {
await waitFor(
() => {
- expect(
- screen.getByRole('img', {
- name: /chart with 2 data series/i,
- })
- ).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
},
{ timeout: 5000 }
)
@@ -217,7 +209,7 @@ describe('TrendsBarChart (ActionsBar)', () => {
},
}),
})
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
const tooltip = await chart.hoverTooltip(2)
@@ -239,7 +231,7 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
await waitFor(
() => {
- expect(screen.getByRole('img', { name: /chart with/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with/i)).toBeInTheDocument()
},
{ timeout: 5000 }
)
@@ -256,7 +248,7 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
}),
})
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
expect(getHogChart().xAxisLabel()).toBe('Total events')
expect(getHogChart().yAxisLabel()).toBe('Series')
expect(
@@ -284,7 +276,7 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
})
// Five hedgehog breakdowns → one series carrying five per-bar colors across five bands.
- await screen.findByRole('img', { name: /chart with 1 data series/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with 1 data series/i, undefined, { timeout: 5000 })
await waitFor(
() => {
expect(getHogChart().yTicks()).toHaveLength(5)
@@ -303,7 +295,7 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
trendsFilter: { display: ChartDisplayType.ActionsBarValue, showValuesOnSeries: true },
}),
})
- await screen.findByRole('img', { name: /chart with 1 data series/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with 1 data series/i, undefined, { timeout: 5000 })
await waitFor(
() => {
@@ -324,7 +316,7 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
breakdownFilter: { breakdown: 'hedgehog', breakdown_type: 'event' },
}),
})
- await screen.findByRole('img', { name: /chart with 1 data series/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with 1 data series/i, undefined, { timeout: 5000 })
await waitFor(
() => {
@@ -344,7 +336,7 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
trendsFilter: { display: ChartDisplayType.ActionsBarValue, stackBreakdownValues: true },
}),
})
- await screen.findByRole('img', { name: /chart with 5 data series/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with 5 data series/i, undefined, { timeout: 5000 })
await waitFor(
() => {
@@ -388,7 +380,7 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
additionalMockResponses: [{ match: (q) => q.kind === NodeKind.TrendsQuery, response: manyBreakdowns }],
},
})
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
await waitFor(
() => {
@@ -408,7 +400,7 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
renderInsight({
query: aggregatedBar(),
})
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
const tooltip = await chart.hoverTooltip(0)
expect(tooltip.title()).toBe('')
@@ -418,7 +410,7 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
renderInsight({
query: aggregatedBar(),
})
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
await chart.clickAtIndex(0)
@@ -436,7 +428,7 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
renderInsight({
query: aggregatedBar({ compareFilter: { compare: true } }),
})
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
await chart.clickAtIndex(0)
@@ -457,7 +449,7 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
query: aggregatedBar(),
context: { onDataPointClick },
})
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
await chart.clickAtIndex(0)
@@ -480,10 +472,10 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
breakdownFilter: { breakdown: 'hedgehog', breakdown_type: 'event' },
}),
})
- await screen.findByRole('img', { name: /chart with 1 data series/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with 1 data series/i, undefined, { timeout: 5000 })
// Spike has aggregated_value 11 — largest, so it's the topmost row in DESC layout.
- const canvas = screen.getByRole('img', { name: /chart with/i })
+ const canvas = screen.getByLabelText(/chart with/i)
const wrapper = canvas.parentElement!
fireEvent.mouseMove(wrapper, {
clientX: dimensions.plotLeft + 10,
@@ -558,7 +550,7 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
additionalMockResponses: [{ match: (q) => q.kind === NodeKind.TrendsQuery, response: compareResults }],
},
})
- const canvas = await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ const canvas = await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
const wrapper = canvas.parentElement!
// Topmost band is the previous period (largest aggregated_value, sorted DESC). Aim at the
// band centre — the bar's hittable region sits inside the band's padding.
@@ -621,11 +613,7 @@ describe('TrendsBarChart (ActionsUnstackedBar)', () => {
await waitFor(
() => {
- expect(
- screen.getByRole('img', {
- name: /chart with 2 data series/i,
- })
- ).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
},
{ timeout: 5000 }
)
@@ -643,7 +631,7 @@ describe('TrendsBarChart overlays', () => {
}),
})
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
await waitFor(
() => {
expect(getHogChart().valueLabels().length).toBeGreaterThan(0)
@@ -673,7 +661,7 @@ describe('TrendsBarChart overlays', () => {
},
})
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
await waitFor(
() => {
expect(getHogChart().annotationBadges().length).toBeGreaterThan(0)
@@ -711,7 +699,7 @@ describe('TrendsBarChart overlays', () => {
}),
})
- await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/chart with/i, undefined, { timeout: 5000 })
await waitFor(
() => {
const lines = getHogChart().referenceLines()
@@ -740,7 +728,7 @@ describe('TrendsBarChart overlays', () => {
const { container } = renderInsight({ query: twoSeriesBar, featureFlags: quillLegendFlag })
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
const legendEl = getInChartLegend(container)
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.test.tsx
index 32de007f333e..57c84228b88f 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.test.tsx
@@ -73,7 +73,7 @@ describe('TrendsLifecycleChart', () => {
)
await waitFor(
() => {
- expect(screen.getByRole('img', { name: /chart with 4 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 4 data series/i)).toBeInTheDocument()
},
{ timeout: 5000 }
)
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx
index 16dca5fe6830..d5234a2ca747 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx
@@ -136,7 +136,7 @@ describe('TrendsLineChart', () => {
})
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
const tooltip = await chart.hoverTooltip(2)
@@ -156,7 +156,7 @@ describe('TrendsLineChart', () => {
})
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
const tooltip = await chart.hoverTooltip(2)
@@ -224,7 +224,7 @@ describe('TrendsLineChart', () => {
// One data series + one moving-average overlay = 2 rendered series.
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
})
@@ -248,7 +248,7 @@ describe('TrendsLineChart', () => {
renderInsight({ query: buildTrendsQuery() })
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 1 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 1 data series/i)).toBeInTheDocument()
})
})
})
@@ -289,7 +289,7 @@ describe('TrendsLineChart', () => {
inSharedMode: true,
})
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
expect(document.querySelectorAll('.AnnotationsBadge')).toHaveLength(0)
})
})
@@ -307,7 +307,7 @@ describe('TrendsLineChart', () => {
})
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
})
@@ -325,7 +325,7 @@ describe('TrendsLineChart', () => {
}),
})
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
await waitFor(() => {
const ticks = getHogChart().yTicks()
expect(ticks.length).toBeGreaterThan(0)
@@ -394,7 +394,7 @@ describe('TrendsLineChart', () => {
query: buildTrendsQuery(),
})
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
// Reference lines come exclusively from goalLines in this test (none configured),
// so the count must be 0 — anything here would be a leaked alert overlay.
expect(getHogChart().referenceLines()).toHaveLength(0)
@@ -414,7 +414,7 @@ describe('TrendsLineChart', () => {
// Wait for both series before toggling.
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
await legend.toggle('Napped')
@@ -437,14 +437,14 @@ describe('TrendsLineChart', () => {
await waitFor(() => {
// 2 main + 2 trend lines = 4 series
- expect(screen.getByRole('img', { name: /chart with 4 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 4 data series/i)).toBeInTheDocument()
})
await legend.toggle('Napped')
await waitFor(() => {
// Hiding Napped removes its main series + its trend line.
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
// No Napped value labels remain (Napped's data is 1, 3, 5, 8, 2; the 8 was the
@@ -477,7 +477,7 @@ describe('TrendsLineChart', () => {
query: buildTrendsQuery({ trendsFilter }),
})
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
expect(getHogChart().xAxisLabel()).toBe(expectedX)
expect(getHogChart().yAxisLabel()).toBe(expectedY)
})
@@ -533,7 +533,7 @@ describe('TrendsLineChart', () => {
query: buildTrendsQuery({ trendsFilter: { goalLines } }),
})
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
await waitFor(
() => {
const lines = getHogChart().referenceLines()
@@ -594,7 +594,7 @@ describe('TrendsLineChart', () => {
it('renders no labels when showValuesOnSeries is disabled', async () => {
renderInsight({ query: buildTrendsQuery() })
- await screen.findByRole('img', { name: /chart with/i })
+ await screen.findByLabelText(/chart with/i)
expect(getHogChart().valueLabels()).toHaveLength(0)
})
})
@@ -609,7 +609,7 @@ describe('TrendsLineChart', () => {
})
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
const tooltip = await chart.hoverTooltip(2)
@@ -629,7 +629,7 @@ describe('TrendsLineChart', () => {
it('adds a CI band series when enabled', async () => {
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
})
@@ -652,7 +652,7 @@ describe('TrendsLineChart', () => {
it('adds a dashed trend-line series when enabled', async () => {
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
})
@@ -681,7 +681,7 @@ describe('TrendsLineChart', () => {
// main + raw trendline + moving avg + moving-avg trendline = 4 series.
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 4 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 4 data series/i)).toBeInTheDocument()
})
})
})
@@ -697,7 +697,7 @@ describe('TrendsLineChart', () => {
await waitFor(() => {
expect(screen.getByTestId('insight-empty-state')).toBeInTheDocument()
})
- expect(screen.queryByRole('img', { name: /chart with/i })).not.toBeInTheDocument()
+ expect(screen.queryByLabelText(/chart with/i)).not.toBeInTheDocument()
})
it('uses context.emptyStateHeading override when provided', async () => {
@@ -832,7 +832,7 @@ describe('TrendsLineChart', () => {
const { container } = renderInsight({ query: twoSeriesQuery, featureFlags: quillLegendFlag })
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
const legendEl = getInChartLegend(container)
@@ -844,7 +844,7 @@ describe('TrendsLineChart', () => {
const { container } = renderInsight({ query: twoSeriesQuery, featureFlags: quillLegendFlag })
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
const legendEl = getInChartLegend(container)
@@ -872,7 +872,7 @@ describe('TrendsLineChart', () => {
})
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
const legendEl = getInChartLegend(container)
@@ -895,7 +895,7 @@ describe('TrendsLineChart', () => {
})
await waitFor(() => {
- expect(screen.getByRole('img', { name: /chart with 2 data series/i })).toBeInTheDocument()
+ expect(screen.getByLabelText(/chart with 2 data series/i)).toBeInTheDocument()
})
const legendEl = getInChartLegend(container)
diff --git a/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.test.tsx
index 5fb25132dd1e..d019b29c8095 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.test.tsx
@@ -53,7 +53,7 @@ describe('TrendsPieChart (ActionsPie)', () => {
},
])('$name', async ({ query, expectedLabels }) => {
renderInsight({ query })
- await screen.findByRole('img', { name: /pie chart with/i }, { timeout: 5000 })
+ await screen.findByLabelText(/pie chart with/i, undefined, { timeout: 5000 })
await waitFor(
() => {
diff --git a/products/workflows/mcp/apps/EmailTemplateView.test.tsx b/products/workflows/mcp/apps/EmailTemplateView.test.tsx
index 2eae5a2ad442..2ba565cf450f 100644
--- a/products/workflows/mcp/apps/EmailTemplateView.test.tsx
+++ b/products/workflows/mcp/apps/EmailTemplateView.test.tsx
@@ -50,15 +50,15 @@ describe('EmailTemplateView', () => {
it('links the edit button to the _posthogUrl', () => {
render(<EmailTemplateView template={baseTemplate} />)
- const link = screen.getByRole('link', { name: /open in editor/i })
- expect(link.getAttribute('href')).toBe(baseTemplate._posthogUrl)
+ const link = screen.getByText(/open in editor/i).closest('a')
+ expect(link?.getAttribute('href')).toBe(baseTemplate._posthogUrl)
})
it('omits the edit link when there is no _posthogUrl', () => {
const { _posthogUrl, ...withoutUrl } = baseTemplate
render(<EmailTemplateView template={withoutUrl} />)
- expect(screen.queryByRole('link', { name: /open in editor/i })).toBeNull()
+ expect(screen.queryByText(/open in editor/i)).toBeNull()
})
it('falls back to plain text when there is no html', () => {