Commit c19bcd5c authored by Sudheer's avatar Sudheer Committed by Harrison Healey
Browse files

MM-25525 Sidebar: Event for tracking number of visible GMs and DMs in 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: default avatarHarrison Healey <harrisonmhealey@gmail.com>
parent b0acfbc4
......@@ -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';
......@@ -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';
......@@ -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};
};
}
......@@ -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]);
......@@ -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),
......@@ -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: {
......@@ -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});
});
});
......@@ -19,6 +19,7 @@ describe('/components/create_team', () => {
currentChannelId: '',
actions: {
prefetchChannelPosts: jest.fn(() => Promise.resolve({})),
trackDMGMOpenChannels: jest.fn(() => Promise.resolve()),
},
prefetchQueueObj: {
1: ['mentionChannel'],
......@@ -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 () => {
......
......@@ -18,6 +18,7 @@ type Props = {
unreadChannels: Channel[];
actions: {
prefetchChannelPosts: (channelId: string, delay?: number) => Promise<any>;
trackDMGMOpenChannels: () => Promise<void>;
};
}
......@@ -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();
......
......@@ -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 {
......@@ -77,6 +79,7 @@ function mapDispatchToProps(dispatch: Dispatch<GenericAction>) {
return {
actions: bindActionCreators<ActionCreatorsMapObject<ActionFunc>, Actions>({
prefetchChannelPosts,
trackDMGMOpenChannels,
}, dispatch),
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment