mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-30 10:58:23 -05:00
rename SetupMessagePolling to pollForMessages
This commit is contained in:
parent
5de96c373d
commit
7eeb63cb3f
2 changed files with 9 additions and 9 deletions
|
@ -28,7 +28,7 @@ class Navigation extends React.Component {
|
|||
bindAll(this, [
|
||||
'getProfileUrl',
|
||||
'handleSearchSubmit',
|
||||
'setupMessagePolling'
|
||||
'pollForMessages'
|
||||
]);
|
||||
this.state = {
|
||||
messageCountIntervalId: -1 // javascript method interval id for getting messsage count.
|
||||
|
@ -37,14 +37,14 @@ class Navigation extends React.Component {
|
|||
componentDidMount () {
|
||||
if (this.props.user) {
|
||||
// Setup polling for messages to start in 2 minutes.
|
||||
setTimeout(this.setupMessagePolling.bind(this, 2), 2 * 60 * 1000);
|
||||
setTimeout(this.pollForMessages.bind(this, 2), 2 * 60 * 1000);
|
||||
}
|
||||
}
|
||||
componentDidUpdate (prevProps) {
|
||||
if (prevProps.user !== this.props.user) {
|
||||
this.props.handleCloseAccountNav();
|
||||
if (this.props.user) {
|
||||
setTimeout(this.setupMessagePolling.bind(this, 2), 2 * 60 * 1000);
|
||||
setTimeout(this.pollForMessages.bind(this, 2), 2 * 60 * 1000);
|
||||
} else {
|
||||
// clear message count check, and set to default id.
|
||||
clearTimeout(this.state.messageCountIntervalId);
|
||||
|
@ -70,7 +70,7 @@ class Navigation extends React.Component {
|
|||
return `/users/${this.props.user.username}/`;
|
||||
}
|
||||
|
||||
setupMessagePolling (minutes) {
|
||||
pollForMessages (minutes) {
|
||||
this.props.getMessageCount(this.props.user.username);
|
||||
// We only poll if it has been less than 30 minutes.
|
||||
// Chances of someone actively using the page for that long without
|
||||
|
@ -78,7 +78,7 @@ class Navigation extends React.Component {
|
|||
if (minutes < 32) {
|
||||
const nextFetch = minutes * 2;
|
||||
const timeoutId = setTimeout(() => {
|
||||
this.setupMessagePolling(nextFetch);
|
||||
this.pollForMessages(nextFetch);
|
||||
}, nextFetch * 60000);
|
||||
this.setState({ // eslint-disable-line react/no-did-mount-set-state
|
||||
messageCountIntervalId: timeoutId
|
||||
|
|
|
@ -138,7 +138,7 @@ describe('Navigation', () => {
|
|||
expect(props.getMessageCount).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('SetupMessagePolling polls for messages 5 times', () => {
|
||||
test('pollForMessages polls for messages 5 times', () => {
|
||||
store = mockStore({
|
||||
navigation: {
|
||||
registrationOpen: false
|
||||
|
@ -164,11 +164,11 @@ describe('Navigation', () => {
|
|||
const navInstance = intlWrapper.children().find('Navigation')
|
||||
.instance();
|
||||
// Clear the timers and mocks because componentDidMount
|
||||
// has already called setupMessagePolling.
|
||||
// has already called pollForMessages.
|
||||
jest.clearAllTimers();
|
||||
jest.clearAllMocks();
|
||||
|
||||
navInstance.setupMessagePolling(2);
|
||||
navInstance.pollForMessages(2);
|
||||
|
||||
// Check that we set the timeout to backoff exponentially
|
||||
let minutes = 2 * 60 * 1000;
|
||||
|
@ -185,7 +185,7 @@ describe('Navigation', () => {
|
|||
// and stop after 32 minutes so it should happen 5 times total.
|
||||
expect(props.getMessageCount).toHaveBeenCalledTimes(5);
|
||||
// setTimeout happens 1 fewer since the original call to
|
||||
// setupMessagePolling isn't counted here.
|
||||
// pollForMessages isn't counted here.
|
||||
expect(setTimeout).toHaveBeenCalledTimes(4);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue