Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
6f156643
Commit
6f156643
authored
Oct 21, 2016
by
杨奕
Committed by
GitHub
Oct 21, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #567 from QingWei-Li/test/pagination
Pagination: add test
parents
d6721eed
ef75d0d3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
325 additions
and
41 deletions
+325
-41
examples/docs/zh-cn/pagination.md
examples/docs/zh-cn/pagination.md
+1
-1
packages/pagination/src/pager.vue
packages/pagination/src/pager.vue
+1
-0
packages/pagination/src/pagination.js
packages/pagination/src/pagination.js
+34
-27
test/unit/specs/date-picker.spec.js
test/unit/specs/date-picker.spec.js
+8
-8
test/unit/specs/pagination.spec.js
test/unit/specs/pagination.spec.js
+270
-0
test/unit/util.js
test/unit/util.js
+11
-5
No files found.
examples/docs/zh-cn/pagination.md
View file @
6f156643
...
@@ -160,7 +160,7 @@
...
@@ -160,7 +160,7 @@
padding: 30px 24px;
padding: 30px 24px;
border-bottom: solid 1px #EFF2F6;
border-bottom: solid 1px #EFF2F6;
&:last-child {
&:last-child {
border-bottom: none;
border-bottom: none;
}
}
}
}
...
...
packages/pagination/src/pager.vue
View file @
6f156643
...
@@ -68,6 +68,7 @@
...
@@ -68,6 +68,7 @@
}
}
}
}
/* istanbul ignore if */
if
(
!
isNaN
(
newPage
))
{
if
(
!
isNaN
(
newPage
))
{
if
(
newPage
<
1
)
{
if
(
newPage
<
1
)
{
newPage
=
1
;
newPage
=
1
;
...
...
packages/pagination/src/pagination.js
View file @
6f156643
...
@@ -45,7 +45,8 @@ export default {
...
@@ -45,7 +45,8 @@ export default {
render
(
h
)
{
render
(
h
)
{
let
template
=
<
div
class
=
'
el-pagination
'
><
/div>
;
let
template
=
<
div
class
=
'
el-pagination
'
><
/div>
;
const
layout
=
this
.
$options
.
layout
||
this
.
layout
||
''
;
const
layout
=
this
.
layout
||
''
;
if
(
!
layout
)
return
;
const
TEMPLATE_MAP
=
{
const
TEMPLATE_MAP
=
{
prev
:
<
prev
><
/prev>
,
prev
:
<
prev
><
/prev>
,
jumper
:
<
jumper
><
/jumper>
,
jumper
:
<
jumper
><
/jumper>
,
...
@@ -116,7 +117,9 @@ export default {
...
@@ -116,7 +117,9 @@ export default {
Sizes
:
{
Sizes
:
{
created
()
{
created
()
{
if
(
Array
.
isArray
(
this
.
$parent
.
pageSizes
))
{
if
(
Array
.
isArray
(
this
.
$parent
.
pageSizes
))
{
this
.
$parent
.
internalPageSize
=
this
.
$parent
.
pageSizes
.
indexOf
(
this
.
$parent
.
pageSize
)
>
-
1
?
this
.
$parent
.
pageSize
:
this
.
$parent
.
pageSizes
[
0
];
this
.
$parent
.
internalPageSize
=
this
.
$parent
.
pageSizes
.
indexOf
(
this
.
$parent
.
pageSize
)
>
-
1
?
this
.
$parent
.
pageSize
:
this
.
$parent
.
pageSizes
[
0
];
}
}
},
},
...
@@ -232,25 +235,26 @@ export default {
...
@@ -232,25 +235,26 @@ export default {
}
}
},
},
first
()
{
// XXX: 暂时没有到第一页和最后一页的交互
const
oldPage
=
this
.
internalCurrentPage
;
// first() {
const
newVal
=
1
;
// const oldPage = this.internalCurrentPage;
this
.
internalCurrentPage
=
this
.
getValidCurrentPage
(
newVal
);
// const newVal = 1;
// this.internalCurrentPage = this.getValidCurrentPage(newVal);
if
(
this
.
internalCurrentPage
!==
oldPage
)
{
//
if (this.internalCurrentPage !== oldPage) {
this
.
$emit
(
'
currentchange
'
,
this
.
internalCurrentPage
);
//
this.$emit('currentchange', this.internalCurrentPage);
}
//
}
},
//
},
last
()
{
//
last() {
const
oldPage
=
this
.
internalCurrentPage
;
//
const oldPage = this.internalCurrentPage;
const
newVal
=
this
.
pageCount
;
//
const newVal = this.pageCount;
this
.
internalCurrentPage
=
this
.
getValidCurrentPage
(
newVal
);
//
this.internalCurrentPage = this.getValidCurrentPage(newVal);
if
(
this
.
internalCurrentPage
!==
oldPage
)
{
//
if (this.internalCurrentPage !== oldPage) {
this
.
$emit
(
'
currentchange
'
,
this
.
internalCurrentPage
);
//
this.$emit('currentchange', this.internalCurrentPage);
}
//
}
},
//
},
getValidCurrentPage
(
value
)
{
getValidCurrentPage
(
value
)
{
value
=
parseInt
(
value
,
10
);
value
=
parseInt
(
value
,
10
);
...
@@ -273,21 +277,23 @@ export default {
...
@@ -273,21 +277,23 @@ export default {
computed
:
{
computed
:
{
pageCount
()
{
pageCount
()
{
return
Math
.
ceil
(
this
.
total
/
this
.
internalPageSize
);
return
Math
.
ceil
(
this
.
total
/
this
.
internalPageSize
);
}
,
}
startRecordIndex
()
{
// XXX: 暂时没用到
const
result
=
(
this
.
internalCurrentPage
-
1
)
*
this
.
internalPageSize
+
1
;
// startRecordIndex() {
return
result
>
0
?
result
:
0
;
// const result = (this.internalCurrentPage - 1) * this.internalPageSize + 1;
},
// return result > 0 ? result : 0;
// },
endRecordIndex
()
{
//
endRecordIndex() {
const
result
=
this
.
internalCurrentPage
*
this
.
internalPageSize
;
//
const result = this.internalCurrentPage * this.internalPageSize;
return
result
>
this
.
total
?
this
.
total
:
result
;
//
return result > this.total ? this.total : result;
}
//
}
},
},
watch
:
{
watch
:
{
pageCount
(
newVal
)
{
pageCount
(
newVal
)
{
/* istanbul ignore if */
if
(
newVal
>
0
&&
this
.
internalCurrentPage
===
0
)
{
if
(
newVal
>
0
&&
this
.
internalCurrentPage
===
0
)
{
this
.
internalCurrentPage
=
1
;
this
.
internalCurrentPage
=
1
;
}
else
if
(
this
.
internalCurrentPage
>
newVal
)
{
}
else
if
(
this
.
internalCurrentPage
>
newVal
)
{
...
@@ -312,6 +318,7 @@ export default {
...
@@ -312,6 +318,7 @@ export default {
internalCurrentPage
(
newVal
,
oldVal
)
{
internalCurrentPage
(
newVal
,
oldVal
)
{
newVal
=
parseInt
(
newVal
,
10
);
newVal
=
parseInt
(
newVal
,
10
);
/* istanbul ignore if */
if
(
isNaN
(
newVal
))
{
if
(
isNaN
(
newVal
))
{
newVal
=
oldVal
||
1
;
newVal
=
oldVal
||
1
;
}
else
{
}
else
{
...
...
test/unit/specs/date-picker.spec.js
View file @
6f156643
...
@@ -39,16 +39,16 @@ describe('DatePicker', () => {
...
@@ -39,16 +39,16 @@ describe('DatePicker', () => {
expect
(
spans
[
1
].
textContent
).
to
.
include
(
date
.
getMonth
()
+
1
);
expect
(
spans
[
1
].
textContent
).
to
.
include
(
date
.
getMonth
()
+
1
);
$el
.
querySelector
(
'
.el-date-picker__prev-btn.el-icon-d-arrow-left
'
).
click
();
$el
.
querySelector
(
'
.el-date-picker__prev-btn.el-icon-d-arrow-left
'
).
click
();
// click 5
// click 5
arrowLeftElm
.
click
();
let
count
=
5
;
arrowLeftElm
.
click
();
while
(
--
count
)
{
arrowLeftElm
.
click
();
arrowLeftElm
.
click
();
arrowLeftElm
.
click
();
}
arrowLeftElm
.
click
();
// click 3
// click 3
arrowRightElm
.
click
();
count
=
3
;
arrowRightElm
.
click
();
while
(
--
count
)
{
arrowRightElm
.
click
();
arrowRightElm
.
click
();
}
setTimeout
(
_
=>
{
setTimeout
(
_
=>
{
expect
(
spans
[
0
].
textContent
).
to
.
include
(
date
.
getFullYear
()
-
1
);
expect
(
spans
[
0
].
textContent
).
to
.
include
(
date
.
getFullYear
()
-
1
);
expect
(
spans
[
1
].
textContent
).
to
.
include
(
date
.
getMonth
()
-
1
);
expect
(
spans
[
1
].
textContent
).
to
.
include
(
date
.
getMonth
()
-
1
);
...
...
test/unit/specs/pagination.spec.js
0 → 100644
View file @
6f156643
import
{
createTest
,
createVue
,
triggerEvent
}
from
'
../util
'
;
import
Pagination
from
'
packages/pagination
'
;
describe
(
'
Pagination
'
,
()
=>
{
it
(
'
create
'
,
()
=>
{
const
vm
=
createTest
(
Pagination
);
const
elm
=
vm
.
$el
;
// prev
expect
(
elm
.
querySelector
(
'
button.btn-prev
'
)).
to
.
exist
;
// pager
expect
(
elm
.
querySelector
(
'
ul.el-pager
'
)).
to
.
exist
;
// next
expect
(
elm
.
querySelector
(
'
button.btn-next
'
)).
to
.
exist
;
// jumper
expect
(
elm
.
querySelector
(
'
.el-pagination__jump
'
)).
to
.
exist
;
// ->
expect
(
elm
.
querySelector
(
'
.el-pagination__rightwrapper
'
)).
to
.
exist
;
// total
expect
(
elm
.
querySelector
(
'
.el-pagination__total
'
)).
to
.
exist
;
});
it
(
'
set layout
'
,
()
=>
{
const
vm
=
createTest
(
Pagination
,
{
layout
:
'
prev, pager, next
'
});
const
elm
=
vm
.
$el
;
// prev
expect
(
elm
.
querySelector
(
'
button.btn-prev
'
)).
to
.
exist
;
// pager
expect
(
elm
.
querySelector
(
'
ul.el-pager
'
)).
to
.
exist
;
// next
expect
(
elm
.
querySelector
(
'
button.btn-next
'
)).
to
.
exist
;
// not found jumper
expect
(
elm
.
querySelector
(
'
.el-pagination__jump
'
)).
to
.
not
.
exist
;
// not found ->
expect
(
elm
.
querySelector
(
'
.el-pagination__rightwrapper
'
)).
to
.
not
.
exist
;
// not found total
expect
(
elm
.
querySelector
(
'
.el-pagination__total
'
)).
to
.
not
.
exist
;
});
it
(
'
small
'
,
()
=>
{
const
vm
=
createTest
(
Pagination
,
{
small
:
true
});
expect
(
vm
.
$el
.
classList
.
contains
(
'
el-pagination--small
'
)).
to
.
true
;
});
it
(
'
pageSize
'
,
()
=>
{
const
vm
=
createTest
(
Pagination
,
{
pageSize
:
25
,
total
:
100
});
expect
(
vm
.
$el
.
querySelectorAll
(
'
li.number
'
)).
to
.
length
(
4
);
});
it
(
'
currentPage
'
,
()
=>
{
const
vm
=
createTest
(
Pagination
,
{
pageSize
:
20
,
total
:
200
,
currentPage
:
3
});
expect
(
vm
.
$el
.
querySelector
(
'
li.number.active
'
)).
to
.
have
.
property
(
'
textContent
'
).
to
.
equal
(
'
3
'
);
});
it
(
'
pageSizes
'
,
()
=>
{
const
vm
=
createTest
(
Pagination
,
{
pageSizes
:
[
10
,
15
,
35
,
50
],
pageSize
:
35
,
total
:
1000
,
layout
:
'
sizes, prev, pager, next
'
});
expect
(
vm
.
$el
.
querySelector
(
'
.el-select-dropdown__item.selected
'
)).
to
.
property
(
'
textContent
'
).
include
(
'
35
'
);
expect
([].
slice
.
call
(
vm
.
$el
.
querySelectorAll
(
'
.el-select-dropdown__item
'
))
.
map
(
node
=>
parseInt
(
node
.
textContent
,
10
)))
.
to
.
deep
.
equal
([
10
,
15
,
35
,
50
]);
});
it
(
'
pageSizes:not found pageSize
'
,
()
=>
{
const
vm
=
createTest
(
Pagination
,
{
pageSizes
:
[
10
,
15
,
35
,
50
],
pageSize
:
24
,
total
:
1000
,
layout
:
'
sizes, prev, pager, next
'
});
expect
(
vm
.
$el
.
querySelector
(
'
.el-select-dropdown__item.selected
'
)).
to
.
property
(
'
textContent
'
).
include
(
'
10
'
);
});
it
(
'
layout is empty
'
,
()
=>
{
const
vm
=
createTest
(
Pagination
,
{
layout
:
''
});
expect
(
vm
.
$el
.
textContent
).
to
.
empty
;
});
it
(
'
jumper: change value
'
,
()
=>
{
const
vm
=
createVue
({
template
:
`
<el-pagination
@currentchange="handleChange"
:page-size="10"
:total="100" />
`
,
methods
:
{
handleChange
(
val
)
{
this
.
page
=
val
;
}
},
data
()
{
return
{
page
:
0
};
}
},
true
);
const
input
=
vm
.
$el
.
querySelector
(
'
.el-pagination__jump input
'
);
input
.
focus
();
input
.
value
=
-
1
;
triggerEvent
(
input
,
'
change
'
);
expect
(
vm
.
page
).
to
.
equal
(
1
);
input
.
value
=
10000
;
triggerEvent
(
input
,
'
change
'
);
expect
(
vm
.
page
).
to
.
equal
(
10
);
input
.
value
=
'
我好帅
'
;
triggerEvent
(
input
,
'
change
'
);
expect
(
vm
.
page
).
to
.
equal
(
1
);
});
it
(
'
event:currentchange
'
,
()
=>
{
const
vm
=
createVue
({
template
:
`
<el-pagination
:total="1000"
@currentchange="change = true" />
`
,
data
()
{
return
{
change
:
false
};
}
});
const
next
=
vm
.
$el
.
querySelector
(
'
button.btn-next
'
);
const
prev
=
vm
.
$el
.
querySelector
(
'
button.btn-prev
'
);
expect
(
vm
.
change
).
to
.
false
;
// click 9
let
count
=
9
;
while
(
--
count
)
{
next
.
click
();
}
prev
.
click
();
expect
(
vm
.
change
).
to
.
true
;
});
it
(
'
event:sizechange
'
,
done
=>
{
const
vm
=
createVue
({
template
:
`
<el-pagination
:total="100"
layout="sizes, prev, pager, next"
@sizechange="trigger = true"
:pageSize="10" />
`
,
data
()
{
return
{
trigger
:
false
};
}
});
expect
(
vm
.
trigger
).
to
.
false
;
vm
.
$el
.
querySelectorAll
(
'
li.el-select-dropdown__item
'
)[
1
].
click
();
setTimeout
(
_
=>
{
expect
(
vm
.
trigger
).
to
.
true
;
done
();
},
50
);
});
it
(
'
pageSize > total
'
,
()
=>
{
const
vm
=
createVue
({
template
:
`
<el-pagination
@currentchange="handleChange"
:page-size="1000"
:total="0" />
`
,
methods
:
{
handleChange
(
val
)
{
this
.
page
=
val
;
}
},
data
()
{
return
{
page
:
0
};
}
});
const
input
=
vm
.
$el
.
querySelector
(
'
.el-pagination__jump input
'
);
input
.
value
=
1
;
triggerEvent
(
input
,
'
change
'
);
expect
(
vm
.
page
).
to
.
equal
(
0
);
input
.
value
=
'
我好帅
'
;
triggerEvent
(
input
,
'
change
'
);
expect
(
vm
.
page
).
to
.
equal
(
0
);
});
describe
(
'
click pager
'
,
()
=>
{
it
(
'
click ul
'
,
()
=>
{
const
vm
=
createTest
(
Pagination
,
{
total
:
1000
},
true
);
vm
.
$el
.
querySelector
(
'
.el-pager
'
).
click
();
expect
(
vm
.
internalCurrentPage
).
to
.
equal
(
1
);
});
it
(
'
click li
'
,
()
=>
{
const
vm
=
createTest
(
Pagination
,
{
total
:
1000
},
true
);
vm
.
$el
.
querySelectorAll
(
'
.el-pager li.number
'
)[
1
].
click
();
expect
(
vm
.
internalCurrentPage
).
to
.
equal
(
2
);
});
it
(
'
click next icon-more
'
,
()
=>
{
const
vm
=
createTest
(
Pagination
,
{
total
:
1000
},
true
);
vm
.
$el
.
querySelector
(
'
.el-pager .more
'
).
click
();
expect
(
vm
.
internalCurrentPage
).
to
.
equal
(
6
);
});
it
(
'
click prev icon-more
'
,
done
=>
{
const
vm
=
createTest
(
Pagination
,
{
total
:
1000
},
true
);
vm
.
$el
.
querySelector
(
'
.btn-quicknext.more
'
).
click
();
setTimeout
(
_
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.btn-quickprev.more
'
)).
to
.
exist
;
vm
.
$el
.
querySelector
(
'
.btn-quickprev.more
'
).
click
();
expect
(
vm
.
internalCurrentPage
).
to
.
equal
(
1
);
done
();
},
50
);
});
it
(
'
click last page
'
,
done
=>
{
const
vm
=
createTest
(
Pagination
,
{
total
:
1000
},
true
);
const
nodes
=
vm
.
$el
.
querySelectorAll
(
'
li.number
'
);
nodes
[
nodes
.
length
-
1
].
click
();
setTimeout
(
_
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.btn-quickprev.more
'
)).
to
.
exist
;
expect
(
vm
.
$el
.
querySelector
(
'
.btn-quicknext.more
'
)).
to
.
not
.
exist
;
done
();
},
50
);
});
});
});
test/unit/util.js
View file @
6f156643
...
@@ -49,16 +49,22 @@ exports.createTest = function(Compo, propsData = {}, mounted = false) {
...
@@ -49,16 +49,22 @@ exports.createTest = function(Compo, propsData = {}, mounted = false) {
/**
/**
* 触发一个事件
* 触发一个事件
* mouseenter, mouseleave, mouseover, keyup 等
* mouseenter, mouseleave, mouseover, keyup
, change
等
* @param {Element} elm
* @param {Element} elm
* @param {EventName} name
* @param {EventName} name
* @param {options} opts
* @param {options} opts
*/
*/
exports
.
triggerEvent
=
function
(
elm
,
name
,
opts
)
{
exports
.
triggerEvent
=
function
(
elm
,
name
,
opts
)
{
const
isMouseEvent
=
/^mouse/
.
test
(
name
);
let
eventName
;
const
isKeyEvent
=
/^key/
.
test
(
name
);
if
(
!
isMouseEvent
&&
!
isKeyEvent
)
return
;
if
(
/^mouse/
.
test
(
name
))
{
const
evt
=
document
.
createEvent
(
isMouseEvent
?
'
MouseEvents
'
:
'
KeyboardEvent
'
);
eventName
=
'
MouseEvents
'
;
}
else
if
(
/^key/
.
test
(
name
))
{
eventName
=
'
KeyboardEvent
'
;
}
else
{
eventName
=
'
HTMLEvents
'
;
}
const
evt
=
document
.
createEvent
(
eventName
);
evt
.
initEvent
(
name
,
...
opts
);
evt
.
initEvent
(
name
,
...
opts
);
elm
.
dispatchEvent
elm
.
dispatchEvent
...
...
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