mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 08:56:29 +00:00
0f9188597e
- Add pagination support to the API endpoints that return lists of items - Adjust UI to enable infinite scrolling via pagination
20 lines
669 B
Go
20 lines
669 B
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestApplyPagination(t *testing.T) {
|
|
example := []int{
|
|
0, 1, 2,
|
|
}
|
|
|
|
assert.Equal(t, ApplyPagination(&ListOptions{All: true}, example), example)
|
|
assert.Equal(t, ApplyPagination(&ListOptions{Page: 1, PerPage: 1}, example), []int{0})
|
|
assert.Equal(t, ApplyPagination(&ListOptions{Page: 2, PerPage: 2}, example), []int{2})
|
|
assert.Equal(t, ApplyPagination(&ListOptions{Page: 3, PerPage: 1}, example), []int{2})
|
|
assert.Equal(t, ApplyPagination(&ListOptions{Page: 4, PerPage: 1}, example), []int{})
|
|
assert.Equal(t, ApplyPagination(&ListOptions{Page: 5, PerPage: 1}, example), []int{})
|
|
}
|