Skip to content

Commit

Permalink
(PC-32824)[PRO] feat: Add tracker on event stock filters update.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmeigniez-pass committed Feb 10, 2025
1 parent 38ed446 commit 68e7c9a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions pro/src/commons/core/FirebaseEvents/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export enum Events {
CLICKED_CONSULT_HELP = 'hasClickedConsultHelp',
UPDATED_BOOKING_LIMIT_DATE = 'hasUpdatedBookingLimitDate',
CLICKED_GENERATE_TEMPLATE_DESCRIPTION = 'hasClickedGenerateTemplateDescription',
UPDATED_EVENT_STOCK_FILTERS = 'hasUpdatedEventStockFilters',
}

export enum VenueEvents {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
StocksOrderedBy,
OfferStatus,
} from 'apiClient/v1'
import { useAnalytics } from 'app/App/analytics/firebase'
import { GET_OFFER_QUERY_KEY } from 'commons/config/swrQueryKeys'
import { Events } from 'commons/core/FirebaseEvents/constants'
import { OFFER_WIZARD_MODE } from 'commons/core/Offers/constants'
import { getIndividualOfferUrl } from 'commons/core/Offers/utils/getIndividualOfferUrl'
import { isOfferDisabled } from 'commons/core/Offers/utils/isOfferDisabled'
Expand Down Expand Up @@ -126,6 +128,7 @@ export const StocksEventEdition = ({
offer,
}: StocksEventEditionProps): JSX.Element => {
// utilities
const { logEvent } = useAnalytics()
const mode = useOfferWizardMode()
const navigate = useNavigate()
const { pathname } = useLocation()
Expand Down Expand Up @@ -414,6 +417,9 @@ export const StocksEventEdition = ({

const onFilterChange = () => {
firstPage()
logEvent(Events.UPDATED_EVENT_STOCK_FILTERS, {
formType: 'edition',
})
}
const isDisabled = isOfferDisabled(offer.status)
const isSynchronized = Boolean(offer.lastProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from 'apiClient/v1'
import { ApiRequestOptions } from 'apiClient/v1/core/ApiRequestOptions'
import { ApiResult } from 'apiClient/v1/core/ApiResult'
import * as useAnalytics from 'app/App/analytics/firebase'
import { IndividualOfferContextProvider } from 'commons/context/IndividualOfferContext/IndividualOfferContext'
import { OFFER_WIZARD_MODE } from 'commons/core/Offers/constants'
import {
Expand Down Expand Up @@ -114,6 +115,7 @@ const renderStockEventScreen = async (

const priceCategoryId = '1'
const otherPriceCategoryId = '2'
const mockLogEvent = vi.fn()

describe('screens:StocksEventEdition', () => {
let apiOffer: GetIndividualOfferWithAddressResponseModel
Expand Down Expand Up @@ -171,6 +173,10 @@ describe('screens:StocksEventEdition', () => {
withdrawalDelay: null,
bookingsCount: 0,
})

vi.spyOn(useAnalytics, 'useAnalytics').mockImplementation(() => ({
logEvent: mockLogEvent,
}))
})

it('render stock event row', async () => {
Expand Down Expand Up @@ -582,4 +588,15 @@ describe('screens:StocksEventEdition', () => {
await userEvent.click(screen.getByText('Quitter la page'))
expect(screen.getByText('Page 3/6')).toBeInTheDocument()
})

it('should trigger an event log when a filter changes', async () => {
await renderStockEventScreen(apiOffer, apiStocks)

await userEvent.selectOptions(
screen.getByLabelText('Filtrer par tarif'),
'1'
)

expect(mockLogEvent).toHaveBeenCalled()
})
})
3 changes: 3 additions & 0 deletions pro/src/components/StocksEventList/StocksEventList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ export const StocksEventList = ({
// Handlers
const onFilterChange = () => {
firstPage()
logEvent(Events.UPDATED_EVENT_STOCK_FILTERS, {
formType: readonly ? 'readonly' : 'creation',
})
}

const onStockCheckChange = (index: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { userEvent } from '@testing-library/user-event'

import { api } from 'apiClient/api'
import { GetOfferStockResponseModel, StocksOrderedBy } from 'apiClient/v1'
import * as useAnalytics from 'app/App/analytics/firebase'
import {
getIndividualOfferFactory,
getOfferStockFactory,
Expand Down Expand Up @@ -77,7 +78,15 @@ const renderStocksEventList = async (
})
}

const mockLogEvent = vi.fn()

describe('StocksEventList', () => {
beforeEach(() => {
vi.spyOn(useAnalytics, 'useAnalytics').mockImplementation(() => ({
logEvent: mockLogEvent,
}))
})

it('should render a table with header and data', async () => {
await renderStocksEventList([stock1])

Expand Down Expand Up @@ -462,4 +471,21 @@ describe('StocksEventList', () => {
expect(api.deleteAllFilteredStocks).toBeCalledTimes(1)
expect(mockMutate).toHaveBeenCalledTimes(1)
})

it('should trigger an event log when a filter changes', async () => {
await renderStocksEventList([stock1])

vi.spyOn(api, 'getStocks').mockResolvedValueOnce({
stocks: [],
stockCount: 0,
hasStocks: false,
})

await userEvent.selectOptions(
screen.getByLabelText('Filtrer par tarif'),
String(filteredPriceCategoryId)
)

expect(mockLogEvent).toHaveBeenCalled()
})
})

0 comments on commit 68e7c9a

Please sign in to comment.