Refactor action for easier testing
parent
089d727c11
commit
80d03553c9
|
@ -7,7 +7,7 @@ import {
|
|||
updateMessage,
|
||||
updateAlerts,
|
||||
updateRuleName,
|
||||
deleteRule,
|
||||
deleteRuleSuccess,
|
||||
} from 'src/kapacitor/actions/view';
|
||||
|
||||
describe('Kapacitor.Reducers.rules', () => {
|
||||
|
@ -113,7 +113,7 @@ describe('Kapacitor.Reducers.rules', () => {
|
|||
};
|
||||
|
||||
expect(Object.keys(initialState).length).to.equal(2);
|
||||
const newState = reducer(initialState, deleteRule(rule2));
|
||||
const newState = reducer(initialState, deleteRuleSuccess(rule2));
|
||||
expect(Object.keys(newState).length).to.equal(1);
|
||||
expect(newState[rule1]).to.equal(initialState[rule1]);
|
||||
});
|
||||
|
|
|
@ -109,16 +109,19 @@ export function updateRuleName(ruleID, name) {
|
|||
};
|
||||
}
|
||||
|
||||
export function deleteRuleSuccess(ruleID) {
|
||||
return {
|
||||
type: 'DELETE_RULE_SUCCESS',
|
||||
payload: {
|
||||
ruleID,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function deleteRule(rule) {
|
||||
return (dispatch) => {
|
||||
deleteRuleAPI(rule).then(() => {
|
||||
dispatch({
|
||||
type: 'DELETE_RULE',
|
||||
payload: {
|
||||
ruleID: rule.id,
|
||||
},
|
||||
});
|
||||
|
||||
dispatch(deleteRuleSuccess(rule.id));
|
||||
dispatch(publishNotification('success', `${rule.name} deleted successfully`));
|
||||
}).catch(() => {
|
||||
dispatch(publishNotification('error', `${rule.name} deleted successfully`));
|
||||
|
|
|
@ -80,7 +80,7 @@ export default function rules(state = {}, action) {
|
|||
});
|
||||
}
|
||||
|
||||
case 'DELETE_RULE': {
|
||||
case 'DELETE_RULE_SUCCESS': {
|
||||
const {ruleID} = action.payload;
|
||||
delete state[ruleID];
|
||||
return Object.assign({}, state);
|
||||
|
|
Loading…
Reference in New Issue