Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
67f4408d
Commit
67f4408d
authored
Oct 10, 2017
by
Filipa Lacerda
Committed by
Phil Hughes
Oct 10, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bad type checking to prevent 0 count badge to be shown
parent
d6170ce4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
52 deletions
+69
-52
app/assets/javascripts/header.js
app/assets/javascripts/header.js
+14
-5
app/assets/javascripts/lib/utils/text_utility.js
app/assets/javascripts/lib/utils/text_utility.js
+11
-3
changelogs/unreleased/34841-todos.yml
changelogs/unreleased/34841-todos.yml
+5
-0
spec/javascripts/header_spec.js
spec/javascripts/header_spec.js
+34
-39
spec/javascripts/lib/utils/text_utility_spec.js
spec/javascripts/lib/utils/text_utility_spec.js
+5
-5
No files found.
app/assets/javascripts/header.js
View file @
67f4408d
/* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, no-var */
import
{
highCountTrim
}
from
'
~/lib/utils/text_utility
'
;
$
(
document
).
on
(
'
todo:toggle
'
,
function
(
e
,
count
)
{
/**
var
$todoPendingCount
=
$
(
'
.todos-count
'
);
* Updates todo counter when todos are toggled.
$todoPendingCount
.
text
(
gl
.
text
.
highCountTrim
(
count
));
* When count is 0, we hide the badge.
$todoPendingCount
.
toggleClass
(
'
hidden
'
,
count
===
0
);
*
* @param {jQuery.Event} e
* @param {String} count
*/
$
(
document
).
on
(
'
todo:toggle
'
,
(
e
,
count
)
=>
{
const
parsedCount
=
parseInt
(
count
,
10
);
const
$todoPendingCount
=
$
(
'
.todos-count
'
);
$todoPendingCount
.
text
(
highCountTrim
(
parsedCount
));
$todoPendingCount
.
toggleClass
(
'
hidden
'
,
parsedCount
===
0
);
});
});
app/assets/javascripts/lib/utils/text_utility.js
View file @
67f4408d
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, no-param-reassign, no-cond-assign, quotes, one-var, one-var-declaration-per-line, operator-assignment, no-else-return, prefer-template, prefer-arrow-callback, no-empty, max-len, consistent-return, no-unused-vars, no-return-assign, max-len, vars-on-top */
/* eslint-disable
import/prefer-default-export,
func-names, space-before-function-paren, wrap-iife, no-var, no-param-reassign, no-cond-assign, quotes, one-var, one-var-declaration-per-line, operator-assignment, no-else-return, prefer-template, prefer-arrow-callback, no-empty, max-len, consistent-return, no-unused-vars, no-return-assign, max-len, vars-on-top */
import
'
vendor/latinise
'
;
import
'
vendor/latinise
'
;
...
@@ -13,9 +13,17 @@ if ((base = w.gl).text == null) {
...
@@ -13,9 +13,17 @@ if ((base = w.gl).text == null) {
gl
.
text
.
addDelimiter
=
function
(
text
)
{
gl
.
text
.
addDelimiter
=
function
(
text
)
{
return
text
?
text
.
toString
().
replace
(
/
\B(?=(\d{3})
+
(?!\d))
/g
,
"
,
"
)
:
text
;
return
text
?
text
.
toString
().
replace
(
/
\B(?=(\d{3})
+
(?!\d))
/g
,
"
,
"
)
:
text
;
};
};
gl
.
text
.
highCountTrim
=
function
(
count
)
{
/**
* Returns '99+' for numbers bigger than 99.
*
* @param {Number} count
* @return {Number|String}
*/
export
function
highCountTrim
(
count
)
{
return
count
>
99
?
'
99+
'
:
count
;
return
count
>
99
?
'
99+
'
:
count
;
};
}
gl
.
text
.
randomString
=
function
()
{
gl
.
text
.
randomString
=
function
()
{
return
Math
.
random
().
toString
(
36
).
substring
(
7
);
return
Math
.
random
().
toString
(
36
).
substring
(
7
);
};
};
...
...
changelogs/unreleased/34841-todos.yml
0 → 100644
View file @
67f4408d
---
title
:
Fix bad type checking to prevent 0 count badge to be shown
merge_request
:
author
:
type
:
fixed
spec/javascripts/header_spec.js
View file @
67f4408d
/* eslint-disable space-before-function-paren, no-var */
import
'
~/header
'
;
import
'
~/header
'
;
import
'
~/lib/utils/text_utility
'
;
(
function
()
{
describe
(
'
Header
'
,
function
()
{
describe
(
'
Header
'
,
function
()
{
const
todosPendingCount
=
'
.todos-count
'
;
var
todosPendingCount
=
'
.todos-count
'
;
const
fixtureTemplate
=
'
issues/open-issue.html.raw
'
;
var
fixtureTemplate
=
'
issues/open-issue.html.raw
'
;
function
isTodosCountHidden
()
{
function
isTodosCountHidden
()
{
return
$
(
todosPendingCount
).
hasClass
(
'
hidden
'
);
return
$
(
todosPendingCount
).
hasClass
(
'
hidden
'
);
}
}
function
triggerToggle
(
newCount
)
{
function
triggerToggle
(
newCount
)
{
$
(
document
).
trigger
(
'
todo:toggle
'
,
newCount
);
$
(
document
).
trigger
(
'
todo:toggle
'
,
newCount
);
}
}
preloadFixtures
(
fixtureTemplate
);
preloadFixtures
(
fixtureTemplate
);
beforeEach
(
function
()
{
beforeEach
(()
=>
{
loadFixtures
(
fixtureTemplate
);
loadFixtures
(
fixtureTemplate
);
});
});
it
(
'
should update todos-count after receiving the todo:toggle event
'
,
function
()
{
it
(
'
should update todos-count after receiving the todo:toggle event
'
,
()
=>
{
triggerToggle
(
5
);
triggerToggle
(
'
5
'
);
expect
(
$
(
todosPendingCount
).
text
()).
toEqual
(
'
5
'
);
expect
(
$
(
todosPendingCount
).
text
()).
toEqual
(
'
5
'
);
});
});
it
(
'
should hide todos-count when it is 0
'
,
function
()
{
it
(
'
should hide todos-count when it is 0
'
,
()
=>
{
triggerToggle
(
0
);
triggerToggle
(
'
0
'
);
expect
(
isTodosCountHidden
()).
toEqual
(
true
);
expect
(
isTodosCountHidden
()).
toEqual
(
true
);
});
it
(
'
should show todos-count when it is more than 0
'
,
()
=>
{
triggerToggle
(
'
10
'
);
expect
(
isTodosCountHidden
()).
toEqual
(
false
);
});
describe
(
'
when todos-count is 1000
'
,
()
=>
{
beforeEach
(()
=>
{
triggerToggle
(
'
1000
'
);
});
});
it
(
'
should show todos-count when it is more than 0
'
,
function
()
{
it
(
'
should show todos-count
'
,
()
=>
{
triggerToggle
(
10
);
expect
(
isTodosCountHidden
()).
toEqual
(
false
);
expect
(
isTodosCountHidden
()).
toEqual
(
false
);
});
});
describe
(
'
when todos-count is 1000
'
,
function
()
{
it
(
'
should show 99+ for todos-count
'
,
()
=>
{
beforeEach
(
function
()
{
expect
(
$
(
todosPendingCount
).
text
()).
toEqual
(
'
99+
'
);
triggerToggle
(
1000
);
});
it
(
'
should show todos-count
'
,
function
()
{
expect
(
isTodosCountHidden
()).
toEqual
(
false
);
});
it
(
'
should show 99+ for todos-count
'
,
function
()
{
expect
(
$
(
todosPendingCount
).
text
()).
toEqual
(
'
99+
'
);
});
});
});
});
});
})
.
call
(
window
)
;
});
spec/javascripts/lib/utils/text_utility_spec.js
View file @
67f4408d
import
'
~/lib/utils/text_utility
'
;
import
{
highCountTrim
}
from
'
~/lib/utils/text_utility
'
;
describe
(
'
text_utility
'
,
()
=>
{
describe
(
'
text_utility
'
,
()
=>
{
describe
(
'
gl.text.getTextWidth
'
,
()
=>
{
describe
(
'
gl.text.getTextWidth
'
,
()
=>
{
...
@@ -35,14 +35,14 @@ describe('text_utility', () => {
...
@@ -35,14 +35,14 @@ describe('text_utility', () => {
});
});
});
});
describe
(
'
gl.text.
highCountTrim
'
,
()
=>
{
describe
(
'
highCountTrim
'
,
()
=>
{
it
(
'
returns 99+ for count >= 100
'
,
()
=>
{
it
(
'
returns 99+ for count >= 100
'
,
()
=>
{
expect
(
gl
.
text
.
highCountTrim
(
105
)).
toBe
(
'
99+
'
);
expect
(
highCountTrim
(
105
)).
toBe
(
'
99+
'
);
expect
(
gl
.
text
.
highCountTrim
(
100
)).
toBe
(
'
99+
'
);
expect
(
highCountTrim
(
100
)).
toBe
(
'
99+
'
);
});
});
it
(
'
returns exact number for count < 100
'
,
()
=>
{
it
(
'
returns exact number for count < 100
'
,
()
=>
{
expect
(
gl
.
text
.
highCountTrim
(
45
)).
toBe
(
45
);
expect
(
highCountTrim
(
45
)).
toBe
(
45
);
});
});
});
});
...
...
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