Ver código fonte

add DELETE_PASSWORD mutation

pull/342/head
Guillaume Vincent 7 anos atrás
pai
commit
d8a403b3de
3 arquivos alterados com 31 adições e 1 exclusões
  1. +2
    -1
      src/store/mutation-types.js
  2. +8
    -0
      src/store/mutations.js
  3. +21
    -0
      test/store.js

+ 2
- 1
src/store/mutation-types.js Ver arquivo

@@ -2,4 +2,5 @@ export const LOGOUT = 'LOGOUT';
export const LOGIN = 'LOGIN';
export const SET_CURRENT_PASSWORD = 'SET_CURRENT_PASSWORD';
export const SET_DEFAULT_PASSWORD = 'SET_DEFAULT_PASSWORD';
export const SET_PASSWORDS = 'SET_PASSWORDS';
export const SET_PASSWORDS = 'SET_PASSWORDS';
export const DELETE_PASSWORD = 'DELETE_PASSWORD';

+ 8
- 0
src/store/mutations.js Ver arquivo

@@ -21,5 +21,13 @@ export const mutations = {
},
[types.SET_PASSWORDS](state, {passwords}){
state.passwords = passwords;
},
[types.DELETE_PASSWORD](state, {id}){
state.passwords = state.passwords.filter(password => {
return password.id !== id;
});
if (state.currentPassword && state.currentPassword.id === id) {
state.currentPassword = Object.assign({}, state.defaultPassword);
}
}
};

+ 21
- 0
test/store.js Ver arquivo

@@ -135,4 +135,25 @@ test('SET_PASSWORDS', t => {
SET_PASSWORDS(state, {passwords: [{site: 'site1'}, {site: 'site2'}]});
t.is(state.passwords[0].site, 'site1');
t.is(state.passwords[1].site, 'site2');
});

test('DELETE_PASSWORD', t => {
const DELETE_PASSWORD = mutations[types.DELETE_PASSWORD];
const state = {
passwords: [{id: '1', site: 'site1'}, {id: '2', site: 'site2'}]
};
t.is(state.passwords.length, 2);
DELETE_PASSWORD(state, {id: '1'});
t.is(state.passwords.length, 1);
});

test('DELETE_PASSWORD clean current password with default password if same id', t => {
const DELETE_PASSWORD = mutations[types.DELETE_PASSWORD];
const state = {
passwords: [{id: '1', length: 30}, {id: '2', length: 16}],
currentPassword: {id: '1', length: 30},
defaultPassword: {length: 16}
};
DELETE_PASSWORD(state, {id: '1'});
t.is(state.currentPassword.length, 16);
});

Carregando…
Cancelar
Salvar