-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updated staking events to use withMetaMetrics helper (#12337)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR updates the events added in #12144 to use the `withMetaMetrics` helper function. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Related issues** Jira Ticket: [STAKE-876: Wrap existing Staking events with withMetaMetrics hook](https://consensyssoftware.atlassian.net/browse/STAKE-876) ## **Manual testing steps** Prerequisite: Add `export MM_POOLED_STAKING_UI_ENABLED=true` to your local `.js.env` file. All events can be tested by running through the stake and unstake flows. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> N/A ### **After** <!-- [screenshots/recordings] --> N/A ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
- Loading branch information
Showing
11 changed files
with
175 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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
99 changes: 99 additions & 0 deletions
99
app/components/UI/Stake/utils/metaMetrics/withMetaMetrics.test.ts
This file contains 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,99 @@ | ||
import { withMetaMetrics } from './withMetaMetrics'; | ||
import { MetaMetrics } from '../../../../../core/Analytics'; | ||
import { MetaMetricsEvents } from '../../../../hooks/useMetrics'; | ||
|
||
describe('withMetaMetrics', () => { | ||
let trackEventSpy: jest.SpyInstance; | ||
|
||
const MOCK_HANDLER_RESULT = 123; | ||
const mockHandler = () => MOCK_HANDLER_RESULT; | ||
const mockAsyncHandler = async () => MOCK_HANDLER_RESULT; | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
trackEventSpy = jest.spyOn(MetaMetrics.getInstance(), 'trackEvent'); | ||
}); | ||
|
||
it('fires single event when wrapping sync function', () => { | ||
const mockHandlerWithMetaMetrics = withMetaMetrics(mockHandler, { | ||
event: MetaMetricsEvents.STAKE_BUTTON_CLICKED, | ||
properties: { | ||
sample: 'value', | ||
}, | ||
}); | ||
|
||
const result = mockHandlerWithMetaMetrics(); | ||
|
||
expect(result).toEqual(MOCK_HANDLER_RESULT); | ||
expect(trackEventSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('fires array of events when wrapping sync function', () => { | ||
const mockHandlerWithMetaMetrics = withMetaMetrics(mockHandler, [ | ||
{ | ||
event: MetaMetricsEvents.TOOLTIP_OPENED, | ||
properties: { | ||
selected_provider: 'consensys', | ||
text: 'Tooltip Opened', | ||
location: 'Unit Test', | ||
tooltip_name: 'Test Tooltip 1', | ||
}, | ||
}, | ||
{ | ||
event: MetaMetricsEvents.TOOLTIP_OPENED, | ||
properties: { | ||
selected_provider: 'consensys', | ||
text: 'Tooltip Opened', | ||
location: 'Unit Test', | ||
tooltip_name: 'Test Tooltip 2', | ||
}, | ||
}, | ||
]); | ||
|
||
const result = mockHandlerWithMetaMetrics(); | ||
expect(result).toEqual(MOCK_HANDLER_RESULT); | ||
expect(trackEventSpy).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
it('fires single event when wrapping async function', async () => { | ||
const mockAsyncHandlerWithMetaMetrics = withMetaMetrics(mockAsyncHandler, { | ||
event: MetaMetricsEvents.STAKE_BUTTON_CLICKED, | ||
properties: { | ||
sample: 'value', | ||
}, | ||
}); | ||
|
||
const result = await mockAsyncHandlerWithMetaMetrics(); | ||
|
||
expect(result).toEqual(MOCK_HANDLER_RESULT); | ||
expect(trackEventSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('fires all events when wrapping async function', async () => { | ||
const mockAsyncHandlerWithMetaMetrics = withMetaMetrics(mockAsyncHandler, [ | ||
{ | ||
event: MetaMetricsEvents.TOOLTIP_OPENED, | ||
properties: { | ||
selected_provider: 'consensys', | ||
text: 'Tooltip Opened', | ||
location: 'Unit Test', | ||
tooltip_name: 'Test Tooltip 1', | ||
}, | ||
}, | ||
{ | ||
event: MetaMetricsEvents.TOOLTIP_OPENED, | ||
properties: { | ||
selected_provider: 'consensys', | ||
text: 'Tooltip Opened', | ||
location: 'Unit Test', | ||
tooltip_name: 'Test Tooltip 2', | ||
}, | ||
}, | ||
]); | ||
|
||
const result = await mockAsyncHandlerWithMetaMetrics(); | ||
|
||
expect(result).toEqual(MOCK_HANDLER_RESULT); | ||
expect(trackEventSpy).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
This file contains 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.