1
|
|
|
import test from 'ava' |
2
|
|
|
|
3
|
|
|
import {addVueAndFeathers, vueAndFeathersCleanup} from './helpers/before/feathers-and-vue-hookup' |
4
|
|
|
import {addBasicService} from './helpers/before/feathers-hookup' |
5
|
|
|
|
6
|
|
|
test.beforeEach(addVueAndFeathers) |
7
|
|
|
test.beforeEach(addBasicService) |
8
|
|
|
|
9
|
|
|
test.afterEach(vueAndFeathersCleanup) |
10
|
|
|
|
11
|
|
|
test.cb('Use single item syncer if requested', t => { |
12
|
|
|
const {Vue} = t.context |
13
|
|
|
|
14
|
|
|
t.context.instance = new Vue({ |
15
|
|
|
sync: { |
16
|
|
|
testVar: { |
17
|
|
|
service: 'test', |
18
|
|
|
id: function () { |
19
|
|
|
return 1 |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
}, |
23
|
|
|
created() { |
24
|
|
|
this.$on('syncer-loaded', path => { |
25
|
|
|
t.is(path, 'testVar') |
26
|
|
|
t.deepEqual(this.testVar, {id: 1, tested: true}) |
27
|
|
|
t.end() |
28
|
|
|
}) |
29
|
|
|
this.$on('syncer-error', (path, error) => { |
30
|
|
|
t.fail(error) |
31
|
|
|
t.end() |
32
|
|
|
}) |
33
|
|
|
} |
34
|
|
|
}) |
35
|
|
|
}) |
36
|
|
|
|
37
|
|
|
test.cb('Cleanup', t => { |
38
|
|
|
const {client, Vue} = t.context |
39
|
|
|
|
40
|
|
|
const instance = t.context.instance = new Vue({ |
41
|
|
|
sync: { |
42
|
|
|
test: 'test' |
43
|
|
|
}, |
44
|
|
|
created() { |
45
|
|
|
this.$on('syncer-loaded', () => { |
46
|
|
|
Vue.util.nextTick(() => { |
47
|
|
|
instance.$destroy() |
48
|
|
|
}) |
49
|
|
|
}) |
50
|
|
|
this.$on('syncer-error', (path, error) => { |
51
|
|
|
t.fail(error) |
52
|
|
|
t.end() |
53
|
|
|
}) |
54
|
|
|
}, |
55
|
|
|
destroyed: function () { |
56
|
|
|
function checkEventListenersAreEmpty(event) { |
57
|
|
|
if (client.io.listeners['test ' + event]) { |
58
|
|
|
t.is(client.io.listeners['test ' + event].length, 0) |
59
|
|
|
} else { |
60
|
|
|
t.pass() |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
checkEventListenersAreEmpty('created') |
65
|
|
|
checkEventListenersAreEmpty('updated') |
66
|
|
|
checkEventListenersAreEmpty('patched') |
67
|
|
|
checkEventListenersAreEmpty('removed') |
68
|
|
|
|
69
|
|
|
// syncer value is null after deletion |
70
|
|
|
t.deepEqual(this.test, null) |
71
|
|
|
|
72
|
|
|
t.end() |
73
|
|
|
} |
74
|
|
|
}) |
75
|
|
|
}) |
76
|
|
|
|
77
|
|
|
test.cb('Synced key can\'t be directly overwritten', t => { |
78
|
|
|
const {Vue} = t.context |
79
|
|
|
|
80
|
|
|
t.context.instance = new Vue({ |
81
|
|
|
sync: { |
82
|
|
|
test: 'test' |
83
|
|
|
}, |
84
|
|
|
created() { |
85
|
|
|
this.$on('syncer-loaded', () => { |
86
|
|
|
Vue.util.nextTick(() => { |
87
|
|
|
this.test = 'Failed' |
88
|
|
|
|
89
|
|
|
t.not(this.test, 'Failed') |
90
|
|
|
|
91
|
|
|
t.end() |
92
|
|
|
}) |
93
|
|
|
}) |
94
|
|
|
this.$on('syncer-error', (path, error) => { |
95
|
|
|
t.fail(error) |
96
|
|
|
t.end() |
97
|
|
|
}) |
98
|
|
|
} |
99
|
|
|
}) |
100
|
|
|
}) |
101
|
|
|
|
102
|
|
|
test.cb('Syncer can be configured in mixins', t => { |
103
|
|
|
const {Vue} = t.context |
104
|
|
|
|
105
|
|
|
t.context.instance = new Vue({ |
106
|
|
|
mixins: [ |
107
|
|
|
{ |
108
|
|
|
sync: { |
109
|
|
|
mixedIn: 'test', |
110
|
|
|
overwritten: { |
111
|
|
|
service: 'test', |
112
|
|
|
id() { |
113
|
|
|
return 2 |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
], |
119
|
|
|
sync: { |
120
|
|
|
overwritten: { |
121
|
|
|
service: 'test', |
122
|
|
|
id() { |
123
|
|
|
return 1 |
124
|
|
|
} |
125
|
|
|
}, |
126
|
|
|
independant: 'test' |
127
|
|
|
}, |
128
|
|
|
created() { |
129
|
|
|
this.$on('syncer-loaded', () => { |
130
|
|
|
if (this.$loadingSyncers) { |
131
|
|
|
return // Wait for all |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
t.deepEqual(this.mixedIn, {1: {id: 1, tested: true}, 2: {id: 2, otherItem: true}}) |
135
|
|
|
t.deepEqual(this.overwritten, {id: 1, tested: true}) |
136
|
|
|
t.deepEqual(this.independant, {1: {id: 1, tested: true}, 2: {id: 2, otherItem: true}}) |
137
|
|
|
t.end() |
138
|
|
|
}) |
139
|
|
|
this.$on('syncer-error', (path, error) => { |
140
|
|
|
t.fail(error) |
141
|
|
|
t.end() |
142
|
|
|
}) |
143
|
|
|
} |
144
|
|
|
}) |
145
|
|
|
}) |
146
|
|
|
|
147
|
|
|
|