Unverified Commit 8b1b8de6 authored by picklesrus's avatar picklesrus Committed by GitHub

Merge pull request #4875 from LLK/develop

Merge develop into release
parents ad9d5b00 080f0def
This diff is collapsed.
...@@ -40,19 +40,31 @@ class ComposeComment extends React.Component { ...@@ -40,19 +40,31 @@ class ComposeComment extends React.Component {
'handleInput', 'handleInput',
'handleMuteClose', 'handleMuteClose',
'handleMuteOpen', 'handleMuteOpen',
'isMuted' 'isMuted',
'setupMuteExpirationTimeout'
]); ]);
const muteExpiresAtMs = this.props.muteStatus.muteExpiresAt ?
this.props.muteStatus.muteExpiresAt * 1000 : 0; // convert to ms
this.state = { this.state = {
message: '', message: '',
status: ComposeStatus.EDITING, status: ComposeStatus.EDITING,
error: null, error: null,
appealId: null, appealId: null,
muteOpen: false, muteOpen: false,
muteExpiresAtMs: this.props.muteStatus.muteExpiresAt ? muteExpiresAtMs: muteExpiresAtMs,
this.props.muteStatus.muteExpiresAt * 1000 : 0, // convert to ms
muteType: this.props.muteStatus.currentMessageType, muteType: this.props.muteStatus.currentMessageType,
showWarning: this.props.muteStatus.showWarning ? this.props.muteStatus.showWarning : false showWarning: this.props.muteStatus.showWarning ? this.props.muteStatus.showWarning : false
}; };
if (this.isMuted()) {
this.setupMuteExpirationTimeout(muteExpiresAtMs);
}
}
setupMuteExpirationTimeout (muteExpiresAtMs) {
// Change state when the mute expiration fires if the user is still on the page.
setTimeout(() => {
this.setState(
{message: '', muteExpiresAtMs: 0, muteOpen: false, status: ComposeStatus.EDITING, error: null});
}, muteExpiresAtMs - Date.now());
} }
handleInput (event) { handleInput (event) {
this.setState({ this.setState({
...@@ -93,6 +105,7 @@ class ComposeComment extends React.Component { ...@@ -93,6 +105,7 @@ class ComposeComment extends React.Component {
} }
showWarning = body.status.mute_status.showWarning; showWarning = body.status.mute_status.showWarning;
muteType = body.status.mute_status.muteType; muteType = body.status.mute_status.muteType;
this.setupMuteExpirationTimeout(muteExpiresAtMs);
} }
// Note: does not reset the message state // Note: does not reset the message state
this.setState({ this.setState({
......
...@@ -95,6 +95,7 @@ describe('Compose Comment test', () => { ...@@ -95,6 +95,7 @@ describe('Compose Comment test', () => {
}); });
test('Comment Status initialized properly when muted', () => { test('Comment Status initialized properly when muted', () => {
jest.useFakeTimers();
const realDateNow = Date.now.bind(global.Date); const realDateNow = Date.now.bind(global.Date);
global.Date.now = () => 0; global.Date.now = () => 0;
const mutedStore = mockStore({ const mutedStore = mockStore({
...@@ -115,6 +116,8 @@ describe('Compose Comment test', () => { ...@@ -115,6 +116,8 @@ describe('Compose Comment test', () => {
const commentInstance = component.instance(); const commentInstance = component.instance();
// Check conversion to ms from seconds is done at init time. // Check conversion to ms from seconds is done at init time.
expect(commentInstance.state.muteExpiresAtMs).toEqual(5 * 1000); expect(commentInstance.state.muteExpiresAtMs).toEqual(5 * 1000);
// Check we setup a timeout to expire the widget when timeout reached.
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 5 * 1000);
expect(commentInstance.state.showWarning).toBe(true); expect(commentInstance.state.showWarning).toBe(true);
// Compose box should be hidden if muted unless they got muted due to a comment they just posted. // 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('FlexRow.compose-comment').exists()).toEqual(false);
......
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