Skip to content

Commit b475107

Browse files
committed
test: added basic vuex tests for categories
1 parent d222009 commit b475107

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

babel.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
module.exports = {
2-
// TODO: We should try to switch to the @vue/app preset, but right now it breaks everything
3-
//presets: ['@vue/app'],
42
presets: ['@vue/cli-plugin-babel/preset'],
53
plugins: ['lodash', '@babel/plugin-syntax-dynamic-import'],
64
comments: false,

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ module.exports = {
2525
preset: 'ts-jest',
2626
testEnvironment: 'node',
2727
testMatch: ['**/test/**/*.test.node.js?(x)'],
28+
transform: {
29+
'^.+\\.js$': 'babel-jest',
30+
'^.+\\.vue$': 'vue-jest',
31+
},
2832
moduleNameMapper: {
2933
'^~/(.+)$': '<rootDir>/src/$1',
3034
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"scripts": {
99
"serve": "vue-cli-service serve",
1010
"build": "vue-cli-service build",
11-
"test": "jest --rootDir=./",
11+
"test": "vue-cli-service test:unit",
1212
"test:unit": "vue-cli-service test:unit",
1313
"test:e2e": "vue-cli-service test:e2e",
1414
"lint": "vue-cli-service lint",

src/util/classes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const defaultCategories: Category[] = [
2424
{
2525
name: ['Work'],
2626
rule: { type: 'regex', regex: 'Google Docs|libreoffice|ReText' },
27-
data: { productivity: 5, color: '#0F0' },
27+
data: { color: '#0F0' },
2828
},
2929
{
3030
name: ['Work', 'Programming'],
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import store from '~/store';
2+
3+
test('loads categories', () => {
4+
// Load categories
5+
expect(store.state.categories.classes).toHaveLength(0);
6+
store.commit('categories/restoreDefaultClasses');
7+
expect(store.state.categories.classes_unsaved_changes).toBeTruthy();
8+
store.commit('categories/saveCompleted');
9+
expect(store.state.categories.classes_unsaved_changes).toBeFalsy();
10+
expect(store.state.categories.classes).not.toHaveLength(0);
11+
12+
// Retrieve class
13+
let workCat = store.getters['categories/get_category'](['Work']);
14+
expect(workCat).not.toBeUndefined();
15+
workCat = JSON.parse(JSON.stringify(workCat)); // copy
16+
17+
// Modify class
18+
const newRegex = 'Just testing';
19+
workCat.rule.regex = newRegex;
20+
store.commit('categories/updateClass', workCat);
21+
expect(store.getters['categories/get_category'](['Work']).rule.regex).toEqual(newRegex);
22+
23+
// Check that getters behave somewhat
24+
expect(store.getters['categories/all_categories']).not.toHaveLength(0);
25+
expect(store.getters['categories/classes_hierarchy']).not.toHaveLength(0);
26+
});

0 commit comments

Comments
 (0)