Skip to content

Commit

Permalink
fix: Navigate to site after reporting to segment (decentraland#1894)
Browse files Browse the repository at this point in the history
* fix: Navigate to site after reporting to segment

* fix: Tests
  • Loading branch information
LautaroPetaccio authored Jun 26, 2023
1 parent e473aae commit ccf8b3f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { fireEvent } from '@testing-library/react'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { getAnalytics } from 'decentraland-dapps/dist/modules/analytics/utils'
import { renderWithProviders } from '../../../utils/test'
import { List } from '../../../modules/favorites/types'

import { Props } from './ShareListModal.types'
import ShareListModal from './ShareListModal'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { fireEvent } from '@testing-library/react'

jest.mock('decentraland-dapps/dist/modules/analytics/utils')

const getAnalyticsMock = getAnalytics as jest.Mock

let list: List = {
id: 'aListId',
Expand All @@ -26,6 +31,18 @@ function renderShareListModal(props: Partial<Props> = {}) {
)
}

beforeEach(() => {
getAnalyticsMock.mockReturnValue({
page: jest.fn(),
track: (
_event: unknown,
_data: unknown,
_options: unknown,
callback: () => unknown
) => callback()
})
})

describe('when the modal is rendered', () => {
let renderedModal: ReturnType<typeof renderShareListModal>

Expand All @@ -46,8 +63,16 @@ describe('when the modal is rendered', () => {
const { getByText } = renderedModal
expect(getByText(list.name)).toBeInTheDocument()
})
})

describe('when the share on twitter button is clicked', () => {
let renderedModal: ReturnType<typeof renderShareListModal>

beforeEach(() => {
renderedModal = renderShareListModal()
})

it('should have a twitter share button with the href pointing to a twitter message', () => {
it('should open a new page with a twitter message', () => {
jest.spyOn(window, 'open').mockImplementation(() => null)
const dclUrl = 'https://market.decentraland.zone'
const locationsUrl =
Expand Down
18 changes: 12 additions & 6 deletions webapp/src/components/Modals/ShareListModal/ShareListModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ const ShareListModal = (props: Props) => {
const url = `${twitterLink}${encodeURIComponent(
`${t('share_list_modal.twitter_message')}${MARKETPLACE_URL}${listLink}`
)}`
getAnalytics().track(events.SHARE_LIST, {
list,
url,
type: events.SHARE_LIST_TYPE.TWITTER
})
window.open(url, '_blank')
getAnalytics().track(
events.SHARE_LIST,
{
list,
url,
type: events.SHARE_LIST_TYPE.TWITTER
},
{},
() => {
window.open(url, '_blank')
}
)
e.currentTarget.blur()
},
[list, listLink]
Expand Down

0 comments on commit ccf8b3f

Please sign in to comment.