Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Nov 21, 2023
1 parent e7af3ef commit 4bd4213
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions src/services/analytics/__tests__/gtm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,11 @@ jest.mock('../TagManager', () => ({
setUserProperty: jest.fn(),
}))

const FAKE_SAFE_APP_NAME = 'Safe App'
const FAKE_DOMAIN = 'http://domain.crypto'

describe('gtm', () => {
// Reset mocks before each test
beforeEach(() => {
jest.clearAllMocks()
})
describe('normalizeAppName', () => {
it('should return the app name if is not an URL', () => {
expect(gtm.normalizeAppName(FAKE_SAFE_APP_NAME)).toBe(FAKE_SAFE_APP_NAME)
})

it('should strip the querystring or hash when is an URL', () => {
expect(gtm.normalizeAppName(FAKE_DOMAIN)).toBe(FAKE_DOMAIN)
expect(gtm.normalizeAppName(`${FAKE_DOMAIN}?q1=query1&q2=query2`)).toBe(FAKE_DOMAIN)
expect(gtm.normalizeAppName(`${FAKE_DOMAIN}#hash`)).toBe(FAKE_DOMAIN)
})
})

describe('gtmInit', () => {
gtm.gtmInit()

expect(TagManager.initialize).toHaveBeenCalledWith({
auth: expect.any(String),
gtmId: expect.any(String),
preview: 'env-3',
})
})

describe('gtmTrack', () => {
it('should send correct data to the dataLayer', () => {
Expand Down Expand Up @@ -136,5 +112,20 @@ describe('gtm', () => {
}),
)
})

describe('normalizeAppName', () => {
const FAKE_SAFE_APP_NAME = 'Safe App'
const FAKE_DOMAIN = 'http://domain.crypto'

it('should return the app name if is not an URL', () => {
expect(gtm.normalizeAppName(FAKE_SAFE_APP_NAME)).toBe(FAKE_SAFE_APP_NAME)
})

it('should strip the querystring or hash when is an URL', () => {
expect(gtm.normalizeAppName(FAKE_DOMAIN)).toBe(FAKE_DOMAIN)
expect(gtm.normalizeAppName(`${FAKE_DOMAIN}?q1=query1&q2=query2`)).toBe(FAKE_DOMAIN)
expect(gtm.normalizeAppName(`${FAKE_DOMAIN}#hash`)).toBe(FAKE_DOMAIN)
})
})
})
})

0 comments on commit 4bd4213

Please sign in to comment.