2020-11-09 11:01:42 -05:00
|
|
|
const React = require('react');
|
|
|
|
const {shallowWithIntl} = require('../../helpers/intl-helpers.jsx');
|
2020-12-11 14:42:06 -05:00
|
|
|
import {mountWithIntl} from '../../helpers/intl-helpers.jsx';
|
2020-11-09 11:01:42 -05:00
|
|
|
const ComposeComment = require('../../../src/views/preview/comment/compose-comment.jsx');
|
|
|
|
import configureStore from 'redux-mock-store';
|
|
|
|
|
|
|
|
describe('Compose Comment test', () => {
|
|
|
|
const mockStore = configureStore();
|
2020-11-12 14:21:23 -05:00
|
|
|
let _mockFormat;
|
2020-11-09 11:01:42 -05:00
|
|
|
const defaultProps = () =>({
|
|
|
|
user: {
|
|
|
|
thumbnailUrl: 'scratch.mit.edu',
|
|
|
|
username: 'auser'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-12-14 08:45:08 -05:00
|
|
|
let defaultStore;
|
2020-11-09 11:01:42 -05:00
|
|
|
beforeEach(() => {
|
2020-11-30 16:16:52 -05:00
|
|
|
const mockFormat = {
|
|
|
|
format: jest.fn()
|
2020-11-12 14:21:23 -05:00
|
|
|
};
|
|
|
|
_mockFormat = Intl.RelativeTimeFormat = jest
|
|
|
|
.fn()
|
2020-11-30 16:16:52 -05:00
|
|
|
.mockImplementation(() => mockFormat);
|
|
|
|
mockFormat.format.mockReturnValue('');
|
|
|
|
|
2020-12-14 08:45:08 -05:00
|
|
|
defaultStore = mockStore({
|
2020-11-09 11:01:42 -05:00
|
|
|
session: {
|
|
|
|
session: {
|
2020-12-03 15:29:34 -05:00
|
|
|
user: {},
|
|
|
|
permissions: {
|
|
|
|
mute_status: {}
|
|
|
|
}
|
2020-11-09 11:01:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-14 08:45:08 -05:00
|
|
|
const getComposeCommentWrapper = (props, store) => {
|
|
|
|
if (!store) {
|
|
|
|
store = defaultStore;
|
|
|
|
}
|
2020-11-09 11:01:42 -05:00
|
|
|
const wrapper = shallowWithIntl(
|
|
|
|
<ComposeComment
|
|
|
|
{...defaultProps()}
|
|
|
|
{...props}
|
|
|
|
|
|
|
|
/>
|
|
|
|
, {context: {store}}
|
|
|
|
);
|
2020-12-14 08:45:08 -05:00
|
|
|
return wrapper.dive(); // unwrap redux connect(injectIntl(ComposeComment))
|
2020-11-09 11:01:42 -05:00
|
|
|
};
|
|
|
|
|
2021-03-19 15:42:54 -04:00
|
|
|
test('status is EDITING when props do not contain a muteStatus ', () => {
|
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
|
|
|
expect(commentInstance.state.status).toBe('EDITING');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('status is COMPOSE_DISALLOWED when props contain a future mute', () => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
const mutedStore = mockStore({
|
|
|
|
session: {
|
|
|
|
session: {
|
|
|
|
user: {},
|
|
|
|
permissions: {
|
|
|
|
mute_status: {
|
|
|
|
muteExpiresAt: 5,
|
|
|
|
offenses: [],
|
|
|
|
showWarning: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const component = getComposeCommentWrapper({}, mutedStore);
|
|
|
|
const commentInstance = component.instance();
|
|
|
|
|
|
|
|
expect(commentInstance.state.status).toBe('COMPOSE_DISALLOWED');
|
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
|
2020-11-09 11:01:42 -05:00
|
|
|
test('Modal & Comment status do not show ', () => {
|
|
|
|
const component = getComposeCommentWrapper({});
|
|
|
|
// Comment compsoe box is there
|
|
|
|
expect(component.find('FlexRow.compose-comment').exists()).toEqual(true);
|
|
|
|
// No error message
|
|
|
|
expect(component.find('FlexRow.compose-error-row').exists()).toEqual(false);
|
|
|
|
expect(component.find('MuteModal').exists()).toEqual(false);
|
|
|
|
expect(component.find('CommentingStatus').exists()).toEqual(false);
|
2021-01-28 15:07:20 -05:00
|
|
|
// Buttons start enabled
|
|
|
|
expect(component.find('Button.compose-post').props().disabled).toBe(false);
|
|
|
|
expect(component.find('Button.compose-cancel').props().disabled).toBe(false);
|
|
|
|
|
2020-11-09 11:01:42 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Error messages shows when comment rejected ', () => {
|
|
|
|
const component = getComposeCommentWrapper({});
|
|
|
|
const commentInstance = component.instance();
|
2021-03-17 16:07:30 -04:00
|
|
|
commentInstance.setState({
|
|
|
|
error: 'isFlood',
|
|
|
|
status: 'REJECTED'
|
|
|
|
});
|
2020-11-09 11:01:42 -05:00
|
|
|
component.update();
|
|
|
|
expect(component.find('FlexRow.compose-error-row').exists()).toEqual(true);
|
2021-01-28 15:07:20 -05:00
|
|
|
// Buttons stay enabled when comment rejected for non-mute reasons
|
|
|
|
expect(component.find('Button.compose-post').props().disabled).toBe(false);
|
|
|
|
expect(component.find('Button.compose-cancel').props().disabled).toBe(false);
|
2020-11-09 11:01:42 -05:00
|
|
|
});
|
|
|
|
|
2021-03-17 16:07:30 -04:00
|
|
|
test('No error message shows when comment rejected because user is already muted ', () => {
|
2020-11-09 11:01:42 -05:00
|
|
|
const component = getComposeCommentWrapper({});
|
|
|
|
const commentInstance = component.instance();
|
|
|
|
commentInstance.setState({
|
|
|
|
error: 'isMuted',
|
2021-03-17 16:07:30 -04:00
|
|
|
status: 'COMPOSE_DISALLOWED'
|
2020-11-09 11:01:42 -05:00
|
|
|
});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('FlexRow.compose-error-row').exists()).toEqual(false);
|
|
|
|
});
|
|
|
|
|
2021-03-18 16:15:11 -04:00
|
|
|
test('Comment Status shows but compose box does not when you load the page and you are already muted', () => {
|
2020-11-17 17:04:54 -05:00
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
2020-11-09 11:01:42 -05:00
|
|
|
const component = getComposeCommentWrapper({});
|
|
|
|
const commentInstance = component.instance();
|
2021-03-18 16:15:11 -04:00
|
|
|
commentInstance.setState({muteExpiresAtMs: 100, status: 'COMPOSE_DISALLOWED'});
|
2020-11-09 11:01:42 -05:00
|
|
|
component.update();
|
2021-03-18 16:15:11 -04:00
|
|
|
|
2020-12-03 15:29:34 -05:00
|
|
|
// Compose box should be hidden if muted unless they got muted due to a comment they just posted.
|
|
|
|
expect(component.find('FlexRow.compose-comment').exists()).toEqual(false);
|
2020-11-09 11:01:42 -05:00
|
|
|
expect(component.find('MuteModal').exists()).toEqual(false);
|
|
|
|
expect(component.find('CommentingStatus').exists()).toEqual(true);
|
2020-11-17 17:04:54 -05:00
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
2020-12-14 08:45:08 -05:00
|
|
|
|
2021-02-04 11:13:30 -05:00
|
|
|
test('Comment Status and compose box do not show on replies when muted, but mute modal does', () => {
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
const store = mockStore({
|
|
|
|
session: {
|
|
|
|
session: {
|
|
|
|
user: {},
|
|
|
|
permissions: {
|
|
|
|
mute_status: {
|
|
|
|
muteExpiresAt: 5,
|
|
|
|
offenses: [],
|
|
|
|
showWarning: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const component = mountWithIntl(
|
|
|
|
<ComposeComment
|
|
|
|
{...defaultProps()}
|
|
|
|
isReply
|
|
|
|
/>
|
|
|
|
, {context: {store}}
|
|
|
|
);
|
|
|
|
expect(component.find('FlexRow.compose-comment').exists()).toEqual(false);
|
|
|
|
expect(component.find('MuteModal').exists()).toBe(true);
|
|
|
|
expect(component.find('MuteModal').props().startStep).toBe(1);
|
|
|
|
expect(component.find('CommentingStatus').exists()).toEqual(false);
|
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Comment Status and compose box show on replies when not muted', () => {
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
2021-02-05 08:01:33 -05:00
|
|
|
const component = getComposeCommentWrapper({isReply: true});
|
2021-02-04 11:13:30 -05:00
|
|
|
expect(component.find('FlexRow.compose-comment').exists()).toEqual(true);
|
|
|
|
expect(component.find('CommentingStatus').exists()).toEqual(false);
|
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
|
2020-12-14 08:45:08 -05:00
|
|
|
test('Comment Status initialized properly when muted', () => {
|
2020-12-15 14:49:35 -05:00
|
|
|
jest.useFakeTimers();
|
2020-12-14 08:45:08 -05:00
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
const mutedStore = mockStore({
|
|
|
|
session: {
|
|
|
|
session: {
|
|
|
|
user: {},
|
|
|
|
permissions: {
|
|
|
|
mute_status: {
|
|
|
|
muteExpiresAt: 5,
|
2020-12-17 15:43:07 -05:00
|
|
|
offenses: [],
|
|
|
|
showWarning: true
|
2020-12-14 08:45:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const component = getComposeCommentWrapper({}, mutedStore);
|
|
|
|
const commentInstance = component.instance();
|
|
|
|
// Check conversion to ms from seconds is done at init time.
|
|
|
|
expect(commentInstance.state.muteExpiresAtMs).toEqual(5 * 1000);
|
2020-12-15 14:49:35 -05:00
|
|
|
// Check we setup a timeout to expire the widget when timeout reached.
|
|
|
|
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 5 * 1000);
|
2020-12-17 15:43:07 -05:00
|
|
|
expect(commentInstance.state.showWarning).toBe(true);
|
2020-12-14 08:45:08 -05:00
|
|
|
// Compose box should be hidden if muted unless they got muted due to a comment they just posted.
|
|
|
|
expect(component.find('FlexRow.compose-comment').exists()).toEqual(false);
|
|
|
|
expect(component.find('MuteModal').exists()).toEqual(false);
|
|
|
|
expect(component.find('CommentingStatus').exists()).toEqual(true);
|
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
2021-03-19 15:42:54 -04:00
|
|
|
|
2021-02-05 08:16:00 -05:00
|
|
|
test('Comment Status shows when user just submitted a reply comment that got them muted', () => {
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
const component = getComposeCommentWrapper({isReply: true});
|
|
|
|
const commentInstance = component.instance();
|
|
|
|
commentInstance.setState({
|
|
|
|
status: 'REJECTED_MUTE',
|
|
|
|
muteExpiresAtMs: 100
|
|
|
|
});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('FlexRow.compose-comment').exists()).toEqual(true);
|
|
|
|
expect(component.find('MuteModal').exists()).toEqual(false);
|
|
|
|
expect(component.find('CommentingStatus').exists()).toEqual(true);
|
|
|
|
// Compose box exists but is disabled
|
|
|
|
expect(component.find('InplaceInput.compose-input').exists()).toEqual(true);
|
|
|
|
expect(component.find('InplaceInput.compose-input').props().disabled).toBe(true);
|
|
|
|
expect(component.find('Button.compose-post').props().disabled).toBe(true);
|
|
|
|
expect(component.find('Button.compose-cancel').props().disabled).toBe(true);
|
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
|
2020-11-17 17:04:54 -05:00
|
|
|
test('Comment Status shows when user just submitted a comment that got them muted', () => {
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
const component = getComposeCommentWrapper({});
|
|
|
|
const commentInstance = component.instance();
|
|
|
|
commentInstance.setState({
|
|
|
|
status: 'REJECTED_MUTE',
|
2020-12-11 08:14:15 -05:00
|
|
|
muteExpiresAtMs: 100
|
2020-11-17 17:04:54 -05:00
|
|
|
});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('FlexRow.compose-comment').exists()).toEqual(true);
|
|
|
|
expect(component.find('MuteModal').exists()).toEqual(false);
|
|
|
|
expect(component.find('CommentingStatus').exists()).toEqual(true);
|
2020-12-03 15:29:34 -05:00
|
|
|
// Compose box exists but is disabled
|
2020-11-17 17:04:54 -05:00
|
|
|
expect(component.find('InplaceInput.compose-input').exists()).toEqual(true);
|
|
|
|
expect(component.find('InplaceInput.compose-input').props().disabled).toBe(true);
|
2021-01-28 15:07:20 -05:00
|
|
|
expect(component.find('Button.compose-post').props().disabled).toBe(true);
|
|
|
|
expect(component.find('Button.compose-cancel').props().disabled).toBe(true);
|
2020-11-17 17:04:54 -05:00
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
test('Comment Error does not show for mutes', () => {
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
const component = getComposeCommentWrapper({});
|
|
|
|
const commentInstance = component.instance();
|
|
|
|
commentInstance.setState({
|
|
|
|
status: 'REJECTED_MUTE',
|
|
|
|
error: 'a mute error'
|
|
|
|
});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('FlexRow.compose-error-row').exists()).toEqual(false);
|
|
|
|
expect(component.find('FlexRow.compose-comment').exists()).toEqual(true);
|
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
test('Comment Error does show for non-mute errors', () => {
|
|
|
|
const component = getComposeCommentWrapper({});
|
|
|
|
const commentInstance = component.instance();
|
|
|
|
commentInstance.setState({
|
|
|
|
error: 'some error',
|
2021-03-18 16:15:11 -04:00
|
|
|
status: 'REJECTED'
|
2020-11-17 17:04:54 -05:00
|
|
|
});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('FlexRow.compose-error-row').exists()).toEqual(true);
|
|
|
|
expect(component.find('FlexRow.compose-comment').exists()).toEqual(true);
|
|
|
|
expect(component.find('InplaceInput.compose-input').exists()).toEqual(true);
|
|
|
|
expect(component.find('InplaceInput.compose-input').props().disabled).toBe(false);
|
2021-01-28 15:07:20 -05:00
|
|
|
expect(component.find('Button.compose-post').props().disabled).toBe(false);
|
|
|
|
expect(component.find('Button.compose-cancel').props().disabled).toBe(false);
|
2020-11-09 11:01:42 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Mute Modal shows when muteOpen is true ', () => {
|
2020-11-17 17:04:54 -05:00
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
2020-12-14 16:16:09 -05:00
|
|
|
const store = mockStore({
|
|
|
|
session: {
|
|
|
|
session: {
|
|
|
|
user: {},
|
|
|
|
permissions: {
|
|
|
|
mute_status: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-12-11 14:42:06 -05:00
|
|
|
const component = mountWithIntl(
|
|
|
|
<ComposeComment
|
|
|
|
{...defaultProps()}
|
|
|
|
/>
|
2020-12-14 20:07:03 -05:00
|
|
|
, {context: {store}}
|
2020-12-11 14:42:06 -05:00
|
|
|
);
|
|
|
|
// set state on the ComposeComment component, not the wrapper
|
|
|
|
const commentInstance = component.find('ComposeComment').instance();
|
2020-11-09 11:01:42 -05:00
|
|
|
commentInstance.setState({muteOpen: true});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('MuteModal').exists()).toEqual(true);
|
2021-02-04 11:13:30 -05:00
|
|
|
expect(component.find('MuteModal').props().startStep).toEqual(0);
|
2020-12-17 15:43:07 -05:00
|
|
|
expect(component.find('MuteModal').props().showWarning).toBe(false);
|
2020-11-17 17:04:54 -05:00
|
|
|
global.Date.now = realDateNow;
|
2020-11-09 11:01:42 -05:00
|
|
|
});
|
|
|
|
|
2020-12-17 15:43:07 -05:00
|
|
|
test('Mute Modal gets showWarning props from state', () => {
|
|
|
|
const store = mockStore({
|
|
|
|
session: {
|
|
|
|
session: {
|
|
|
|
user: {},
|
|
|
|
permissions: {
|
|
|
|
mute_status: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const component = mountWithIntl(
|
|
|
|
<ComposeComment
|
|
|
|
{...defaultProps()}
|
|
|
|
/>
|
|
|
|
, {context: {store}}
|
|
|
|
);
|
|
|
|
// set state on the ComposeComment component, not the wrapper
|
|
|
|
const commentInstance = component.find('ComposeComment').instance();
|
|
|
|
commentInstance.setState({muteOpen: true});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('MuteModal').exists()).toEqual(true);
|
|
|
|
expect(component.find('MuteModal').props().showWarning).toBe(false);
|
|
|
|
commentInstance.setState({
|
|
|
|
muteOpen: true,
|
|
|
|
showWarning: true
|
|
|
|
});
|
|
|
|
component.update();
|
|
|
|
expect(component.find('MuteModal').props().showWarning).toBe(true);
|
|
|
|
});
|
|
|
|
|
2021-03-10 16:07:31 -05:00
|
|
|
test('Mute Modal gets showFeedback props from state', () => {
|
|
|
|
const store = mockStore({
|
|
|
|
session: {
|
|
|
|
session: {
|
|
|
|
user: {},
|
|
|
|
permissions: {
|
|
|
|
mute_status: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const component = mountWithIntl(
|
|
|
|
<ComposeComment
|
|
|
|
{...defaultProps()}
|
|
|
|
/>
|
|
|
|
, {context: {store}}
|
|
|
|
);
|
|
|
|
|
|
|
|
const commentInstance = component.find('ComposeComment').instance();
|
|
|
|
commentInstance.setState({
|
|
|
|
status: 'REJECTED_MUTE',
|
|
|
|
error: 'isBad',
|
|
|
|
muteOpen: true
|
|
|
|
});
|
|
|
|
|
|
|
|
component.update();
|
|
|
|
expect(component.find('MuteModal').exists()).toEqual(true);
|
|
|
|
expect(component.find('MuteModal').props().showFeedback).toBe(true);
|
|
|
|
|
|
|
|
commentInstance.setState({
|
2021-03-18 16:15:11 -04:00
|
|
|
status: 'COMPOSE_DISALLOWED',
|
2021-03-10 16:07:31 -05:00
|
|
|
error: 'isMute',
|
|
|
|
showWarning: true,
|
|
|
|
muteOpen: true
|
|
|
|
});
|
|
|
|
|
|
|
|
component.update();
|
|
|
|
expect(component.find('MuteModal').exists()).toEqual(true);
|
|
|
|
expect(component.find('MuteModal').props().showFeedback).toBe(false);
|
|
|
|
|
|
|
|
commentInstance.setState({
|
|
|
|
status: 'REJECTED',
|
|
|
|
error: 'isBad',
|
|
|
|
showWarning: true,
|
|
|
|
muteOpen: true
|
|
|
|
});
|
|
|
|
|
|
|
|
component.update();
|
|
|
|
expect(component.find('MuteModal').exists()).toEqual(true);
|
|
|
|
expect(component.find('MuteModal').props().showFeedback).toBe(false);
|
|
|
|
});
|
2020-12-18 09:30:02 -05:00
|
|
|
test('shouldShowMuteModal is false when muteStatus is undefined ', () => {
|
2020-11-09 11:01:42 -05:00
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
|
|
|
expect(commentInstance.shouldShowMuteModal()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-12-18 09:30:02 -05:00
|
|
|
test('shouldShowMuteModal is false when list is undefined ', () => {
|
|
|
|
const muteStatus = {};
|
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
|
|
|
expect(commentInstance.shouldShowMuteModal(muteStatus)).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-11-09 11:01:42 -05:00
|
|
|
test('shouldShowMuteModal is false when list empty ', () => {
|
2020-12-18 09:30:02 -05:00
|
|
|
const muteStatus = {
|
|
|
|
offenses: []
|
|
|
|
};
|
2020-11-09 11:01:42 -05:00
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
2020-12-18 09:30:02 -05:00
|
|
|
expect(commentInstance.shouldShowMuteModal(muteStatus)).toBe(false);
|
2020-11-09 11:01:42 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('shouldShowMuteModal is true when only 1 recent offesnse ', () => {
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
// Since Date.now mocked to 0 above, we just need a small number to make
|
|
|
|
// it look like it was created < 2 minutes ago.
|
|
|
|
const offense = {
|
|
|
|
expiresAt: '1000',
|
|
|
|
createdAt: '-60' // ~1 ago min given shouldShowMuteModal's conversions,
|
|
|
|
};
|
2020-12-18 09:30:02 -05:00
|
|
|
const muteStatus = {
|
|
|
|
offenses: [offense]
|
|
|
|
};
|
2020-11-09 11:01:42 -05:00
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
2021-03-18 16:15:11 -04:00
|
|
|
expect(commentInstance.shouldShowMuteModal(muteStatus, true)).toBe(true);
|
2020-11-09 11:01:42 -05:00
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('shouldShowMuteModal is false when multiple offenses, even if 1 is recent ', () => {
|
|
|
|
const offenses = [];
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
// Since Date.now mocked to 0 above, we just need a small number to make
|
|
|
|
// it look like it was created more than 2 minutes ago.
|
|
|
|
let offense = {
|
|
|
|
expiresAt: '1000',
|
|
|
|
createdAt: '-119' // just shy of two min ago
|
|
|
|
};
|
|
|
|
offenses.push(offense);
|
|
|
|
offense.createdAt = '-180'; // 3 minutes ago;
|
|
|
|
offenses.push(offense);
|
2020-12-18 09:30:02 -05:00
|
|
|
const muteStatus = {
|
|
|
|
offenses: offenses
|
|
|
|
};
|
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
2021-03-18 16:15:11 -04:00
|
|
|
expect(commentInstance.shouldShowMuteModal(muteStatus, true)).toBe(false);
|
2020-12-18 09:30:02 -05:00
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('shouldShowMuteModal is true when showWarning is true even with multiple offenses', () => {
|
|
|
|
const offenses = [];
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
// Since Date.now mocked to 0 above, we just need a small number to make
|
|
|
|
// it look like it was created more than 2 minutes ago.
|
|
|
|
let offense = {
|
|
|
|
expiresAt: '1000',
|
|
|
|
createdAt: '-119' // just shy of two min ago
|
|
|
|
};
|
|
|
|
offenses.push(offense);
|
|
|
|
offense.createdAt = '-180'; // 3 minutes ago;
|
|
|
|
offenses.push(offense);
|
|
|
|
const muteStatus = {
|
|
|
|
offenses: offenses,
|
|
|
|
showWarning: true
|
|
|
|
};
|
2020-11-09 11:01:42 -05:00
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
2021-03-18 16:15:11 -04:00
|
|
|
expect(commentInstance.shouldShowMuteModal(muteStatus, true)).toBe(true);
|
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('shouldShowMuteModal is false when the user is already muted, even when only 1 recent offesnse ', () => {
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
// Since Date.now mocked to 0 above, we just need a small number to make
|
|
|
|
// it look like it was created < 2 minutes ago.
|
|
|
|
const offense = {
|
|
|
|
expiresAt: '1000',
|
|
|
|
createdAt: '-60' // ~1 ago min given shouldShowMuteModal's conversions,
|
|
|
|
};
|
|
|
|
const muteStatus = {
|
|
|
|
offenses: [offense]
|
|
|
|
};
|
|
|
|
const justMuted = false;
|
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
|
|
|
expect(commentInstance.shouldShowMuteModal(muteStatus, justMuted)).toBe(false);
|
2020-11-09 11:01:42 -05:00
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
|
2021-03-19 15:29:29 -04:00
|
|
|
test('shouldShowMuteModal is true when the user is already muted if the comment is a reply', () => {
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
// Since Date.now mocked to 0 above, we just need a small number to make
|
|
|
|
// it look like it was created < 2 minutes ago.
|
|
|
|
const offense = {
|
|
|
|
expiresAt: '1000',
|
|
|
|
createdAt: '-60' // ~1 ago min given shouldShowMuteModal's conversions,
|
|
|
|
};
|
|
|
|
const muteStatus = {
|
|
|
|
offenses: [offense]
|
|
|
|
};
|
|
|
|
const justMuted = false;
|
|
|
|
const commentInstance = getComposeCommentWrapper({isReply: true}).instance();
|
|
|
|
expect(commentInstance.shouldShowMuteModal(muteStatus, justMuted)).toBe(true);
|
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('getMuteModalStartStep: not a reply', () => {
|
2021-02-05 08:01:33 -05:00
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
|
|
|
expect(commentInstance.getMuteModalStartStep()).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('getMuteModalStartStep: A reply that got them muted ', () => {
|
|
|
|
const commentInstance = getComposeCommentWrapper({isReply: true}).instance();
|
|
|
|
commentInstance.setState({
|
|
|
|
status: 'REJECTED_MUTE'
|
|
|
|
});
|
|
|
|
expect(commentInstance.getMuteModalStartStep()).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('getMuteModalStartStep: A reply click when already muted ', () => {
|
|
|
|
const commentInstance = getComposeCommentWrapper({isReply: true}).instance();
|
|
|
|
commentInstance.setState({
|
2021-03-18 16:15:11 -04:00
|
|
|
status: 'COMPOSE_DISALLOWED'
|
2021-02-05 08:01:33 -05:00
|
|
|
});
|
|
|
|
expect(commentInstance.getMuteModalStartStep()).toBe(1);
|
|
|
|
});
|
|
|
|
|
2020-11-17 17:04:54 -05:00
|
|
|
test('isMuted: expiration is in the future ', () => {
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0; // Set "now" to 0 for easier testing.
|
|
|
|
|
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
2020-12-11 08:14:15 -05:00
|
|
|
commentInstance.setState({muteExpiresAtMs: 100});
|
2020-11-17 17:04:54 -05:00
|
|
|
expect(commentInstance.isMuted()).toBe(true);
|
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('isMuted: expiration is in the past ', () => {
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
|
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
2020-12-11 08:14:15 -05:00
|
|
|
commentInstance.setState({muteExpiresAtMs: -100});
|
2020-11-17 17:04:54 -05:00
|
|
|
expect(commentInstance.isMuted()).toBe(false);
|
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('isMuted: expiration is not set ', () => {
|
|
|
|
const realDateNow = Date.now.bind(global.Date);
|
|
|
|
global.Date.now = () => 0;
|
|
|
|
|
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
|
|
|
expect(commentInstance.isMuted()).toBe(false);
|
|
|
|
global.Date.now = realDateNow;
|
|
|
|
});
|
2021-01-07 14:04:48 -05:00
|
|
|
|
2021-03-23 11:00:01 -04:00
|
|
|
test('getMuteMessageInfo: muteType set and just got muted', () => {
|
2021-03-23 16:33:24 -04:00
|
|
|
const justMuted = true;
|
2021-01-07 14:04:48 -05:00
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
|
|
|
commentInstance.setState({muteType: 'unconstructive'});
|
2021-03-23 16:33:24 -04:00
|
|
|
expect(commentInstance.getMuteMessageInfo(justMuted).commentType).toBe('comment.type.unconstructive');
|
|
|
|
expect(commentInstance.getMuteMessageInfo(justMuted)
|
|
|
|
.muteStepContent[0]).toBe('comment.unconstructive.content1');
|
2021-01-07 14:04:48 -05:00
|
|
|
});
|
|
|
|
|
2021-03-23 11:00:01 -04:00
|
|
|
test('getMuteMessageInfo: muteType set and already muted', () => {
|
2021-03-23 16:33:24 -04:00
|
|
|
const justMuted = false;
|
2021-01-07 14:04:48 -05:00
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
2021-03-23 11:00:01 -04:00
|
|
|
commentInstance.setState({muteType: 'pii'});
|
2021-03-23 16:33:24 -04:00
|
|
|
expect(commentInstance.getMuteMessageInfo(justMuted).commentType).toBe('comment.type.pii.past');
|
2021-03-23 11:00:01 -04:00
|
|
|
// PII has the same content1 regardless of whether you were just muted
|
2021-03-23 16:33:24 -04:00
|
|
|
expect(commentInstance.getMuteMessageInfo(justMuted).muteStepContent[0]).toBe('comment.pii.content1');
|
2021-03-23 11:00:01 -04:00
|
|
|
|
|
|
|
commentInstance.setState({muteType: 'vulgarity'});
|
2021-03-23 16:33:24 -04:00
|
|
|
expect(commentInstance.getMuteMessageInfo(justMuted).commentType).toBe('comment.type.vulgarity.past');
|
|
|
|
expect(commentInstance.getMuteMessageInfo(justMuted).muteStepContent[0]).toBe('comment.type.vulgarity.past');
|
2021-03-23 11:00:01 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('getMuteMessageInfo: muteType not set and just got muted', () => {
|
2021-03-23 16:33:24 -04:00
|
|
|
const justMuted = true;
|
2021-03-23 11:00:01 -04:00
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
2021-03-23 16:33:24 -04:00
|
|
|
expect(commentInstance.getMuteMessageInfo(justMuted).commentType).toBe('comment.type.general');
|
2021-03-23 11:00:01 -04:00
|
|
|
// general has the same content1 regardless of whether you were just muted
|
2021-03-23 16:33:24 -04:00
|
|
|
expect(commentInstance.getMuteMessageInfo(justMuted).muteStepContent[0]).toBe('comment.general.content1');
|
2021-03-23 11:00:01 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('getMuteMessageInfo: muteType not set and already muted', () => {
|
2021-03-23 16:33:24 -04:00
|
|
|
const justMuted = false;
|
2021-03-23 11:00:01 -04:00
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
2021-03-23 16:33:24 -04:00
|
|
|
expect(commentInstance.getMuteMessageInfo(justMuted).commentType).toBe('comment.type.general.past');
|
2021-03-23 11:00:01 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('getMuteMessageInfo: muteType set to something we don\'t have messages for and just got muted', () => {
|
2021-03-23 16:33:24 -04:00
|
|
|
const justMuted = true;
|
2021-03-23 11:00:01 -04:00
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
|
|
|
commentInstance.setState({muteType: 'spaghetti'});
|
2021-03-23 16:33:24 -04:00
|
|
|
expect(commentInstance.getMuteMessageInfo(justMuted).commentType).toBe('comment.type.general');
|
2021-01-07 14:04:48 -05:00
|
|
|
});
|
|
|
|
|
2021-03-23 11:00:01 -04:00
|
|
|
test('getMuteMessageInfo: muteType set to something we don\'t have messages for and already muted', () => {
|
2021-03-23 16:33:24 -04:00
|
|
|
const justMuted = false;
|
2021-01-07 14:04:48 -05:00
|
|
|
const commentInstance = getComposeCommentWrapper({}).instance();
|
|
|
|
commentInstance.setState({muteType: 'spaghetti'});
|
2021-03-23 16:33:24 -04:00
|
|
|
expect(commentInstance.getMuteMessageInfo(justMuted).commentType).toBe('comment.type.general.past');
|
2021-01-07 14:04:48 -05:00
|
|
|
});
|
2020-11-09 11:01:42 -05:00
|
|
|
});
|