|
| 1 | +import { viewScreenEvent } from './analytics'; |
| 2 | + |
| 3 | +interface MockedData { |
| 4 | + getFirstAAID_value?: boolean; |
| 5 | +} |
| 6 | + |
| 7 | +const mockedData: MockedData = {}; |
| 8 | + |
| 9 | +jest.mock('./container', () => ({ |
| 10 | + Container: { siteManager: { getFirstAAID: () => mockedData.getFirstAAID_value } }, |
| 11 | +})); |
| 12 | + |
| 13 | +function setProcessPlatform(platform: NodeJS.Platform) { |
| 14 | + Object.defineProperty(process, 'platform', { |
| 15 | + value: platform, |
| 16 | + writable: false, |
| 17 | + }); |
| 18 | +} |
| 19 | + |
| 20 | +describe('viewScreenEvent', () => { |
| 21 | + const originalPlatform = process.platform; |
| 22 | + |
| 23 | + beforeAll(() => { |
| 24 | + setProcessPlatform('win32'); |
| 25 | + }); |
| 26 | + |
| 27 | + beforeEach(() => { |
| 28 | + mockedData.getFirstAAID_value = true; |
| 29 | + }); |
| 30 | + |
| 31 | + afterAll(() => { |
| 32 | + setProcessPlatform(originalPlatform); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should create a screen event with the correct screen name', async () => { |
| 36 | + const screenName = 'testScreen'; |
| 37 | + const event = await viewScreenEvent(screenName); |
| 38 | + expect(event.name).toEqual(screenName); |
| 39 | + expect(event.screenEvent.attributes).toBeUndefined(); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should exclude from activity if screen name is atlascodeWelcomeScreen', async () => { |
| 43 | + const screenName = 'atlascodeWelcomeScreen'; |
| 44 | + const event = await viewScreenEvent(screenName); |
| 45 | + expect(event.screenEvent.attributes.excludeFromActivity).toBeTruthy(); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should include site information if provided (cloud)', async () => { |
| 49 | + const screenName = 'testScreen'; |
| 50 | + const site: any = { |
| 51 | + id: 'siteId', |
| 52 | + product: { name: 'Jira', key: 'jira' }, |
| 53 | + isCloud: true, |
| 54 | + }; |
| 55 | + const event = await viewScreenEvent(screenName, site); |
| 56 | + expect(event.screenEvent.attributes.instanceType).toEqual('cloud'); |
| 57 | + expect(event.screenEvent.attributes.hostProduct).toEqual('Jira'); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should include site information if provided (server)', async () => { |
| 61 | + const screenName = 'testScreen'; |
| 62 | + const site: any = { |
| 63 | + id: 'siteId', |
| 64 | + product: { name: 'Jira', key: 'jira' }, |
| 65 | + isCloud: false, |
| 66 | + }; |
| 67 | + const event = await viewScreenEvent(screenName, site); |
| 68 | + expect(event.screenEvent.attributes.instanceType).toEqual('server'); |
| 69 | + expect(event.screenEvent.attributes.hostProduct).toEqual('Jira'); |
| 70 | + }); |
| 71 | + |
| 72 | + it('should include product information if provided', async () => { |
| 73 | + const screenName = 'testScreen'; |
| 74 | + const product = { name: 'Bitbucket', key: 'bitbucket' }; |
| 75 | + const event = await viewScreenEvent(screenName, undefined, product); |
| 76 | + expect(event.screenEvent.attributes.hostProduct).toEqual('Bitbucket'); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should set platform based on process.platform (win32)', async () => { |
| 80 | + setProcessPlatform('win32'); |
| 81 | + const screenName = 'testScreen'; |
| 82 | + const event = await viewScreenEvent(screenName); |
| 83 | + expect(event.screenEvent.platform).toEqual('windows'); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should set platform based on process.platform (darwin)', async () => { |
| 87 | + setProcessPlatform('darwin'); |
| 88 | + const screenName = 'testScreen'; |
| 89 | + const event = await viewScreenEvent(screenName); |
| 90 | + expect(event.screenEvent.platform).toEqual('mac'); |
| 91 | + }); |
| 92 | + |
| 93 | + it('should set platform based on process.platform (linux)', async () => { |
| 94 | + setProcessPlatform('linux'); |
| 95 | + const screenName = 'testScreen'; |
| 96 | + const event = await viewScreenEvent(screenName); |
| 97 | + expect(event.screenEvent.platform).toEqual('linux'); |
| 98 | + }); |
| 99 | + |
| 100 | + it('should set platform based on process.platform (aix)', async () => { |
| 101 | + setProcessPlatform('aix'); |
| 102 | + const screenName = 'testScreen'; |
| 103 | + const event = await viewScreenEvent(screenName); |
| 104 | + expect(event.screenEvent.platform).toEqual('desktop'); |
| 105 | + }); |
| 106 | +}); |
0 commit comments