mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #1677 from gradido/503-Transaction-List-Pagination-Pages-clickable
503 transaction list pagination pages clickable
This commit is contained in:
commit
c54ec6cf6a
@ -23,6 +23,8 @@ describe('GddTransactionList', () => {
|
|||||||
return mount(GddTransactionList, { localVue, mocks })
|
return mount(GddTransactionList, { localVue, mocks })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const decayStartBlock = new Date(2001, 8, 9)
|
||||||
|
|
||||||
describe('mount', () => {
|
describe('mount', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = Wrapper()
|
wrapper = Wrapper()
|
||||||
@ -84,7 +86,6 @@ describe('GddTransactionList', () => {
|
|||||||
|
|
||||||
describe('with transactions', () => {
|
describe('with transactions', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const decayStartBlock = new Date(2001, 8, 9)
|
|
||||||
await wrapper.setProps({
|
await wrapper.setProps({
|
||||||
transactions: [
|
transactions: [
|
||||||
{
|
{
|
||||||
@ -406,7 +407,9 @@ describe('GddTransactionList', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('pagination buttons', () => {
|
describe('pagination buttons', () => {
|
||||||
const transactions = Array.from({ length: 42 }, (_, idx) => {
|
beforeEach(async () => {
|
||||||
|
await wrapper.setProps({
|
||||||
|
transactions: Array.from({ length: 42 }, (_, idx) => {
|
||||||
return {
|
return {
|
||||||
amount: '3.14',
|
amount: '3.14',
|
||||||
balanceDate: '2021-04-29T17:26:40+00:00',
|
balanceDate: '2021-04-29T17:26:40+00:00',
|
||||||
@ -421,63 +424,41 @@ describe('GddTransactionList', () => {
|
|||||||
typeId: 'RECEIVE',
|
typeId: 'RECEIVE',
|
||||||
balance: '33.33',
|
balance: '33.33',
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
|
|
||||||
let paginationButtons
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await wrapper.setProps({
|
|
||||||
transactions,
|
|
||||||
transactionCount: 42,
|
transactionCount: 42,
|
||||||
|
decayStartBlock,
|
||||||
|
pageSize: 25,
|
||||||
showPagination: true,
|
showPagination: true,
|
||||||
decayStartBlock: new Date(),
|
|
||||||
})
|
})
|
||||||
paginationButtons = wrapper.find('div.pagination-buttons')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows the pagination buttons', () => {
|
describe('next page button clicked', () => {
|
||||||
expect(paginationButtons.exists()).toBeTruthy()
|
beforeEach(async () => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
await wrapper.findComponent({ name: 'BPagination' }).vm.$emit('input', 2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has the previous button disabled', () => {
|
it('emits update transactions', () => {
|
||||||
expect(paginationButtons.find('button.previous-page').attributes('disabled')).toBe(
|
expect(wrapper.emitted('update-transactions')).toEqual(
|
||||||
'disabled',
|
expect.arrayContaining([[{ currentPage: 2, pageSize: 25 }]]),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
it('shows the text "1 / 2"', () => {
|
|
||||||
expect(paginationButtons.find('p.text-center').text()).toBe('1 math.div 2')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('emits update-transactions when next button is clicked', async () => {
|
describe('show no pagination', () => {
|
||||||
await paginationButtons.find('button.next-page').trigger('click')
|
beforeEach(async () => {
|
||||||
expect(wrapper.emitted('update-transactions')[1]).toEqual([
|
await wrapper.setProps({
|
||||||
{ currentPage: 2, pageSize: 25 },
|
transactions: [],
|
||||||
])
|
transactionCount: 2,
|
||||||
|
decayStartBlock,
|
||||||
|
pageSize: 25,
|
||||||
|
showPagination: false,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows text "2 / 2" when next button is clicked', async () => {
|
it('shows no pagination buttons', () => {
|
||||||
await paginationButtons.find('button.next-page').trigger('click')
|
expect(wrapper.find('ul.pagination').exists()).toBe(false)
|
||||||
expect(paginationButtons.find('p.text-center').text()).toBe('2 math.div 2')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('has next-button disabled when next button is clicked', async () => {
|
|
||||||
await paginationButtons.find('button.next-page').trigger('click')
|
|
||||||
expect(paginationButtons.find('button.next-page').attributes('disabled')).toBe('disabled')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('scrolls to top after loading next page', async () => {
|
|
||||||
await paginationButtons.find('button.next-page').trigger('click')
|
|
||||||
expect(scrollToMock).toBeCalled()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('emits update-transactions when preivous button is clicked after next buton', async () => {
|
|
||||||
await paginationButtons.find('button.next-page').trigger('click')
|
|
||||||
await paginationButtons.find('button.previous-page').trigger('click')
|
|
||||||
expect(wrapper.emitted('update-transactions')[2]).toEqual([
|
|
||||||
{ currentPage: 1, pageSize: 25 },
|
|
||||||
])
|
|
||||||
expect(scrollToMock).toBeCalled()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -63,12 +63,17 @@
|
|||||||
</transaction-list-item>
|
</transaction-list-item>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<pagination-buttons
|
<b-pagination
|
||||||
v-if="showPagination"
|
v-if="showPagination"
|
||||||
|
class="mt-3"
|
||||||
|
pills
|
||||||
|
size="lg"
|
||||||
v-model="currentPage"
|
v-model="currentPage"
|
||||||
:per-page="pageSize"
|
:per-page="pageSize"
|
||||||
:total-rows="transactionCount"
|
:total-rows="transactionCount"
|
||||||
></pagination-buttons>
|
align="center"
|
||||||
|
></b-pagination>
|
||||||
|
|
||||||
<div v-if="transactionCount <= 0" class="mt-4 text-center">
|
<div v-if="transactionCount <= 0" class="mt-4 text-center">
|
||||||
<b-icon v-if="pending" icon="three-dots" animation="cylon"></b-icon>
|
<b-icon v-if="pending" icon="three-dots" animation="cylon"></b-icon>
|
||||||
<div v-else>{{ $t('transaction.nullTransactions') }}</div>
|
<div v-else>{{ $t('transaction.nullTransactions') }}</div>
|
||||||
@ -78,7 +83,6 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import TransactionListItem from '@/components/TransactionListItem'
|
import TransactionListItem from '@/components/TransactionListItem'
|
||||||
import PaginationButtons from '@/components/PaginationButtons'
|
|
||||||
import TransactionDecay from '@/components/Transactions/TransactionDecay'
|
import TransactionDecay from '@/components/Transactions/TransactionDecay'
|
||||||
import TransactionSend from '@/components/Transactions/TransactionSend'
|
import TransactionSend from '@/components/Transactions/TransactionSend'
|
||||||
import TransactionReceive from '@/components/Transactions/TransactionReceive'
|
import TransactionReceive from '@/components/Transactions/TransactionReceive'
|
||||||
@ -89,7 +93,6 @@ export default {
|
|||||||
name: 'gdd-transaction-list',
|
name: 'gdd-transaction-list',
|
||||||
components: {
|
components: {
|
||||||
TransactionListItem,
|
TransactionListItem,
|
||||||
PaginationButtons,
|
|
||||||
TransactionDecay,
|
TransactionDecay,
|
||||||
TransactionSend,
|
TransactionSend,
|
||||||
TransactionReceive,
|
TransactionReceive,
|
||||||
|
|||||||
@ -155,8 +155,8 @@ describe('GdtTransactionList ', () => {
|
|||||||
describe('change of currentPage', () => {
|
describe('change of currentPage', () => {
|
||||||
it('calls the API after currentPage changes', async () => {
|
it('calls the API after currentPage changes', async () => {
|
||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
wrapper.setData({ currentPage: 2 })
|
await wrapper.setData({ transactionGdtCount: 42 })
|
||||||
await wrapper.vm.$nextTick()
|
await wrapper.findComponent({ name: 'BPagination' }).vm.$emit('input', 2)
|
||||||
expect(apolloMock).toBeCalledWith(
|
expect(apolloMock).toBeCalledWith(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
variables: {
|
variables: {
|
||||||
@ -166,6 +166,44 @@ describe('GdtTransactionList ', () => {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('pagination buttons', () => {
|
||||||
|
describe('with transactionCount > pageSize', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
apolloMock.mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
listGDTEntries: {
|
||||||
|
count: 42,
|
||||||
|
gdtEntries: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
wrapper = Wrapper()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows the pagination buttons', () => {
|
||||||
|
expect(wrapper.find('ul.pagination').exists()).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('with transactionCount < pageSize', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
apolloMock.mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
listGDTEntries: {
|
||||||
|
count: 2,
|
||||||
|
gdtEntries: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
wrapper = Wrapper()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows no pagination buttons', () => {
|
||||||
|
expect(wrapper.find('ul.pagination').exists()).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -27,23 +27,26 @@
|
|||||||
></transaction>
|
></transaction>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<pagination-buttons
|
<b-pagination
|
||||||
|
v-if="transactionGdtCount > pageSize"
|
||||||
|
class="mt-3"
|
||||||
|
pills
|
||||||
|
size="lg"
|
||||||
v-model="currentPage"
|
v-model="currentPage"
|
||||||
:per-page="pageSize"
|
:per-page="pageSize"
|
||||||
:total-rows="transactionGdtCount"
|
:total-rows="transactionGdtCount"
|
||||||
></pagination-buttons>
|
align="center"
|
||||||
|
></b-pagination>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { listGDTEntriesQuery } from '@/graphql/queries'
|
import { listGDTEntriesQuery } from '@/graphql/queries'
|
||||||
import PaginationButtons from '@/components/PaginationButtons'
|
|
||||||
import Transaction from '@/components/Transaction.vue'
|
import Transaction from '@/components/Transaction.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'gdt-transaction-list',
|
name: 'gdt-transaction-list',
|
||||||
components: {
|
components: {
|
||||||
PaginationButtons,
|
|
||||||
Transaction,
|
Transaction,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
|||||||
@ -1,49 +0,0 @@
|
|||||||
import { mount } from '@vue/test-utils'
|
|
||||||
import PaginationButtons from './PaginationButtons'
|
|
||||||
|
|
||||||
const localVue = global.localVue
|
|
||||||
|
|
||||||
const propsData = {
|
|
||||||
totalRows: 42,
|
|
||||||
perPage: 12,
|
|
||||||
value: 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('PaginationButtons', () => {
|
|
||||||
let wrapper
|
|
||||||
|
|
||||||
const mocks = {
|
|
||||||
$t: jest.fn((t) => t),
|
|
||||||
}
|
|
||||||
|
|
||||||
const Wrapper = () => {
|
|
||||||
return mount(PaginationButtons, { localVue, mocks, propsData })
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('mount', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
wrapper = Wrapper()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('renders the component', () => {
|
|
||||||
expect(wrapper.find('div.pagination-buttons').exists()).toBeTruthy()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('with active buttons', () => {
|
|
||||||
it('emits input next page button is clicked', async () => {
|
|
||||||
wrapper.find('button.next-page').trigger('click')
|
|
||||||
await wrapper.vm.$nextTick()
|
|
||||||
expect(wrapper.emitted().input[0]).toEqual([2])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('emits input when previous page button is clicked', async () => {
|
|
||||||
wrapper.setProps({ value: 2 })
|
|
||||||
wrapper.setData({ currentValue: 2 })
|
|
||||||
await wrapper.vm.$nextTick()
|
|
||||||
wrapper.find('button.previous-page').trigger('click')
|
|
||||||
await wrapper.vm.$nextTick()
|
|
||||||
expect(wrapper.emitted().input[0]).toEqual([1])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="pagination-buttons" v-if="totalRows > perPage">
|
|
||||||
<b-row class="m-4">
|
|
||||||
<b-col class="text-right">
|
|
||||||
<b-button class="previous-page" :disabled="!hasPrevious" @click="currentValue--">
|
|
||||||
<b-icon icon="chevron-left" variant="primary"></b-icon>
|
|
||||||
</b-button>
|
|
||||||
</b-col>
|
|
||||||
<b-col cols="3">
|
|
||||||
<p class="text-center pt-2">{{ value }} {{ $t('math.div') }} {{ totalPages }}</p>
|
|
||||||
</b-col>
|
|
||||||
<b-col>
|
|
||||||
<b-button class="next-page" :disabled="!hasNext" @click="currentValue++">
|
|
||||||
<b-icon icon="chevron-right" variant="primary"></b-icon>
|
|
||||||
</b-button>
|
|
||||||
</b-col>
|
|
||||||
</b-row>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
name: 'PaginationButtons',
|
|
||||||
props: {
|
|
||||||
totalRows: { required: true },
|
|
||||||
perPage: { type: Number, required: true },
|
|
||||||
value: { type: Number, required: true },
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
currentValue: { type: Number, default: 1 },
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
hasNext() {
|
|
||||||
return this.value * this.perPage < this.totalRows
|
|
||||||
},
|
|
||||||
hasPrevious() {
|
|
||||||
return this.value > 1
|
|
||||||
},
|
|
||||||
totalPages() {
|
|
||||||
return Math.ceil(this.totalRows / this.perPage)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
this.currentValue = this.value
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
currentValue() {
|
|
||||||
if (this.currentValue !== this.value) this.$emit('input', this.currentValue)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@ -143,7 +143,6 @@
|
|||||||
"login": "Anmeldung",
|
"login": "Anmeldung",
|
||||||
"math": {
|
"math": {
|
||||||
"aprox": "~",
|
"aprox": "~",
|
||||||
"div": "/",
|
|
||||||
"equal": "=",
|
"equal": "=",
|
||||||
"exclaim": "!",
|
"exclaim": "!",
|
||||||
"pipe": "|"
|
"pipe": "|"
|
||||||
|
|||||||
@ -143,7 +143,6 @@
|
|||||||
"login": "Login",
|
"login": "Login",
|
||||||
"math": {
|
"math": {
|
||||||
"aprox": "~",
|
"aprox": "~",
|
||||||
"div": "/",
|
|
||||||
"equal": "=",
|
"equal": "=",
|
||||||
"exclaim": "!",
|
"exclaim": "!",
|
||||||
"pipe": "|"
|
"pipe": "|"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user