Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
67f4408d
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
67f4408d
编写于
10月 10, 2017
作者:
F
Filipa Lacerda
提交者:
Phil Hughes
10月 10, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bad type checking to prevent 0 count badge to be shown
上级
d6170ce4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
69 addition
and
52 deletion
+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
未找到文件。
app/assets/javascripts/header.js
浏览文件 @
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
'
);
$todoPendingCount
.
text
(
gl
.
text
.
highCountTrim
(
count
));
$todoPendingCount
.
toggleClass
(
'
hidden
'
,
count
===
0
);
/**
* Updates todo counter when todos are toggled.
* When count is 0, we hide the badge.
*
* @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
浏览文件 @
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
'
;
...
...
@@ -13,9 +13,17 @@ if ((base = w.gl).text == null) {
gl
.
text
.
addDelimiter
=
function
(
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
;
};
}
gl
.
text
.
randomString
=
function
()
{
return
Math
.
random
().
toString
(
36
).
substring
(
7
);
};
...
...
changelogs/unreleased/34841-todos.yml
0 → 100644
浏览文件 @
67f4408d
---
title
:
Fix bad type checking to prevent 0 count badge to be shown
merge_request
:
author
:
type
:
fixed
spec/javascripts/header_spec.js
浏览文件 @
67f4408d
/* eslint-disable space-before-function-paren, no-var */
import
'
~/header
'
;
import
'
~/lib/utils/text_utility
'
;
(
function
()
{
describe
(
'
Header
'
,
function
()
{
var
todosPendingCount
=
'
.todos-count
'
;
var
fixtureTemplate
=
'
issues/open-issue.html.raw
'
;
describe
(
'
Header
'
,
function
()
{
const
todosPendingCount
=
'
.todos-count
'
;
const
fixtureTemplate
=
'
issues/open-issue.html.raw
'
;
function
isTodosCountHidden
()
{
return
$
(
todosPendingCount
).
hasClass
(
'
hidden
'
);
}
function
isTodosCountHidden
()
{
return
$
(
todosPendingCount
).
hasClass
(
'
hidden
'
);
}
function
triggerToggle
(
newCount
)
{
$
(
document
).
trigger
(
'
todo:toggle
'
,
newCount
);
}
function
triggerToggle
(
newCount
)
{
$
(
document
).
trigger
(
'
todo:toggle
'
,
newCount
);
}
preloadFixtures
(
fixtureTemplate
);
beforeEach
(
function
()
{
loadFixtures
(
fixtureTemplate
);
});
preloadFixtures
(
fixtureTemplate
);
beforeEach
(()
=>
{
loadFixtures
(
fixtureTemplate
);
});
it
(
'
should update todos-count after receiving the todo:toggle event
'
,
function
()
{
triggerToggle
(
5
);
expect
(
$
(
todosPendingCount
).
text
()).
toEqual
(
'
5
'
);
});
it
(
'
should update todos-count after receiving the todo:toggle event
'
,
()
=>
{
triggerToggle
(
'
5
'
);
expect
(
$
(
todosPendingCount
).
text
()).
toEqual
(
'
5
'
);
});
it
(
'
should hide todos-count when it is 0
'
,
function
()
{
triggerToggle
(
0
);
expect
(
isTodosCountHidden
()).
toEqual
(
true
);
it
(
'
should hide todos-count when it is 0
'
,
()
=>
{
triggerToggle
(
'
0
'
);
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
()
{
triggerToggle
(
10
);
it
(
'
should show todos-count
'
,
()
=>
{
expect
(
isTodosCountHidden
()).
toEqual
(
false
);
});
describe
(
'
when todos-count is 1000
'
,
function
()
{
beforeEach
(
function
()
{
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+
'
);
});
it
(
'
should show 99+ for todos-count
'
,
()
=>
{
expect
(
$
(
todosPendingCount
).
text
()).
toEqual
(
'
99+
'
);
});
});
})
.
call
(
window
)
;
});
spec/javascripts/lib/utils/text_utility_spec.js
浏览文件 @
67f4408d
import
'
~/lib/utils/text_utility
'
;
import
{
highCountTrim
}
from
'
~/lib/utils/text_utility
'
;
describe
(
'
text_utility
'
,
()
=>
{
describe
(
'
gl.text.getTextWidth
'
,
()
=>
{
...
...
@@ -35,14 +35,14 @@ describe('text_utility', () => {
});
});
describe
(
'
gl.text.
highCountTrim
'
,
()
=>
{
describe
(
'
highCountTrim
'
,
()
=>
{
it
(
'
returns 99+ for count >= 100
'
,
()
=>
{
expect
(
gl
.
text
.
highCountTrim
(
105
)).
toBe
(
'
99+
'
);
expect
(
gl
.
text
.
highCountTrim
(
100
)).
toBe
(
'
99+
'
);
expect
(
highCountTrim
(
105
)).
toBe
(
'
99+
'
);
expect
(
highCountTrim
(
100
)).
toBe
(
'
99+
'
);
});
it
(
'
returns exact number for count < 100
'
,
()
=>
{
expect
(
gl
.
text
.
highCountTrim
(
45
)).
toBe
(
45
);
expect
(
highCountTrim
(
45
)).
toBe
(
45
);
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录