Skip to content

Commit 50c13ba

Browse files
committed
Adding test for 8d83973
1 parent 8d83973 commit 50c13ba

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

test/collection.pagination.test.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import test from 'ava'
2+
3+
import CollectionSyncer from '../src/syncers/collection'
4+
5+
import {addPaginatedService} from './helpers/before/feathers-hookup'
6+
import {addVueAndFeathers, vueAndFeathersCleanup} from './helpers/before/feathers-and-vue-hookup'
7+
8+
test.beforeEach(addVueAndFeathers)
9+
test.beforeEach(addPaginatedService)
10+
test.beforeEach(t => {
11+
const Vue = t.context.Vue
12+
t.context.instance = new Vue({
13+
data: function () {
14+
return {
15+
// To avoid vue-warn for setting paths on vm
16+
variables: {}
17+
}
18+
}
19+
})
20+
21+
t.context.createSyncer = function (settings) {
22+
return new CollectionSyncer(Vue, t.context.instance, 'test', settings)
23+
}
24+
})
25+
26+
test.afterEach(t => {
27+
if ('syncer' in t.context) {
28+
t.context.syncer.destroy()
29+
}
30+
})
31+
test.afterEach(vueAndFeathersCleanup)
32+
33+
test('Basic handling of pagination', async t => {
34+
const {instance, createSyncer} = t.context
35+
36+
instance.$on('syncer-error', (path, error) => {
37+
t.fail(error)
38+
})
39+
40+
const syncer = t.context.syncer = createSyncer({
41+
service: 'paginated',
42+
query() {
43+
return {
44+
$limit: 3
45+
}
46+
}
47+
})
48+
49+
t.plan(4)
50+
51+
// Loading by default
52+
t.truthy(syncer.loading)
53+
54+
instance.$once('syncer-loaded', path => {
55+
// correct path
56+
t.is(path, 'test')
57+
})
58+
59+
await syncer.ready()
60+
61+
t.falsy(syncer.loading)
62+
t.deepEqual(syncer.state, {1: {id: 1, item: 'first'}, 2: {id: 2, item: 'second'}, 3: {id: 3, item: 'third'}})
63+
})

test/helpers/before/feathers-hookup.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,38 @@ export function addBasicService(t) {
5757
}
5858
}
5959

60+
export function addPaginatedService(t) {
61+
t.context.server.service('paginated', new Service({
62+
paginate: {
63+
default: 3,
64+
max: 10
65+
},
66+
startId: 6,
67+
store: cloneDeep({
68+
1: {
69+
id: 1,
70+
item: 'first'
71+
},
72+
2: {
73+
id: 2,
74+
item: 'second'
75+
},
76+
3: {
77+
id: 3,
78+
item: 'third'
79+
},
80+
4: {
81+
id: 4,
82+
item: 'fourth'
83+
},
84+
5: {
85+
id: 5,
86+
item: 'fifth'
87+
}
88+
})
89+
}))
90+
}
91+
6092
export function feathersCleanup(t) {
6193
t.context.server.io.close()
6294
}

0 commit comments

Comments
 (0)