client: reorganize filters and add tests

This commit is contained in:
Matteo Pagliazzi
2016-12-06 18:27:49 -08:00
parent 0b0466b960
commit 046761b9aa
8 changed files with 30 additions and 7 deletions

View File

@@ -0,0 +1,8 @@
import floorFilter from 'client/filters/floor';
describe('floor filter', () => {
it('can floor a decimal number', () => {
expect(floorFilter(4.567)).to.equal(4.56);
expect(floorFilter(4.562)).to.equal(4.56);
});
});

View File

@@ -0,0 +1,8 @@
import roundFilter from 'client/filters/round';
describe('round filter', () => {
it('can round a decimal number', () => {
expect(roundFilter(4.567)).to.equal(4.57);
expect(roundFilter(4.562)).to.equal(4.56);
});
});

View File

@@ -100,12 +100,6 @@ export default {
components: { components: {
Avatar, Avatar,
}, },
filters: {
percent,
round (val) {
return Math.round(val * 100) / 100;
},
},
methods: { methods: {
percent, percent,
}, },

View File

@@ -32,7 +32,7 @@
span {{userGems}} span {{userGems}}
.item.with-img.gp-icon .item.with-img.gp-icon
img(src="~assets/header/png/gold@3x.png") img(src="~assets/header/png/gold@3x.png")
span {{Math.floor(user.stats.gp * 100) / 100}} span {{user.stats.gp | floor}}
a.item.with-img.notifications-dropdown a.item.with-img.notifications-dropdown
img(src="~assets/header/png/notifications@3x.png") img(src="~assets/header/png/notifications@3x.png")
.ui.simple.dropdown.pointing .ui.simple.dropdown.pointing

View File

@@ -0,0 +1,3 @@
export default function floor (val) {
return Math.floor(val * 100) / 100;
}

View File

@@ -0,0 +1,6 @@
import Vue from 'vue';
import round from './round';
import floor from './floor';
Vue.filter('round', round);
Vue.filter('floor', floor);

View File

@@ -0,0 +1,3 @@
export default function round (val) {
return Math.round(val * 100) / 100;
}

View File

@@ -7,6 +7,7 @@ import VueResource from 'vue-resource';
import AppComponent from './app'; import AppComponent from './app';
import router from './router'; import router from './router';
import store from './store'; import store from './store';
import './filters/registerGlobals';
// TODO just for the beginning // TODO just for the beginning
Vue.use(VueResource); Vue.use(VueResource);