Skip to content

Commit 1aa5a6e

Browse files
committed
update
1 parent 4425f12 commit 1aa5a6e

File tree

5 files changed

+33
-5908
lines changed

5 files changed

+33
-5908
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ By default the value emitted for the input event is of type `Number`. However yo
142142
by setting the property `output-type` to `String`.
143143
```vue
144144
<vue-numeric output-type="String"></vue-numeric>
145-
```
145+
```
146146

147147
## Props
148148
|Props|Description|Required|Type|Default|
@@ -161,6 +161,7 @@ by setting the property `output-type` to `String`.
161161
|thousand-separator|Custom thousand separator|false|String|-|
162162
|read-only|Hide input field and show the value as text|false|Boolean|false|
163163
|read-only-class|Class for read-only element|false|String|''|
164+
|allow-clear|Use input type search|false|Boolean|false|
164165

165166
## License
166167

docs/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ <h1 class="title is-4">
146146
</div>
147147

148148
<script src="https://unpkg.com/accounting-js"></script>
149-
<script src="https://unpkg.com/vue@2.6.14"></script>
149+
<script src="https://unpkg.com/vue@2.6.14/dist/vue.js"></script>
150150
<script src="../dist/vue-numeric.min.js"></script>
151151

152152
<script>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-numeric",
3-
"version": "2.4.3",
3+
"version": "2.5.0",
44
"description": "Input field component to display currency value based on Vue.",
55
"author": "Kevin Ongko",
66
"main": "dist/vue-numeric.min.js",

test/specs/vue-numeric.spec.js

+29-13
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ describe('vue-numeric.vue', () => {
5858

5959
it('outputs Number type by default', () => {
6060
const component = Vue.extend({
61+
components: { VueNumeric },
6162
data: () => ({ total: 100 }),
6263
template: '<div><vue-numeric v-model="total" :min="1" :max="100"></vue-numeric></div>',
63-
components: { VueNumeric }
6464
})
6565

6666
const wrapper = mount(component)
@@ -69,9 +69,9 @@ describe('vue-numeric.vue', () => {
6969

7070
it('outputs String if specified', () => {
7171
const component = Vue.extend({
72+
components: { VueNumeric },
7273
data: () => ({ total: 100 }),
7374
template: '<div><vue-numeric v-model="total" outputType="String" :min="1" :max="100"></vue-numeric></div>',
74-
components: { VueNumeric }
7575
})
7676

7777
const wrapper = mount(component)
@@ -133,9 +133,9 @@ describe('vue-numeric.vue', () => {
133133

134134
it('cannot exceed max props', () => {
135135
const component = Vue.extend({
136+
components: { VueNumeric },
136137
data: () => ({ total: 150 }),
137138
template: '<div><vue-numeric v-model="total" :max="100"></vue-numeric></div>',
138-
components: { VueNumeric }
139139
})
140140

141141
const wrapper = mount(component)
@@ -144,9 +144,9 @@ describe('vue-numeric.vue', () => {
144144

145145
it('cannot below min props', () => {
146146
const component = Vue.extend({
147+
components: { VueNumeric },
147148
data: () => ({ total: 150 }),
148149
template: '<div><vue-numeric v-model="total" :min="200"></vue-numeric></div>',
149-
components: { VueNumeric }
150150
})
151151

152152
const wrapper = mount(component)
@@ -155,9 +155,9 @@ describe('vue-numeric.vue', () => {
155155

156156
it('process valid value ', () => {
157157
const component = Vue.extend({
158+
components: { VueNumeric },
158159
data: () => ({ total: 100 }),
159160
template: '<div><vue-numeric v-model="total" :min="10" :max="200"></vue-numeric></div>',
160-
components: { VueNumeric }
161161
})
162162

163163
const wrapper = mount(component)
@@ -166,9 +166,9 @@ describe('vue-numeric.vue', () => {
166166

167167
it('allow minus value when minus props is true', () => {
168168
const component = Vue.extend({
169+
components: { VueNumeric },
169170
data: () => ({ total: -150 }),
170171
template: '<div><vue-numeric v-model="total" :min="-150" :minus="true"></vue-numeric></div>',
171-
components: { VueNumeric }
172172
})
173173

174174
const wrapper = mount(component)
@@ -177,9 +177,9 @@ describe('vue-numeric.vue', () => {
177177

178178
it('disallow minus value when minus props is false', () => {
179179
const component = Vue.extend({
180+
components: { VueNumeric },
180181
data: () => ({ total: -150 }),
181182
template: '<div><vue-numeric v-model="total" :min="-150" :minus="false"></vue-numeric></div>',
182-
components: { VueNumeric }
183183
})
184184

185185
const wrapper = mount(component)
@@ -190,9 +190,9 @@ describe('vue-numeric.vue', () => {
190190
const el = document.createElement('div')
191191
const vm = new Vue({
192192
el,
193+
components: { VueNumeric },
193194
data: () => ({ total: 0 }),
194195
template: '<div><vue-numeric v-model="total"></vue-numeric></div>',
195-
components: { VueNumeric }
196196
}).$mount()
197197

198198
setTimeout(() => {
@@ -216,10 +216,10 @@ describe('vue-numeric.vue', () => {
216216
expect(wrapper.data().amount).to.equal('2,000')
217217
})
218218

219-
it('clear the field if zero value', () => {
220-
const wrapper = mount(VueNumeric, {propsData: { value: 0, separator: '.', precision: 2 }})
219+
it('on focus empty string return empty string', () => {
220+
const wrapper = mount(VueNumeric, {propsData: { value: '', separator: '.', precision: 2 }})
221221
wrapper.trigger('focus')
222-
expect(wrapper.data().amount).to.equal(null)
222+
expect(wrapper.data().amount).to.equal('')
223223
})
224224

225225
it('remove thousand separator and symbol on focus with , decimal', () => {
@@ -258,9 +258,9 @@ describe('vue-numeric.vue', () => {
258258

259259
it('apply min props value if user input negative value when minus props disabled', () => {
260260
const component = Vue.extend({
261+
components: { VueNumeric },
261262
data: () => ({ total: -200 }),
262263
template: '<div><vue-numeric v-model="total" :min="150" :minus="false"></vue-numeric></div>',
263-
components: { VueNumeric }
264264
})
265265

266266
const wrapper = mount(component)
@@ -269,9 +269,9 @@ describe('vue-numeric.vue', () => {
269269

270270
it('apply 0 value if user input negative value when minus props disabled and min props is negative too', () => {
271271
const component = Vue.extend({
272+
components: { VueNumeric },
272273
data: () => ({ total: -200 }),
273274
template: '<div><vue-numeric v-model="total" :min="-150" :minus="false"></vue-numeric></div>',
274-
components: { VueNumeric }
275275
})
276276

277277
const wrapper = mount(component)
@@ -307,14 +307,30 @@ describe('vue-numeric.vue', () => {
307307
})
308308
expect(wrapper.data().amount).to.equal('1 000,94')
309309
})
310+
310311
it('emit change event', () => {
311312
const process = sinon.stub()
312313
const wrapper = mount(VueNumeric, { propsData: { value: 2000 }, methods: { process }})
313314
wrapper.trigger('change')
314315
expect(process.called).to.equal(true)
315316
})
317+
316318
it('initial value is 0 if zero is passed', () => {
317319
const wrapper = mount(VueNumeric, { propsData: { value: 0}})
318320
expect(wrapper.data().amount).to.equal('0')
319321
})
322+
323+
it('when format empty string should return empty string', () => {
324+
const wrapper = mount(VueNumeric, {propsData: { value: '', separator: '.', precision: 2 }})
325+
expect(wrapper.vm.format('')).to.equal('')
326+
})
327+
328+
it('emit input event when process empty string', () => {
329+
const update = sinon.stub()
330+
const wrapper = mount(VueNumeric, {propsData: { value: '', separator: '.', precision: 2 }, methods: { update }})
331+
const spy = sinon.spy(wrapper.vm, '$emit')
332+
wrapper.trigger('input')
333+
expect(update.called).to.equal(false)
334+
expect(spy.args[0][0]).to.equal('input')
335+
})
320336
})

0 commit comments

Comments
 (0)