mattermost-mobile/app/screens/interactive_dialog/dialog_element.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

100 lines
3.3 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 Preferences from '@mm-redux/constants/preferences';
import RadioSetting from 'app/components/widgets/settings/radio_setting';
import BoolSetting from 'app/components/widgets/settings/bool_setting';
import DialogElement from './dialog_element.js';
describe('DialogElement', () => {
const baseDialogProps = {
displayName: 'Testing',
name: 'testing',
type: 'text',
isLandscape: false,
};
const theme = Preferences.THEMES.default;
test('secureTextEntry is true and multiline is false when subtype is password', () => {
const wrapper = shallow(
<DialogElement
{...baseDialogProps}
theme={theme}
subtype='password'
/>,
);
expect(wrapper.find({secureTextEntry: true}).exists()).toBe(true);
expect(wrapper.find({multiline: false}).exists()).toBe(true);
});
test('secureTextEntry is false when subtype is not password', () => {
const wrapper = shallow(
<DialogElement
{...baseDialogProps}
theme={theme}
subtype='email'
/>,
);
expect(wrapper.find({secureTextEntry: false}).exists()).toBe(true);
});
describe('radioSetting', () => {
const radioOptions = [
{value: 'foo', text: 'foo-text'},
{value: 'bar', text: 'bar-text'},
];
test('The default value can be specified from the list', () => {
const wrapper = shallow(
<DialogElement
{...baseDialogProps}
theme={theme}
type='radio'
options={radioOptions}
value={radioOptions[1].value}
/>,
);
expect(wrapper.find(RadioSetting).find({options: radioOptions, default: radioOptions[1].value}).exists()).toBe(true);
});
});
describe('boolSetting', () => {
test('propagates when false', () => {
const wrapper = shallow(
<DialogElement
{...baseDialogProps}
theme={theme}
type='bool'
value={false}
/>,
);
expect(wrapper.find(BoolSetting).find({value: false}).exists()).toBe(true);
});
test('propagates when true', () => {
const wrapper = shallow(
<DialogElement
{...baseDialogProps}
theme={theme}
type='bool'
value={true}
/>,
);
expect(wrapper.find(BoolSetting).find({value: true}).exists()).toBe(true);
});
test('propagates when null', () => {
const wrapper = shallow(
<DialogElement
{...baseDialogProps}
theme={theme}
type='bool'
value={null}
/>,
);
expect(wrapper.find(BoolSetting).find({value: false}).exists()).toBe(true);
});
});
});