Skip to content

Commit

Permalink
test: added basic vuex tests for categories
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Feb 22, 2021
1 parent d222009 commit b475107
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
2 changes: 0 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
module.exports = {
// TODO: We should try to switch to the @vue/app preset, but right now it breaks everything
//presets: ['@vue/app'],
presets: ['@vue/cli-plugin-babel/preset'],
plugins: ['lodash', '@babel/plugin-syntax-dynamic-import'],
comments: false,
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/test/**/*.test.node.js?(x)'],
transform: {
'^.+\\.js$': 'babel-jest',
'^.+\\.vue$': 'vue-jest',
},
moduleNameMapper: {
'^~/(.+)$': '<rootDir>/src/$1',
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test": "jest --rootDir=./",
"test": "vue-cli-service test:unit",
"test:unit": "vue-cli-service test:unit",
"test:e2e": "vue-cli-service test:e2e",
"lint": "vue-cli-service lint",
Expand Down
2 changes: 1 addition & 1 deletion src/util/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const defaultCategories: Category[] = [
{
name: ['Work'],
rule: { type: 'regex', regex: 'Google Docs|libreoffice|ReText' },
data: { productivity: 5, color: '#0F0' },
data: { color: '#0F0' },
},
{
name: ['Work', 'Programming'],
Expand Down
26 changes: 26 additions & 0 deletions test/unit/store/categories.test.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import store from '~/store';

test('loads categories', () => {
// Load categories
expect(store.state.categories.classes).toHaveLength(0);
store.commit('categories/restoreDefaultClasses');
expect(store.state.categories.classes_unsaved_changes).toBeTruthy();
store.commit('categories/saveCompleted');
expect(store.state.categories.classes_unsaved_changes).toBeFalsy();
expect(store.state.categories.classes).not.toHaveLength(0);

// Retrieve class
let workCat = store.getters['categories/get_category'](['Work']);
expect(workCat).not.toBeUndefined();
workCat = JSON.parse(JSON.stringify(workCat)); // copy

// Modify class
const newRegex = 'Just testing';
workCat.rule.regex = newRegex;
store.commit('categories/updateClass', workCat);
expect(store.getters['categories/get_category'](['Work']).rule.regex).toEqual(newRegex);

// Check that getters behave somewhat
expect(store.getters['categories/all_categories']).not.toHaveLength(0);
expect(store.getters['categories/classes_hierarchy']).not.toHaveLength(0);
});

0 comments on commit b475107

Please sign in to comment.