Repository navigation
chore(taxonomic-filter): share the context filters and cover the menu #91206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0e71eda
fix(insights): keep the Pinned tab to groups the picker offers
haacked 4df4a99
chore(insights): drop a redundant cast in the pinned-tab test
haacked 36cf0e2
test(taxonomic-filter): cover the menu's pinned context filter
haacked a921f8c
refactor(taxonomic-filter): share the recents filter with the legacy …
haacked 35c14dd
chore(taxonomic-filter): refresh the generated recents selector type
haacked 55e80ae
chore(taxonomic-filter): make the pinned override comment durable
haacked File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.pinned.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import '@testing-library/jest-dom' | ||
|
|
||
| import { cleanup, render, screen, waitFor } from '@testing-library/react' | ||
| import userEvent from '@testing-library/user-event' | ||
| import { Provider } from 'kea' | ||
|
|
||
| import { useMocks } from '~/mocks/jest' | ||
| import { actionsModel } from '~/models/actionsModel' | ||
| import { groupsModel } from '~/models/groupsModel' | ||
| import { performQuery } from '~/queries/query' | ||
| import { initKeaTests } from '~/test/init' | ||
| import { emptyPaginated } from '~/test/mocks/taxonomicFilterApiMock' | ||
|
|
||
| import { TaxonomicFilterHeadless } from '../headless' | ||
| import { __clearTaxonomicResourceCache } from '../hooks/useTaxonomicResource' | ||
| import { taxonomicFilterPinnedPropertiesLogic } from '../taxonomicFilterPinnedPropertiesLogic' | ||
| import { TaxonomicFilterGroupType } from '../types' | ||
| import { TaxonomicFilterMenu } from './TaxonomicFilterMenu' | ||
|
|
||
| jest.mock('~/queries/query', () => ({ | ||
| performQuery: jest.fn(), | ||
| })) | ||
|
|
||
| jest.mock('posthog-js', () => ({ | ||
| __esModule: true, | ||
| default: { capture: jest.fn() }, | ||
| })) | ||
|
|
||
| jest.mock('lib/api', () => require('~/test/mocks/taxonomicFilterApiMock').buildTaxonomicFilterApiMock()) | ||
|
|
||
| const apiGet = jest.requireMock('lib/api').default.get as jest.MockedFunction<any> | ||
|
|
||
| // Two content groups, so the picker does not take the sole-group path that | ||
| // promotes pinned items into the single list. | ||
| const GROUP_TYPES = [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.EventProperties] | ||
|
|
||
| function renderMenu(): ReturnType<typeof render> { | ||
| return render( | ||
| <Provider> | ||
| <TaxonomicFilterHeadless.Root taxonomicGroupTypes={GROUP_TYPES} onChange={jest.fn()}> | ||
| <TaxonomicFilterMenu /> | ||
| </TaxonomicFilterHeadless.Root> | ||
| </Provider> | ||
| ) | ||
| } | ||
|
|
||
| function pinnedRowTexts(): string[] { | ||
| return Array.from(document.querySelectorAll('[data-slot="taxonomic-filter-menu-row"]')).map( | ||
| (el) => el.textContent ?? '' | ||
| ) | ||
| } | ||
|
|
||
| describe('TaxonomicFilterMenu pinned rows', () => { | ||
| beforeEach(() => { | ||
| __clearTaxonomicResourceCache() | ||
| apiGet.mockReset() | ||
| apiGet.mockImplementation(emptyPaginated) | ||
| ;(performQuery as jest.Mock).mockResolvedValue({ tables: {}, joins: [] }) | ||
| useMocks({}) | ||
| localStorage.clear() | ||
| initKeaTests() | ||
| actionsModel.mount() | ||
| groupsModel.mount() | ||
| }) | ||
|
|
||
| afterEach(() => cleanup()) | ||
|
|
||
| // Pins are stored globally, so a pin can outlive the picker it was made in. | ||
| // Without the context filter the cohort still renders: resolveShortcutGroup | ||
| // falls back to the first non-meta group, so it appears as an Events row and | ||
| // commits a cohort id under the Events group. | ||
| it('leaves out a pin whose source group this picker does not offer', async () => { | ||
| const pinnedLogic = taxonomicFilterPinnedPropertiesLogic.build() | ||
| pinnedLogic.mount() | ||
| pinnedLogic.actions.setPinnedFilters([ | ||
| { | ||
| groupType: TaxonomicFilterGroupType.Events, | ||
| groupName: 'Events', | ||
| value: 'signed up', | ||
| item: { name: 'signed up' }, | ||
| timestamp: 0, | ||
| }, | ||
| { | ||
| groupType: TaxonomicFilterGroupType.Cohorts, | ||
| groupName: 'Cohorts', | ||
| value: 1, | ||
| item: { name: 'Power users' }, | ||
| timestamp: 0, | ||
| }, | ||
| ]) | ||
|
|
||
| renderMenu() | ||
|
|
||
| await userEvent.click(screen.getByTestId('taxonomic-filter-menu-trigger')) | ||
| await waitFor(() => { | ||
| expect(screen.getByText('Pinned')).toBeInTheDocument() | ||
| }) | ||
| await userEvent.click(screen.getByText('Pinned')) | ||
|
|
||
| await waitFor(() => { | ||
| expect(pinnedRowTexts().length).toBeGreaterThan(0) | ||
| }) | ||
| const rows = pinnedRowTexts() | ||
| expect(rows.some((text) => text.includes('signed up'))).toBe(true) | ||
| expect(rows.some((text) => text.includes('Power users'))).toBe(false) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.