mattermost-mobile/app/components/message_attachments/action_button/action_button.test.js
Miguel Alatzar 2d81b497cf [MM-23520] Port mattermost-redux (#4088)
* Remove mattermost-redux

* Move mm-redux files into app/redux

* Add @redux path to tsconfig.json

* Fix imports

* Install missing dependencies

* Fix tsc errors

* Fix i18n_utils test

* Fix more imports

* Remove redux websocket

* Fix tests

* Rename @redux

* Apply changes from mattermost-redux PR 1103

* Remove mattermost-redux mention in template

* Add missing imports

* Rename app/redux/ to app/mm-redux/

* Remove test file

* Fix fetching Sidebar GM profiles

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-04-17 21:12:09 -07:00

128 lines
No EOL
4.5 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import ActionButton from './action_button';
import {changeOpacity} from 'app/utils/theme';
import {getStatusColors} from 'app/utils/message_attachment_colors';
import Preferences from '@mm-redux/constants/preferences';
describe('ActionButton', () => {
test('correct styles when from global theme', () => {
const buttonConfig = {
id: 'gpc1tihowfabfmmcizddo',
name: 'Option 1',
style: 'onlineIndicator',
};
const baseProps = {
id: buttonConfig.id,
cookie: '',
name: buttonConfig.name,
postId: buttonConfig.id,
buttonColor: buttonConfig.style,
theme: Preferences.THEMES.default,
actions: {
doPostActionWithCookie: jest.fn(),
},
};
const wrapper = shallow(<ActionButton {...baseProps}/>);
const buttonTextChild = wrapper.getElement().props.children;
const dynamicButtonStyles = wrapper.getElement().props.containerStyle[1];
expect(dynamicButtonStyles.borderColor).toBe(changeOpacity(Preferences.THEMES.default[buttonConfig.style], 0.25));
expect(buttonTextChild.props.style.color).toBe(Preferences.THEMES.default[buttonConfig.style]);
});
test('correct styles when a status color', () => {
const buttonConfig = {
id: 'gpc1tihowbfmmcizofm7zhr1to',
name: 'Option 2',
style: 'danger',
};
const baseProps = {
id: buttonConfig.id,
cookie: '',
name: buttonConfig.name,
postId: buttonConfig.id,
buttonColor: buttonConfig.style,
theme: Preferences.THEMES.default,
actions: {
doPostActionWithCookie: jest.fn(),
},
};
const wrapper = shallow(<ActionButton {...baseProps}/>);
const buttonTextChild = wrapper.getElement().props.children;
const dynamicButtonStyles = wrapper.getElement().props.containerStyle[1];
const STATUS_COLORS = getStatusColors(Preferences.THEMES.default);
expect(dynamicButtonStyles.borderColor).toBe(changeOpacity(STATUS_COLORS[buttonConfig.style], 0.25));
expect(buttonTextChild.props.style.color).toBe(STATUS_COLORS[buttonConfig.style]);
});
test('correct styles when a hex style', () => {
const buttonConfig = {
id: 'gpc1tihowbfawemmcizddo',
name: 'Option 3',
style: '#166de0',
};
const baseProps = {
id: buttonConfig.id,
cookie: '',
name: buttonConfig.name,
postId: buttonConfig.id,
buttonColor: buttonConfig.style,
theme: Preferences.THEMES.default,
actions: {
doPostActionWithCookie: jest.fn(),
},
};
const wrapper = shallow(<ActionButton {...baseProps}/>);
const buttonTextChild = wrapper.getElement().props.children;
const dynamicButtonStyles = wrapper.getElement().props.containerStyle[1];
expect(dynamicButtonStyles.borderColor).toBe(changeOpacity(buttonConfig.style, 0.25));
expect(buttonTextChild.props.style.color).toBe(buttonConfig.style);
});
test('correct default styles', () => {
const buttonConfig = {
id: 'gpc1tihowbfawemmcizddo',
name: 'Option 4',
};
const baseProps = {
id: buttonConfig.id,
cookie: '',
name: buttonConfig.name,
postId: buttonConfig.id,
buttonColor: buttonConfig.style,
theme: Preferences.THEMES.default,
actions: {
doPostActionWithCookie: jest.fn(),
},
};
const wrapper = shallow(<ActionButton {...baseProps}/>);
const buttonTextChild = wrapper.getElement().props.children;
const baseButtonStyles = wrapper.getElement().props.containerStyle[0];
const dynamicButtonStyles = wrapper.getElement().props.containerStyle[1];
expect(baseButtonStyles.borderColor).toBe(changeOpacity(Preferences.THEMES.default.centerChannelColor, 0.25));
expect(baseButtonStyles.borderWidth).toBe(2);
expect(baseButtonStyles.borderRadius).toBe(4);
expect(dynamicButtonStyles).toBe(undefined);
expect(buttonTextChild.props.style.color).toBe(Preferences.THEMES.default.centerChannelColor);
});
});