diff options
Diffstat (limited to 'spec/frontend/sentry/index_spec.js')
-rw-r--r-- | spec/frontend/sentry/index_spec.js | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/spec/frontend/sentry/index_spec.js b/spec/frontend/sentry/index_spec.js index 2dd528a8a1c..aa19bb03cda 100644 --- a/spec/frontend/sentry/index_spec.js +++ b/spec/frontend/sentry/index_spec.js @@ -4,8 +4,6 @@ import LegacySentryConfig from '~/sentry/legacy_sentry_config'; import SentryConfig from '~/sentry/sentry_config'; describe('Sentry init', () => { - let originalGon; - const dsn = 'https://123@sentry.gitlab.test/123'; const environment = 'test'; const currentUserId = '1'; @@ -14,7 +12,6 @@ describe('Sentry init', () => { const featureCategory = 'my_feature_category'; beforeEach(() => { - originalGon = window.gon; window.gon = { sentry_dsn: dsn, sentry_environment: environment, @@ -28,10 +25,6 @@ describe('Sentry init', () => { jest.spyOn(SentryConfig, 'init').mockImplementation(); }); - afterEach(() => { - window.gon = originalGon; - }); - it('exports new version of Sentry in the global object', () => { // eslint-disable-next-line no-underscore-dangle expect(window._Sentry.SDK_VERSION).not.toMatch(/^5\./); @@ -61,4 +54,49 @@ describe('Sentry init', () => { expect(LegacySentryConfig.init).not.toHaveBeenCalled(); }); }); + + describe('with "data-page" attr in body', () => { + const mockPage = 'projects:show'; + + beforeEach(() => { + document.body.dataset.page = mockPage; + + index(); + }); + + afterEach(() => { + delete document.body.dataset.page; + }); + + it('configures sentry with a "page" tag', () => { + expect(SentryConfig.init).toHaveBeenCalledTimes(1); + expect(SentryConfig.init).toHaveBeenCalledWith( + expect.objectContaining({ + tags: { + revision, + page: mockPage, + feature_category: featureCategory, + }, + }), + ); + }); + }); + + describe('with no tags configuration', () => { + beforeEach(() => { + window.gon.revision = undefined; + window.gon.feature_category = undefined; + + index(); + }); + + it('configures sentry with no tags', () => { + expect(SentryConfig.init).toHaveBeenCalledTimes(1); + expect(SentryConfig.init).toHaveBeenCalledWith( + expect.objectContaining({ + tags: {}, + }), + ); + }); + }); }); |