q42-cms-components
Version:
Front-end package that provides a UI on top of the QMS back-end
37 lines (28 loc) • 1.14 kB
JavaScript
/* global describe, it, expect */
import alerts from './alerts'
import Vue from 'vue'
import Vuex, { mapState } from 'vuex'
Vue.use(Vuex)
describe('Alerts store', function() {
it('should add and remove various alerts', function() {
const store = new Vuex.Store({
modules: {
alerts
}
})
const vm = new Vue({
computed: mapState({
alerts: state => state.alerts.all
}),
store
});
expect(vm.alerts).toEqual([]);
vm.$store.dispatch('alerts/addSuccess', 'yes');
vm.$store.dispatch('alerts/addWarning', 'ohnoes');
vm.$store.dispatch('alerts/addInfo', 'FYI');
vm.$store.dispatch('alerts/addError', 'Oops!');
expect(vm.alerts).toEqual([{'html': 'yes', 'type': 'success'},{'html': 'ohnoes', 'type': 'warning'},{'html': 'FYI', 'type': 'info'},{'html': 'Oops!', 'type': 'danger'}]);
vm.$store.dispatch('alerts/remove', vm.alerts.find(obj => obj.type == 'warning'));
expect(vm.alerts).toEqual([{'html': 'yes', 'type': 'success'},{'html': 'FYI', 'type': 'info'},{'html': 'Oops!', 'type': 'danger'}]);
});
});