Unverified Commit 32015bac authored by Sudheer's avatar Sudheer Committed by GitHub
Browse files

MM-26685 enable redux setting to emit rudder events when url and key is set (#5858)

* MM-26685 enable redux setting to emit rudder events when url and key is set

* Update tests

* Update redux hash

* Update redux hash

* Update redux hash
parent f2161612
......@@ -3,7 +3,7 @@
import $ from 'jquery';
import {rudderAnalytics} from 'mattermost-redux/client';
import {rudderAnalytics, client4} from 'mattermost-redux/client';
import PropTypes from 'prop-types';
import React from 'react';
import FastClick from 'fastclick';
......@@ -164,6 +164,7 @@ export default class Root extends React.PureComponent {
const rudderUrl = Constants.DIAGNOSTICS_RUDDER_DATAPLANE_URL;
if (rudderKey != null && rudderKey !== '' && !rudderKey.startsWith('placeholder') && rudderUrl != null && rudderUrl !== '' && !rudderUrl.startsWith('placeholder') && this.props.diagnosticsEnabled) {
client4.enableRudderEvents();
rudderAnalytics.load(rudderKey, rudderUrl);
rudderAnalytics.identify(diagnosticId, {}, {
......
......@@ -4,9 +4,12 @@
import React from 'react';
import {shallow} from 'enzyme';
import {client4} from 'mattermost-redux/client';
import Root from 'components/root/root';
import * as GlobalActions from 'actions/global_actions.jsx';
import * as Utils from 'utils/utils';
import Constants from 'utils/constants';
jest.mock('fastclick', () => ({
attach: () => {}, // eslint-disable-line no-empty-function
......@@ -26,6 +29,18 @@ jest.mock('utils/utils', () => ({
enableDevModeFeatures: jest.fn(),
}));
jest.mock('mattermost-redux/client', () => {
const original = require.requireActual('mattermost-redux/client');
return {
...original,
client4: {
...original.client4,
enableRudderEvents: jest.fn(),
},
};
});
describe('components/Root', () => {
const baseProps = {
diagnosticsEnabled: true,
......@@ -167,4 +182,19 @@ describe('components/Root', () => {
wrapper.setProps(props2);
expect(props.history.push).toHaveBeenLastCalledWith('/signup_user_complete');
});
test('should not call enableRudderEvents on call of onConfigLoaded if url and key for rudder is not set', () => {
const wrapper = shallow(<Root {...baseProps}/>);
wrapper.instance().onConfigLoaded();
expect(client4.enableRudderEvents).not.toHaveBeenCalled();
});
test('should call for enableRudderEvents on call of onConfigLoaded if url and key for rudder is set', () => {
Constants.DIAGNOSTICS_RUDDER_KEY = 'testKey';
Constants.DIAGNOSTICS_RUDDER_DATAPLANE_URL = 'url';
const wrapper = shallow(<Root {...baseProps}/>);
wrapper.instance().onConfigLoaded();
expect(client4.enableRudderEvents).toHaveBeenCalled();
});
});
......@@ -18109,8 +18109,8 @@
"integrity": "sha512-6qE4B9deFBIa9YSpOc9O0Sgc43zTeVYbgDT5veRKSlB2+ZuHNoVVxA1L/ckMUayV9Ay9y7Z/SZCLcGteW9i7bg=="
},
"mattermost-redux": {
"version": "github:mattermost/mattermost-redux#9ffb2f619450ac03ebbe54491f1e9a7da3744b2d",
"from": "github:mattermost/mattermost-redux#9ffb2f619450ac03ebbe54491f1e9a7da3744b2d",
"version": "github:mattermost/mattermost-redux#8b003ea1aa10bf64b306a006e8a0ed7477924704",
"from": "github:mattermost/mattermost-redux#8b003ea1aa10bf64b306a006e8a0ed7477924704",
"requires": {
"core-js": "3.6.4",
"form-data": "3.0.0",
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