Skip to content

Commit fc34189

Browse files
authored
Merge pull request #1129 from wikanonymous-dev/feat/pagination
Feat/pagination
2 parents b3fd1e0 + f2021bd commit fc34189

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/components/pagination/Pagination.spec.ts

+33
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ it('should render pagination items if "total" props is provided', () => {
3232
expect(paginationItems).toHaveLength(5)
3333
})
3434

35+
it('should render no pagination item if "total" props less than zero', () => {
36+
const screen = render({
37+
components: { Pagination },
38+
template : '<Pagination :total="-100" />',
39+
})
40+
41+
const pagination = screen.getByTestId('pagination')
42+
const paginationItems = screen.queryAllByTestId('pagination-item')
43+
44+
expect(pagination).toBeInTheDocument()
45+
expect(paginationItems).toHaveLength(0)
46+
})
47+
3548
it('should render only one page item if "total" props less than provided or default "per-page" props', () => {
3649
const screen = render({
3750
components: { Pagination },
@@ -290,6 +303,26 @@ it('should bind total page to "v-model", if total page count less than current p
290303
expect(model.value).toBe(5)
291304
})
292305

306+
it('should not change "v-model" to zero, if total pagination changed to zero', async () => {
307+
const model = ref(1)
308+
const total = ref(100)
309+
310+
render({
311+
components: { Pagination },
312+
template : '<Pagination v-model="model" :total="total" :per-page="10" />',
313+
setup () {
314+
return { model, total }
315+
},
316+
})
317+
318+
expect(model.value).toBe(1)
319+
320+
total.value = 0
321+
await nextTick()
322+
323+
expect(model.value).toBe(1)
324+
})
325+
293326
it('should not change "v-model", if ellipsis is clicked', async () => {
294327
const model = ref(1)
295328
const screen = render({

src/components/pagination/Pagination.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ const rowPerPage = computed({
276276
277277
watch(totalPageCount, (value) => {
278278
if (model.value > value)
279-
model.value = value
279+
model.value = value || 1
280280
})
281281
282282
function next () {

0 commit comments

Comments
 (0)