-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bring back shared pagination component and refactor it to use DDAU vi…
…a props instead of store
- Loading branch information
Showing
10 changed files
with
143 additions
and
69 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/web-app-files/src/components/FilesList/Pagination.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<template> | ||
<oc-pagination | ||
v-if="pages > 1" | ||
:pages="pages" | ||
:current-page="currentPage" | ||
:max-displayed="3" | ||
:current-route="$route" | ||
class="files-pagination uk-flex uk-flex-center oc-my-s" | ||
/> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: { | ||
pages: { | ||
type: Number, | ||
required: true | ||
}, | ||
currentPage: { | ||
type: Number, | ||
required: true | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
packages/web-app-files/tests/unit/components/FilesList/Pagination.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import _ from 'lodash' | ||
import DesignSystem from 'owncloud-design-system' | ||
import Pagination from '@files/src/components/FilesList/Pagination.vue' | ||
import { | ||
createLocalVue as OGCreateLocalVue, | ||
mount, | ||
RouterLinkStub, | ||
shallowMount | ||
} from '@vue/test-utils' | ||
|
||
const filesPersonalRoute = { name: 'files-personal', path: '/files/home' } | ||
|
||
const selectors = { | ||
filesPagination: '.files-pagination' | ||
} | ||
|
||
const createLocalVue = () => { | ||
const localVue = OGCreateLocalVue() | ||
localVue.use(DesignSystem) | ||
localVue.prototype.$gettextInterpolate = jest.fn() | ||
|
||
return localVue | ||
} | ||
|
||
const getWrapper = (propsData = {}) => { | ||
return shallowMount(Pagination, { | ||
localVue: createLocalVue(), | ||
stubs: { | ||
'oc-pagination': true | ||
}, | ||
propsData: _.merge({ currentPage: 1, pages: 10 }, propsData), | ||
mocks: { | ||
$route: filesPersonalRoute | ||
} | ||
}) | ||
} | ||
|
||
const getMountedWrapper = (propsData = {}) => { | ||
return mount(Pagination, { | ||
localVue: createLocalVue(), | ||
propsData: _.merge({ currentPage: 1, pages: 10 }, propsData), | ||
stubs: { | ||
'oc-pagination': false, | ||
RouterLink: RouterLinkStub | ||
}, | ||
mocks: { | ||
$route: filesPersonalRoute | ||
} | ||
}) | ||
} | ||
|
||
describe('Pagination', () => { | ||
describe('when amount of pages is', () => { | ||
describe('less than or equals one', () => { | ||
it.each([-1, 0, 1])('should not show wrapper', (pages) => { | ||
const wrapper = getWrapper({ currentPage: 0, pages }) | ||
|
||
expect(wrapper.find(selectors.filesPagination).exists()).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe('greater than one', () => { | ||
const wrapper = getWrapper({ currentPage: 1, pages: 2 }) | ||
|
||
it('should show wrapper', () => { | ||
const paginationEl = wrapper.find('.files-pagination') | ||
|
||
expect(paginationEl.exists()).toBeTruthy() | ||
expect(paginationEl.attributes().pages).toBe('2') | ||
}) | ||
|
||
it('should set provided current page', () => { | ||
const paginationEl = wrapper.find(selectors.filesPagination) | ||
console.log(wrapper.html()) | ||
expect(paginationEl.attributes().currentpage).toBe('1') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('current route', () => { | ||
it('should use provided route to render pages', () => { | ||
const wrapper = getMountedWrapper() | ||
const currentRoute = wrapper.vm.$route | ||
const links = wrapper.findAllComponents(RouterLinkStub) | ||
|
||
// three links (route to prev, next and last page) | ||
expect(links.length).toBe(3) | ||
expect(links.at(0).props().to.name).toBe(currentRoute.name) | ||
expect(links.at(1).props().to.name).toBe(currentRoute.name) | ||
expect(links.at(2).props().to.name).toBe(currentRoute.name) | ||
}) | ||
}) | ||
}) |