Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
MM-25525 Sidebar: Event for tracking number of visible GMs and DMs in…
Browse files Browse the repository at this point in the history
… LHS (#5794)

* MM-25525 Sidebar: Event for tracking number of visible GMs and DMs in sidebar

* Fix types

* Fix test

* Use getDirectChannels

* Update rudder key for testing

* Fix Actions type

* Remove Rudder keys for testing

Co-authored-by: Harrison Healey <[email protected]>
  • Loading branch information
sudheerDev and hmhealey committed Jul 21, 2020
1 parent bb57d35 commit 7b15c24
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
12 changes: 12 additions & 0 deletions actions/user_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getMyChannels,
getMyChannelMember,
getChannelMembersInChannels,
getDirectChannels,
} from 'mattermost-redux/selectors/entities/channels';
import {getBool} from 'mattermost-redux/selectors/entities/preferences';
import {getCurrentTeamId, getTeamMember} from 'mattermost-redux/selectors/entities/teams';
Expand All @@ -21,6 +22,7 @@ import {makeFilterAutoclosedDMs, makeFilterManuallyClosedDMs} from 'mattermost-r
import {CategoryTypes} from 'mattermost-redux/constants/channel_categories';

import {loadStatusesForProfilesList, loadStatusesForProfilesMap} from 'actions/status_actions.jsx';
import {trackEvent} from 'actions/diagnostics_actions.jsx';
import store from 'stores/redux_store.jsx';
import * as Utils from 'utils/utils.jsx';
import {Constants, Preferences, UserStatuses} from 'utils/constants';
Expand Down Expand Up @@ -419,3 +421,13 @@ export function autoResetStatus() {
return userStatus;
};
}

export function trackDMGMOpenChannels() {
return (doDispatch, doGetState) => {
const state = doGetState();
const channels = getDirectChannels(state);
trackEvent('ui', 'LHS_DM_GM_Count', {count: channels.length});

return {data: true};
};
}
31 changes: 29 additions & 2 deletions actions/user_actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {CategoryTypes} from 'mattermost-redux/constants/channel_categories';
import * as UserActions from 'actions/user_actions';
import {getState} from 'stores/redux_store';
import TestHelper from 'tests/helpers/client-test-helper';
import {trackEvent} from 'actions/diagnostics_actions.jsx';

const mockStore = configureStore([thunk]);

Expand All @@ -29,12 +30,24 @@ jest.mock('mattermost-redux/actions/users', () => {
};
});

jest.mock('mattermost-redux/selectors/entities/channels', () => {
const GeneralTypes = require.requireActual('mattermost-redux/constants').General;
const original = jest.requireActual('mattermost-redux/selectors/entities/channels');
const mockDmGmUsersInLhs = [{id: 'gmChannel', type: GeneralTypes.GM_CHANNEL}, {id: 'dmChannel', type: GeneralTypes.DM_CHANNEL}];

return {
...original,
getDirectChannels: jest.fn().mockReturnValue(mockDmGmUsersInLhs),
};
});

jest.mock('mattermost-redux/selectors/entities/channel_categories', () => {
const GeneralTypes = jest.requireActual('mattermost-redux/constants').General;
const original = jest.requireActual('mattermost-redux/selectors/entities/channel_categories');
const GeneralTypes = require.requireActual('mattermost-redux/constants').General;
const original = require.requireActual('mattermost-redux/selectors/entities/channel_categories');

const mockChannelsObj = [{id: 'gmChannel', type: GeneralTypes.GM_CHANNEL}];
const mockFunc = jest.fn();

return {
...original,
makeFilterAutoclosedDMs: jest.fn().mockReturnValue(mockFunc),
Expand Down Expand Up @@ -74,6 +87,14 @@ jest.mock('stores/redux_store', () => {
};
});

jest.mock('actions/diagnostics_actions.jsx', () => {
const original = require.requireActual('actions/diagnostics_actions.jsx');
return {
...original,
trackEvent: jest.fn(),
};
});

describe('Actions.User', () => {
const initialState = {
entities: {
Expand Down Expand Up @@ -349,4 +370,10 @@ describe('Actions.User', () => {
expect(UserActions.queue.onEmpty).toHaveBeenCalled();
expect(UserActions.queue.add).toHaveBeenCalled();
});

test('trackDMGMOpenChannels', async () => {
const testStore = await mockStore(initialState);
await testStore.dispatch(UserActions.trackDMGMOpenChannels());
expect(trackEvent).toHaveBeenCalledWith('ui', 'LHS_DM_GM_Count', {count: 2});
});
});
3 changes: 3 additions & 0 deletions components/data_prefetch/data_prefetch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('/components/create_team', () => {
currentChannelId: '',
actions: {
prefetchChannelPosts: jest.fn(() => Promise.resolve({})),
trackDMGMOpenChannels: jest.fn(() => Promise.resolve()),
},
prefetchQueueObj: {
1: ['mentionChannel'],
Expand Down Expand Up @@ -71,6 +72,8 @@ describe('/components/create_team', () => {
instance.prefetchPosts = jest.fn();
wrapper.setProps({currentChannelId: 'currentChannelId'});
expect(instance.prefetchPosts).toHaveBeenCalledWith('currentChannelId');
await loadProfilesForSidebar();
expect(defaultProps.actions.trackDMGMOpenChannels).toHaveBeenCalled();
});

test('should call for LHS profiles and also call for posts based on prefetchQueueObj', async () => {
Expand Down
2 changes: 2 additions & 0 deletions components/data_prefetch/data_prefetch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Props = {
unreadChannels: Channel[];
actions: {
prefetchChannelPosts: (channelId: string, delay?: number) => Promise<any>;
trackDMGMOpenChannels: () => Promise<void>;
};
}

Expand Down Expand Up @@ -52,6 +53,7 @@ export default class DataPrefetch extends React.PureComponent<Props, {}> {
queue.add(async () => this.prefetchPosts(currentChannelId));
await loadProfilesForSidebar();
this.prefetchData();
this.props.actions.trackDMGMOpenChannels();
} else if (prevProps.prefetchQueueObj !== prefetchQueueObj) {
clearTimeout(this.prefetchTimeout);
await queue.clear();
Expand Down
3 changes: 3 additions & 0 deletions components/data_prefetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import {RelationOneToOne} from 'mattermost-redux/types/utilities';
import {GlobalState} from 'types/store';

import {prefetchChannelPosts} from 'actions/views/channel';
import {trackDMGMOpenChannels} from 'actions/user_actions';

import DataPrefetch from './data_prefetch';

type Actions = {
prefetchChannelPosts: (channelId: string, delay?: number) => Promise<{data: {}}>;
trackDMGMOpenChannels: () => Promise<void>;
};

enum Priority {
Expand Down Expand Up @@ -77,6 +79,7 @@ function mapDispatchToProps(dispatch: Dispatch<GenericAction>) {
return {
actions: bindActionCreators<ActionCreatorsMapObject<ActionFunc>, Actions>({
prefetchChannelPosts,
trackDMGMOpenChannels,
}, dispatch),
};
}
Expand Down

0 comments on commit 7b15c24

Please sign in to comment.