Skip to content

Commit aced170

Browse files
authored
Merge pull request #3 from coderdiaz/next
Next release
2 parents 2d2a5d6 + 38193ff commit aced170

File tree

10 files changed

+2689
-52
lines changed

10 files changed

+2689
-52
lines changed

.babelrc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@
22
"presets": [
33
["env", { "modules": false }],
44
"stage-3"
5-
]
5+
],
6+
"env": {
7+
"test": {
8+
"presets": [
9+
["env", { "targets": { "node": 8 }}]
10+
]
11+
}
12+
}
613
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
node_modules/
33
dist/
44
public/
5+
coverage/
56
npm-debug.log
67
yarn-error.log
78

__tests__/TinyPagination.spec.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import {mount} from 'vue-test-utils'
2+
import TinyPagination from '../src/components/TinyPagination.vue'
3+
import { create } from 'domain';
4+
5+
// Helper function to create a component
6+
const createComponent = propsData => mount(TinyPagination, {propsData})
7+
8+
describe('TinyPagination.vue', () => {
9+
let cmp
10+
it('has a created hook', () => {
11+
expect(typeof TinyPagination.created).toBe('function')
12+
})
13+
14+
describe('Properties', () => {
15+
it('when the component is created without page prop, Page 1 is the page by default', () => {
16+
cmp = createComponent({total: 300})
17+
expect(cmp.vm.page).toBe(1)
18+
})
19+
20+
it('when the page property is set, the currentPage is equals', () => {
21+
cmp = createComponent({total: 300, page: 2})
22+
expect(cmp.vm.currentPage).toBe(2)
23+
})
24+
25+
it('when the component is created, English is the language by default', () => {
26+
cmp = createComponent({total: 300})
27+
expect(cmp.vm.lang).toBe('en')
28+
expect(cmp.vm.translation.title).toBe('Page')
29+
})
30+
31+
it('when the lang prop is set to spanish, the component is translated', () => {
32+
cmp = createComponent({total: 300, lang: 'es'})
33+
expect(cmp.vm.lang).toBe('es')
34+
expect(cmp.vm.translation.title).toBe('Página')
35+
})
36+
37+
it('when the lang prop is set to not available language, English is the language by default', () => {
38+
cmp = createComponent({total: 300, lang: 'fr'})
39+
expect(cmp.vm.translation.title).toBe('Page')
40+
})
41+
})
42+
43+
describe('Watchers', () => {
44+
45+
it('currentPage watcher is called with the new value', () => {
46+
let spy = jest.fn()
47+
cmp = createComponent({total: 100})
48+
cmp.vm.$watch('currentPage', spy)
49+
50+
cmp.setData({currentPage: 3})
51+
cmp.update()
52+
53+
expect(spy).toBeCalled()
54+
})
55+
56+
it('currentLimit watcher is called with the new value', () => {
57+
let spy = jest.fn()
58+
cmp = createComponent({total: 200})
59+
cmp.vm.$watch('currentLimit', spy)
60+
61+
cmp.setData({currentLimit: 20})
62+
cmp.update()
63+
64+
expect(spy).toBeCalled()
65+
})
66+
67+
it('when the currentPage watcher is called, the tiny:change-page event is emitted', () => {
68+
let stub = jest.fn()
69+
cmp = createComponent({total: 100})
70+
cmp.vm.$on('tiny:change-page', stub)
71+
72+
cmp.setData({currentPage: 3})
73+
expect(stub).toBeCalledWith({page: 3})
74+
})
75+
76+
it('when the currentLimit watcher is called, the tiny:change-limit event is emitted', () => {
77+
let stub = jest.fn()
78+
cmp = createComponent({total: 100})
79+
cmp.vm.$on('tiny:change-limit', stub)
80+
81+
cmp.setData({currentLimit: 20})
82+
expect(stub).toBeCalledWith({limit: 20})
83+
})
84+
})
85+
86+
describe('Events', () => {
87+
beforeEach(() => {
88+
cmp = createComponent({total: 20})
89+
})
90+
91+
it('calls nextPage when click on next button', () => {
92+
cmp.vm.nextPage = jest.fn()
93+
cmp.update()
94+
95+
const el = cmp.find('.btn-next-page').trigger('click')
96+
expect(cmp.vm.nextPage).toBeCalled()
97+
})
98+
99+
it('call lastPage when click on prev button', () => {
100+
cmp.vm.lastPage = jest.fn()
101+
cmp.update()
102+
103+
const el = cmp.find('.btn-prev-page').trigger('click')
104+
expect(cmp.vm.lastPage).toBeCalled()
105+
})
106+
})
107+
108+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy