2020-10-05 11:09:54 -04:00
|
|
|
import React from 'react';
|
2023-10-24 14:22:28 -04:00
|
|
|
import {mountWithIntl, shallowWithIntl} from '../../helpers/intl-helpers.jsx';
|
2020-10-05 11:09:54 -04:00
|
|
|
import MuteModal from '../../../src/components/modal/mute/modal';
|
|
|
|
import Modal from '../../../src/components/modal/base/modal';
|
|
|
|
|
|
|
|
|
|
|
|
describe('MuteModalTest', () => {
|
2020-12-11 08:45:29 -05:00
|
|
|
const defaultMessages = {
|
2021-01-26 08:42:41 -05:00
|
|
|
commentType: 'comment.type.general',
|
|
|
|
muteStepHeader: 'comment.general.header',
|
|
|
|
muteStepContent: ['comment.general.content1']
|
2020-12-11 08:45:29 -05:00
|
|
|
};
|
2020-10-05 11:09:54 -04:00
|
|
|
|
|
|
|
test('Mute Modal rendering', () => {
|
|
|
|
const component = shallowWithIntl(
|
2020-12-11 08:45:29 -05:00
|
|
|
<MuteModal muteModalMessages={defaultMessages} />
|
|
|
|
).dive();
|
2020-10-05 11:09:54 -04:00
|
|
|
expect(component.find('div.mute-modal-header').exists()).toEqual(true);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Mute Modal only shows next button on initial step', () => {
|
|
|
|
const component = mountWithIntl(
|
2020-12-11 08:45:29 -05:00
|
|
|
<MuteModal muteModalMessages={defaultMessages} />
|
2020-10-05 11:09:54 -04:00
|
|
|
);
|
2020-12-11 08:45:29 -05:00
|
|
|
|
2020-10-05 11:09:54 -04:00
|
|
|
expect(component.find('div.mute-nav').exists()).toEqual(true);
|
|
|
|
expect(component.find('button.next-button').exists()).toEqual(true);
|
|
|
|
expect(component.find('button.next-button').getElements()[0].props.onClick)
|
2020-12-11 08:45:29 -05:00
|
|
|
.toEqual(component.find('MuteModal').instance().handleNext);
|
2020-10-05 11:09:54 -04:00
|
|
|
expect(component.find('button.close-button').exists()).toEqual(false);
|
|
|
|
expect(component.find('button.back-button').exists()).toEqual(false);
|
|
|
|
});
|
|
|
|
|
2020-12-17 15:43:07 -05:00
|
|
|
test('Mute Modal shows extra showWarning step', () => {
|
|
|
|
const component = mountWithIntl(
|
|
|
|
<MuteModal
|
|
|
|
showWarning
|
|
|
|
muteModalMessages={defaultMessages}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
component.find('MuteModal').instance()
|
2021-01-25 17:52:33 -05:00
|
|
|
.setState({step: 1});
|
|
|
|
expect(component.find('button.next-button').exists()).toEqual(true);
|
|
|
|
expect(component.find('button.next-button').getElements()[0].props.onClick)
|
|
|
|
.toEqual(component.find('MuteModal').instance().handleNext);
|
|
|
|
component.find('MuteModal').instance()
|
|
|
|
.handleNext();
|
|
|
|
expect(component.find('MuteModal').instance().state.step).toEqual(2);
|
2020-12-17 15:43:07 -05:00
|
|
|
});
|
|
|
|
|
2020-10-05 11:09:54 -04:00
|
|
|
test('Mute Modal shows back & close button on last step', () => {
|
|
|
|
const component = mountWithIntl(
|
2020-12-11 08:45:29 -05:00
|
|
|
<MuteModal muteModalMessages={defaultMessages} />
|
2020-10-05 11:09:54 -04:00
|
|
|
);
|
|
|
|
// Step 1 is the last step.
|
2020-12-11 08:45:29 -05:00
|
|
|
component.find('MuteModal').instance()
|
|
|
|
.setState({step: 1});
|
2020-10-05 11:09:54 -04:00
|
|
|
component.update();
|
|
|
|
|
|
|
|
expect(component.find('div.mute-nav').exists()).toEqual(true);
|
|
|
|
expect(component.find('button.next-button').exists()).toEqual(false);
|
|
|
|
expect(component.find('button.back-button').exists()).toEqual(true);
|
|
|
|
expect(component.find('button.back-button').getElements()[0].props.onClick)
|
2020-12-11 08:45:29 -05:00
|
|
|
.toEqual(component.find('MuteModal').instance().handlePrevious);
|
2020-10-05 11:09:54 -04:00
|
|
|
expect(component.find('button.close-button').exists()).toEqual(true);
|
|
|
|
expect(component.find('button.close-button').getElements()[0].props.onClick)
|
2020-12-11 08:45:29 -05:00
|
|
|
.toEqual(component.find('MuteModal').instance().props.onRequestClose);
|
2020-10-05 11:09:54 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Mute modal sends correct props to Modal', () => {
|
|
|
|
const closeFn = jest.fn();
|
|
|
|
const component = shallowWithIntl(
|
|
|
|
<MuteModal
|
2020-12-11 08:45:29 -05:00
|
|
|
muteModalMessages={defaultMessages}
|
2020-10-05 11:09:54 -04:00
|
|
|
onRequestClose={closeFn}
|
|
|
|
/>
|
2020-12-11 08:45:29 -05:00
|
|
|
).dive();
|
2020-10-05 11:09:54 -04:00
|
|
|
const modal = component.find(Modal);
|
|
|
|
expect(modal).toHaveLength(1);
|
|
|
|
expect(modal.props().showCloseButton).toBe(false);
|
|
|
|
expect(modal.props().isOpen).toBe(true);
|
|
|
|
expect(modal.props().className).toBe('modal-mute');
|
|
|
|
expect(modal.props().onRequestClose).toBe(closeFn);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Mute modal handle next step', () => {
|
|
|
|
const closeFn = jest.fn();
|
|
|
|
const component = shallowWithIntl(
|
|
|
|
<MuteModal
|
2020-12-11 08:45:29 -05:00
|
|
|
muteModalMessages={defaultMessages}
|
2020-10-05 11:09:54 -04:00
|
|
|
onRequestClose={closeFn}
|
|
|
|
/>
|
2020-12-11 08:45:29 -05:00
|
|
|
).dive();
|
2020-10-05 11:09:54 -04:00
|
|
|
expect(component.instance().state.step).toBe(0);
|
|
|
|
component.instance().handleNext();
|
|
|
|
expect(component.instance().state.step).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Mute modal handle previous step', () => {
|
|
|
|
const component = shallowWithIntl(
|
2020-12-11 08:45:29 -05:00
|
|
|
<MuteModal muteModalMessages={defaultMessages} />
|
|
|
|
).dive();
|
2020-10-05 11:09:54 -04:00
|
|
|
component.instance().setState({step: 1});
|
|
|
|
|
|
|
|
component.instance().handlePrevious();
|
|
|
|
expect(component.instance().state.step).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Mute modal handle previous step stops at 0', () => {
|
|
|
|
const component = shallowWithIntl(
|
2020-12-11 08:45:29 -05:00
|
|
|
<MuteModal muteModalMessages={defaultMessages} />
|
|
|
|
).dive();
|
2020-10-05 11:09:54 -04:00
|
|
|
component.instance().setState({step: 0});
|
|
|
|
component.instance().handlePrevious();
|
|
|
|
expect(component.instance().state.step).toBe(0);
|
|
|
|
});
|
2021-01-25 17:52:33 -05:00
|
|
|
|
2021-02-11 15:44:25 -05:00
|
|
|
test('Mute modal asks for feedback if showFeedback', () => {
|
2021-01-25 17:52:33 -05:00
|
|
|
const component = mountWithIntl(
|
2021-02-11 15:44:25 -05:00
|
|
|
<MuteModal
|
|
|
|
showFeedback
|
|
|
|
muteModalMessages={defaultMessages}
|
|
|
|
/>
|
2021-01-25 17:52:33 -05:00
|
|
|
);
|
|
|
|
component.find('MuteModal').instance()
|
|
|
|
.setState({step: 1});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('p.feedback-prompt').exists()).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2021-02-11 15:44:25 -05:00
|
|
|
test('Mute modal do not ask for feedback if not showFeedback', () => {
|
|
|
|
const component = mountWithIntl(
|
|
|
|
<MuteModal
|
|
|
|
muteModalMessages={defaultMessages}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
component.find('MuteModal').instance()
|
|
|
|
.setState({step: 1});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('p.feedback-prompt').exists()).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Mute modal asks for feedback on extra showWarning step if showFeedback', () => {
|
2021-01-25 17:52:33 -05:00
|
|
|
const component = mountWithIntl(
|
|
|
|
<MuteModal
|
2021-02-11 15:44:25 -05:00
|
|
|
showFeedback
|
2021-01-25 17:52:33 -05:00
|
|
|
showWarning
|
|
|
|
muteModalMessages={defaultMessages}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
component.find('MuteModal').instance()
|
|
|
|
.setState({step: 1});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('p.feedback-prompt').exists()).toEqual(false);
|
|
|
|
component.find('MuteModal').instance()
|
|
|
|
.setState({step: 2});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('p.feedback-prompt').exists()).toEqual(true);
|
|
|
|
});
|
|
|
|
|
2021-03-10 16:07:31 -05:00
|
|
|
test('Mute modal does not for feedback on extra showWarning step if not showFeedback', () => {
|
|
|
|
const component = mountWithIntl(
|
|
|
|
<MuteModal
|
|
|
|
showWarning
|
|
|
|
muteModalMessages={defaultMessages}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
component.find('MuteModal').instance()
|
|
|
|
.setState({step: 1});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('p.feedback-prompt').exists()).toEqual(false);
|
|
|
|
component.find('MuteModal').instance()
|
|
|
|
.setState({step: 2});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('p.feedback-prompt').exists()).toEqual(false);
|
|
|
|
});
|
|
|
|
|
2021-01-25 17:52:33 -05:00
|
|
|
test('Mute modal handle go to feedback', () => {
|
|
|
|
const component = shallowWithIntl(
|
|
|
|
<MuteModal
|
|
|
|
muteModalMessages={defaultMessages}
|
|
|
|
/>
|
|
|
|
).dive();
|
|
|
|
component.instance().handleGoToFeedback();
|
|
|
|
expect(component.instance().state.step).toBe(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Mute modal submit feedback gives thank you step', () => {
|
|
|
|
const component = shallowWithIntl(
|
|
|
|
<MuteModal
|
|
|
|
muteModalMessages={defaultMessages}
|
2021-02-11 15:44:25 -05:00
|
|
|
user={{
|
|
|
|
id: 12345,
|
|
|
|
username: 'myusername',
|
|
|
|
token: 'mytoken',
|
|
|
|
thumbnailUrl: 'mythumbnail'
|
|
|
|
}}
|
2021-01-25 17:52:33 -05:00
|
|
|
/>
|
|
|
|
).dive();
|
2021-02-01 15:50:55 -05:00
|
|
|
component.instance().handleFeedbackSubmit('something');
|
2021-01-25 17:52:33 -05:00
|
|
|
expect(component.instance().state.step).toBe(4);
|
|
|
|
});
|
2020-10-05 11:09:54 -04:00
|
|
|
});
|