Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
7eeb63cb
Commit
7eeb63cb
authored
Jul 16, 2020
by
picklesrus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename SetupMessagePolling to pollForMessages
parent
5de96c37
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
9 deletions
+9
-9
src/components/navigation/www/navigation.jsx
src/components/navigation/www/navigation.jsx
+5
-5
test/unit/components/navigation.test.jsx
test/unit/components/navigation.test.jsx
+4
-4
No files found.
src/components/navigation/www/navigation.jsx
View file @
7eeb63cb
...
@@ -28,7 +28,7 @@ class Navigation extends React.Component {
...
@@ -28,7 +28,7 @@ class Navigation extends React.Component {
bindAll
(
this
,
[
bindAll
(
this
,
[
'
getProfileUrl
'
,
'
getProfileUrl
'
,
'
handleSearchSubmit
'
,
'
handleSearchSubmit
'
,
'
setupMessagePolling
'
'
pollForMessages
'
]);
]);
this
.
state
=
{
this
.
state
=
{
messageCountIntervalId
:
-
1
// javascript method interval id for getting messsage count.
messageCountIntervalId
:
-
1
// javascript method interval id for getting messsage count.
...
@@ -37,14 +37,14 @@ class Navigation extends React.Component {
...
@@ -37,14 +37,14 @@ class Navigation extends React.Component {
componentDidMount
()
{
componentDidMount
()
{
if
(
this
.
props
.
user
)
{
if
(
this
.
props
.
user
)
{
// Setup polling for messages to start in 2 minutes.
// 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
)
{
componentDidUpdate
(
prevProps
)
{
if
(
prevProps
.
user
!==
this
.
props
.
user
)
{
if
(
prevProps
.
user
!==
this
.
props
.
user
)
{
this
.
props
.
handleCloseAccountNav
();
this
.
props
.
handleCloseAccountNav
();
if
(
this
.
props
.
user
)
{
if
(
this
.
props
.
user
)
{
setTimeout
(
this
.
setupMessagePolling
.
bind
(
this
,
2
),
2
*
60
*
1000
);
setTimeout
(
this
.
pollForMessages
.
bind
(
this
,
2
),
2
*
60
*
1000
);
}
else
{
}
else
{
// clear message count check, and set to default id.
// clear message count check, and set to default id.
clearTimeout
(
this
.
state
.
messageCountIntervalId
);
clearTimeout
(
this
.
state
.
messageCountIntervalId
);
...
@@ -70,7 +70,7 @@ class Navigation extends React.Component {
...
@@ -70,7 +70,7 @@ class Navigation extends React.Component {
return
`/users/
${
this
.
props
.
user
.
username
}
/`
;
return
`/users/
${
this
.
props
.
user
.
username
}
/`
;
}
}
setupMessagePolling
(
minutes
)
{
pollForMessages
(
minutes
)
{
this
.
props
.
getMessageCount
(
this
.
props
.
user
.
username
);
this
.
props
.
getMessageCount
(
this
.
props
.
user
.
username
);
// We only poll if it has been less than 30 minutes.
// We only poll if it has been less than 30 minutes.
// Chances of someone actively using the page for that long without
// Chances of someone actively using the page for that long without
...
@@ -78,7 +78,7 @@ class Navigation extends React.Component {
...
@@ -78,7 +78,7 @@ class Navigation extends React.Component {
if
(
minutes
<
32
)
{
if
(
minutes
<
32
)
{
const
nextFetch
=
minutes
*
2
;
const
nextFetch
=
minutes
*
2
;
const
timeoutId
=
setTimeout
(()
=>
{
const
timeoutId
=
setTimeout
(()
=>
{
this
.
setupMessagePolling
(
nextFetch
);
this
.
pollForMessages
(
nextFetch
);
},
nextFetch
*
60000
);
},
nextFetch
*
60000
);
this
.
setState
({
// eslint-disable-line react/no-did-mount-set-state
this
.
setState
({
// eslint-disable-line react/no-did-mount-set-state
messageCountIntervalId
:
timeoutId
messageCountIntervalId
:
timeoutId
...
...
test/unit/components/navigation.test.jsx
View file @
7eeb63cb
...
@@ -138,7 +138,7 @@ describe('Navigation', () => {
...
@@ -138,7 +138,7 @@ describe('Navigation', () => {
expect
(
props
.
getMessageCount
).
toHaveBeenCalled
();
expect
(
props
.
getMessageCount
).
toHaveBeenCalled
();
});
});
test
(
'
SetupMessagePolling
polls for messages 5 times
'
,
()
=>
{
test
(
'
pollForMessages
polls for messages 5 times
'
,
()
=>
{
store
=
mockStore
({
store
=
mockStore
({
navigation
:
{
navigation
:
{
registrationOpen
:
false
registrationOpen
:
false
...
@@ -164,11 +164,11 @@ describe('Navigation', () => {
...
@@ -164,11 +164,11 @@ describe('Navigation', () => {
const
navInstance
=
intlWrapper
.
children
().
find
(
'
Navigation
'
)
const
navInstance
=
intlWrapper
.
children
().
find
(
'
Navigation
'
)
.
instance
();
.
instance
();
// Clear the timers and mocks because componentDidMount
// Clear the timers and mocks because componentDidMount
// has already called
setupMessagePolling
.
// has already called
pollForMessages
.
jest
.
clearAllTimers
();
jest
.
clearAllTimers
();
jest
.
clearAllMocks
();
jest
.
clearAllMocks
();
navInstance
.
setupMessagePolling
(
2
);
navInstance
.
pollForMessages
(
2
);
// Check that we set the timeout to backoff exponentially
// Check that we set the timeout to backoff exponentially
let
minutes
=
2
*
60
*
1000
;
let
minutes
=
2
*
60
*
1000
;
...
@@ -185,7 +185,7 @@ describe('Navigation', () => {
...
@@ -185,7 +185,7 @@ describe('Navigation', () => {
// and stop after 32 minutes so it should happen 5 times total.
// and stop after 32 minutes so it should happen 5 times total.
expect
(
props
.
getMessageCount
).
toHaveBeenCalledTimes
(
5
);
expect
(
props
.
getMessageCount
).
toHaveBeenCalledTimes
(
5
);
// setTimeout happens 1 fewer since the original call to
// setTimeout happens 1 fewer since the original call to
//
setupMessagePolling
isn't counted here.
//
pollForMessages
isn't counted here.
expect
(
setTimeout
).
toHaveBeenCalledTimes
(
4
);
expect
(
setTimeout
).
toHaveBeenCalledTimes
(
4
);
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment