Explorar el Código

add SET_DEFAULT_OPTIONS tests

pull/342/head
Guillaume Vincent hace 7 años
padre
commit
db5a0d06c0
Se han modificado 3 ficheros con 43 adiciones y 9 borrados
  1. +0
    -3
      src/store/mutation-types.js
  2. +12
    -5
      src/store/mutations.js
  3. +31
    -1
      test/store.js

+ 0
- 3
src/store/mutation-types.js Ver fichero

@@ -1,3 +0,0 @@
export const LOGIN = 'LOGIN';
export const LOGOUT = 'LOGOUT';
export const SET_CURRENT_PASSWORD_PROFILE = 'SET_CURRENT_PASSWORD_PROFILE';

+ 12
- 5
src/store/mutations.js Ver fichero

@@ -1,13 +1,20 @@
import * as types from './mutation-types';
import {set} from 'vue';

function setState(state, id, object) {
set(state, id, Object.assign({}, object));
}

export const mutations = {
[types.LOGIN](state){
LOGIN(state){
state.authenticated = true;
},
[types.LOGOUT](state){
LOGOUT(state){
state.authenticated = false;
},
[types.SET_CURRENT_PASSWORD_PROFILE](state, passwordProfile){
state.currentPasswordProfile = passwordProfile;
SET_CURRENT_PASSWORD_PROFILE(state, passwordProfile){
setState(state, 'currentPasswordProfile', passwordProfile);
},
SET_DEFAULT_OPTIONS(state, options){
setState(state, 'defaultOptions', options);
}
};

+ 31
- 1
test/store.js Ver fichero

@@ -22,6 +22,36 @@ test('SET_CURRENT_PASSWORD_PROFILE', t => {
uppercase: true,
version: 2
});
t.true(state.currentPasswordProfile.version == 2);
t.is(state.currentPasswordProfile.version, 2);
t.true(state.currentPasswordProfile.uppercase);
});

test('SET_CURRENT_PASSWORD_PROFILE immutable', t => {
const {SET_CURRENT_PASSWORD_PROFILE} = mutations;
const state = {};
const profile = {version: 2};
SET_CURRENT_PASSWORD_PROFILE(state, profile);
profile.version = 1;
t.is(state.currentPasswordProfile.version, 2);
});

test('SET_DEFAULT_OPTIONS', t => {
const {SET_DEFAULT_OPTIONS} = mutations;
const state = {
defaultOptions: {
uppercase: true,
lowercase: true,
numbers: true,
symbols: true,
length: 16,
counter: 1,
version: 2
}
};
SET_DEFAULT_OPTIONS(state, {
symbols: false,
length: 30
});
t.is(state.defaultOptions.length, 30);
t.false(state.defaultOptions.symbols);
});

Cargando…
Cancelar
Guardar