diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2bd99e045..104b85502 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -212,7 +212,7 @@ jobs: report_name: Coverage Frontend type: lcov result_path: ./coverage/lcov.info - min_coverage: 20 + min_coverage: 21 token: ${{ github.token }} ############################################################################## diff --git a/community_server/src/Controller/AppRequestsController.php b/community_server/src/Controller/AppRequestsController.php index 2ece0c726..6b744ff69 100644 --- a/community_server/src/Controller/AppRequestsController.php +++ b/community_server/src/Controller/AppRequestsController.php @@ -348,7 +348,7 @@ class AppRequestsController extends AppController $decay = true; $transactions = []; $transactions_from_db = $stateUserTransactionsQuery->toArray(); - + if(count($transactions_from_db)) { if($orderDirection == 'DESC') { $transactions_from_db = array_reverse($transactions_from_db); diff --git a/frontend/src/apis/communityAPI.js b/frontend/src/apis/communityAPI.js index 25ef10f43..b2df337b8 100644 --- a/frontend/src/apis/communityAPI.js +++ b/frontend/src/apis/communityAPI.js @@ -35,7 +35,7 @@ const communityAPI = { balance: async (sessionId) => { return apiGet(CONFIG.COMMUNITY_API_URL + 'getBalance/' + sessionId) }, - transactions: async (sessionId, firstPage = 1, items = 1000, order = 'DESC') => { + transactions: async (sessionId, firstPage = 1, items = 5, order = 'DESC') => { return apiGet( `${CONFIG.COMMUNITY_API_URL}listTransactions/${firstPage}/${items}/${order}/${sessionId}`, ) diff --git a/frontend/src/components/PaginationButtons.spec.js b/frontend/src/components/PaginationButtons.spec.js new file mode 100644 index 000000000..7a03d0443 --- /dev/null +++ b/frontend/src/components/PaginationButtons.spec.js @@ -0,0 +1,53 @@ +import { mount } from '@vue/test-utils' +import PaginationButtons from './PaginationButtons' + +const localVue = global.localVue + +describe('PaginationButtons', () => { + let wrapper + + const Wrapper = () => { + return mount(PaginationButtons, { localVue }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('renders the component', () => { + expect(wrapper.find('div.pagination-buttons').exists()).toBeTruthy() + }) + + it('has previous page button disabled by default', () => { + expect(wrapper.find('button.previous-page').attributes('disabled')).toBe('disabled') + }) + + it('has bext page button disabled by default', () => { + expect(wrapper.find('button.next-page').attributes('disabled')).toBe('disabled') + }) + + it('shows the text "1 / 1" by default"', () => { + expect(wrapper.find('p.text-center').text()).toBe('1 / 1') + }) + + describe('with active buttons', () => { + beforeEach(async () => { + await wrapper.setProps({ + hasNext: true, + hasPrevious: true, + }) + }) + + it('emits show-previous when previous page button is clicked', () => { + wrapper.find('button.previous-page').trigger('click') + expect(wrapper.emitted('show-previous')).toBeTruthy() + }) + + it('emits show-next when next page button is clicked', () => { + wrapper.find('button.next-page').trigger('click') + expect(wrapper.emitted('show-next')).toBeTruthy() + }) + }) + }) +}) diff --git a/frontend/src/components/PaginationButtons.vue b/frontend/src/components/PaginationButtons.vue new file mode 100644 index 000000000..ac7ff73c6 --- /dev/null +++ b/frontend/src/components/PaginationButtons.vue @@ -0,0 +1,30 @@ + + diff --git a/frontend/src/views/Layout/DashboardLayout_gdd.vue b/frontend/src/views/Layout/DashboardLayout_gdd.vue index d6b9f44ff..b7dfe2b93 100755 --- a/frontend/src/views/Layout/DashboardLayout_gdd.vue +++ b/frontend/src/views/Layout/DashboardLayout_gdd.vue @@ -106,9 +106,13 @@ export default { this.$store.dispatch('logout') this.$router.push('/login') }, - async updateTransactions() { + async updateTransactions(pagination) { this.pending = true - const result = await communityAPI.transactions(this.$store.state.sessionId) + const result = await communityAPI.transactions( + this.$store.state.sessionId, + pagination.firstPage, + pagination.items, + ) if (result.success) { this.GdtBalance = Number(result.result.data.gdtSum) this.transactions = result.result.data.transactions @@ -129,7 +133,7 @@ export default { this.initScrollbar() }, created() { - this.updateTransactions() + this.updateTransactions({ firstPage: 1, items: 5 }) }, } diff --git a/frontend/src/views/Pages/AccountOverview.vue b/frontend/src/views/Pages/AccountOverview.vue index 5f262f627..f25cce48b 100644 --- a/frontend/src/views/Pages/AccountOverview.vue +++ b/frontend/src/views/Pages/AccountOverview.vue @@ -31,10 +31,10 @@ @@ -116,6 +116,9 @@ export default { this.transactionData = EMPTY_TRANSACTION_DATA this.currentTransactionStep = 0 }, + updateTransactions(pagination) { + this.$emit('update-transactions', pagination) + }, }, } diff --git a/frontend/src/views/Pages/AccountOverview/GddTransactionList.spec.js b/frontend/src/views/Pages/AccountOverview/GddTransactionList.spec.js index af084d784..93dd748d6 100644 --- a/frontend/src/views/Pages/AccountOverview/GddTransactionList.spec.js +++ b/frontend/src/views/Pages/AccountOverview/GddTransactionList.spec.js @@ -202,16 +202,6 @@ describe('GddTransactionList', () => { expect(transaction.findAll('div').at(3).text()).toBe('decay') }) }) - - describe('max property set to 2', () => { - beforeEach(async () => { - await wrapper.setProps({ max: 2 }) - }) - - it('shows only 2 transactions', () => { - expect(wrapper.findAll('div.gdd-transaction-list-item')).toHaveLength(2) - }) - }) }) describe('with invalid transaction type', () => { @@ -234,5 +224,69 @@ describe('GddTransactionList', () => { expect(errorHandler).toHaveBeenCalled() }) }) + + describe('pagination buttons', () => { + const transactions = Array.from({ length: 42 }, (_, idx) => { + return { + balance: '3.14', + date: '2021-04-29T17:26:40+00:00', + memo: 'Kreiszahl PI', + name: 'Euklid', + transaction_id: idx + 1, + type: 'receive', + } + }) + + let paginationButtons + + beforeEach(async () => { + await wrapper.setProps({ + transactions, + transactionCount: 42, + showPagination: true, + }) + paginationButtons = wrapper.find('div.pagination-buttons') + }) + + it('shows the pagination buttons', () => { + expect(paginationButtons.exists()).toBeTruthy() + }) + + it('has the previous button disabled', () => { + expect(paginationButtons.find('button.previous-page').attributes('disabled')).toBe( + 'disabled', + ) + }) + + it('shows the text "1 / 2"', () => { + expect(paginationButtons.find('p.text-center').text()).toBe('1 / 2') + }) + + it('emits update-transactions when next button is clicked', async () => { + paginationButtons.find('button.next-page').trigger('click') + await wrapper.vm.$nextTick() + expect(wrapper.emitted('update-transactions')[1]).toEqual([{ firstPage: 2, items: 25 }]) + }) + + it('shows text "2 / 2" when next button is clicked', async () => { + paginationButtons.find('button.next-page').trigger('click') + await wrapper.vm.$nextTick() + expect(paginationButtons.find('p.text-center').text()).toBe('2 / 2') + }) + + it('has next-button disabled when next button is clicked', async () => { + paginationButtons.find('button.next-page').trigger('click') + await wrapper.vm.$nextTick() + expect(paginationButtons.find('button.next-page').attributes('disabled')).toBe('disabled') + }) + + it('emits update-transactions when preivous button is clicked after next buton', async () => { + paginationButtons.find('button.next-page').trigger('click') + await wrapper.vm.$nextTick() + paginationButtons.find('button.previous-page').trigger('click') + await wrapper.vm.$nextTick() + expect(wrapper.emitted('update-transactions')[2]).toEqual([{ firstPage: 1, items: 25 }]) + }) + }) }) }) diff --git a/frontend/src/views/Pages/AccountOverview/GddTransactionList.vue b/frontend/src/views/Pages/AccountOverview/GddTransactionList.vue index d2a81cdbf..55f03f9e2 100644 --- a/frontend/src/views/Pages/AccountOverview/GddTransactionList.vue +++ b/frontend/src/views/Pages/AccountOverview/GddTransactionList.vue @@ -2,7 +2,7 @@
@@ -66,6 +66,15 @@ +
{{ $t('transaction.nullTransactions') }}
@@ -74,6 +83,8 @@ diff --git a/frontend/src/views/Pages/UserProfileTransactionList.vue b/frontend/src/views/Pages/UserProfileTransactionList.vue index 1b5b30f7b..5e5fb9efe 100644 --- a/frontend/src/views/Pages/UserProfileTransactionList.vue +++ b/frontend/src/views/Pages/UserProfileTransactionList.vue @@ -9,6 +9,7 @@ :timestamp="timestamp" :transactionCount="transactionCount" :transactions="transactions" + :show-pagination="true" @update-transactions="updateTransactions" />
@@ -32,8 +33,8 @@ export default { } }, methods: { - updateTransactions() { - this.$emit('update-transactions') + updateTransactions(pagination) { + this.$emit('update-transactions', pagination) }, }, }