Unit tests added, alert adjusted
This commit is contained in:
parent
91af7ef626
commit
05dd90a204
4 changed files with 96 additions and 4 deletions
|
|
@ -2,7 +2,7 @@
|
|||
<div class="funnel-header d-flex justify-content-center align-items-center flex-column" v-if="imageSrc">
|
||||
<img class="logo-image img-fluid" :src="imageSrc" alt="Safelite logo" />
|
||||
</div>
|
||||
<alert class="position-absolute mt-6 w-100" v-if="displayGlobalAlert" :alertClass="globalAlertMessage.type" :alertHeadline="globalAlertMessage.messageCopy" :alertCopy="globalAlertMessage.messageHeadline" v-bind:isDismissible="globalAlertMessage.isDismissible" />
|
||||
<alert class="position-absolute rounded-0 w-100 border-0 shadow-sm" v-if="displayGlobalAlert" :alertClass="globalAlertMessage.type" :alertHeadline="globalAlertMessage.messageCopy" :alertCopy="globalAlertMessage.messageHeadline" v-bind:isDismissible="globalAlertMessage.isDismissible" />
|
||||
|
||||
</template>
|
||||
|
||||
|
|
|
|||
50
src/helpers/event-bus/event-bus.spec.js
Normal file
50
src/helpers/event-bus/event-bus.spec.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { globalEvents, globalEventTypes } from "@/constants/events";
|
||||
import eventBus from "@/helpers/event-bus/event-bus";
|
||||
import store from "@/store";
|
||||
|
||||
describe("event-bus.js", () => {
|
||||
|
||||
let event = {
|
||||
isDismissible: true,
|
||||
messageCopy: 'You can get a quote by starting on this page.',
|
||||
messageHeadline: 'We\'re sorry, something went wrong.',
|
||||
type: globalEventTypes.Danger
|
||||
};
|
||||
|
||||
it("Puts item on bus and then take it off", () => {
|
||||
|
||||
// Arrange / Act
|
||||
eventBus.addEventToBus(
|
||||
globalEvents.Categories.GLOBAL_ALERT,
|
||||
globalEvents.SubCategories.PAGE_NOT_FOUND,
|
||||
event
|
||||
);
|
||||
|
||||
|
||||
// Assert
|
||||
expect(store.getters.eventBusItem(globalEvents.Categories.GLOBAL_ALERT, globalEvents.SubCategories.PAGE_NOT_FOUND)).toEqual(event);
|
||||
|
||||
expect(store.state.applicationUser.eventBus.length).toEqual(1);
|
||||
|
||||
// Arrange / Act
|
||||
const eventValue = eventBus.readAndPopEventFromBus(globalEvents.Categories.GLOBAL_ALERT, globalEvents.SubCategories.PAGE_NOT_FOUND);
|
||||
|
||||
// Assert
|
||||
expect(eventValue).toEqual(event);
|
||||
|
||||
expect(store.state.applicationUser.eventBus.length).toEqual(0);
|
||||
});
|
||||
|
||||
it("Reads event from bus, should have event value.", () => {
|
||||
// Arrange / Act
|
||||
eventBus.addEventToBus(
|
||||
globalEvents.Categories.GLOBAL_ALERT,
|
||||
globalEvents.SubCategories.PAGE_NOT_FOUND,
|
||||
event
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(eventBus.readEventFromBus(globalEvents.Categories.GLOBAL_ALERT, globalEvents.SubCategories.PAGE_NOT_FOUND)).toEqual(event);
|
||||
|
||||
});
|
||||
});
|
||||
|
|
@ -3,6 +3,7 @@ import { endpoints } from "@/constants/endpoints.js";
|
|||
import { storeMutations } from "@/constants/store-mutations"
|
||||
import createPersistedState from "vuex-persistedstate";
|
||||
import globalMethods from "@/global-methods";
|
||||
import eventBus from "../helpers/event-bus/event-bus";
|
||||
|
||||
export default createStore({
|
||||
plugins: [createPersistedState()],
|
||||
|
|
@ -85,7 +86,7 @@ export default createStore({
|
|||
|
||||
// If the item exists, remove it.
|
||||
if (itemIndex > -1) {
|
||||
state.applicationUser.eventBus.splice(itemIndex, 1);
|
||||
state.applicationUser.eventBus.splice(itemIndex, 1);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -253,10 +253,51 @@ describe("Mutations", () => {
|
|||
expect(store.state.order.vehicle.carId).toBe("123abc");
|
||||
expect(store.state.order.vehicle.category).toBe("car");
|
||||
});
|
||||
|
||||
it("Should add event onto bus and update state", () => {
|
||||
// Arrange
|
||||
const event = {category: 'TestCategoryOne', subCategory: 'TestSubCategoryOne', eventValue: 'TestEventValueOne'};
|
||||
|
||||
// Act
|
||||
store.commit("addEventToBus", event);
|
||||
|
||||
//Assert
|
||||
expect(store.state.applicationUser.eventBus[0].category).toBe('TestCategoryOne');
|
||||
expect(store.state.applicationUser.eventBus[0].subCategory).toBe('TestSubCategoryOne');
|
||||
expect(store.state.applicationUser.eventBus[0].eventValue).toBe('TestEventValueOne');
|
||||
});
|
||||
});
|
||||
|
||||
describe("Getters", () => {
|
||||
const vehicle = store.getters.vehicle;
|
||||
|
||||
expect(typeof vehicle).toBe('object');
|
||||
it("Should validate vehicle getter", () => {
|
||||
// Arrange
|
||||
const vehicle = store.getters.vehicle;
|
||||
|
||||
// Assert
|
||||
expect(typeof vehicle).toBe('object');
|
||||
});
|
||||
|
||||
it("Should get item from bus via getter", () => {
|
||||
// Arrange
|
||||
const event = {category: 'TestCategoryOne', subCategory: 'TestSubCategoryOne', eventValue: 'TestEventValueOne'};
|
||||
|
||||
// Act
|
||||
store.commit("addEventToBus", event)
|
||||
|
||||
// Assert
|
||||
const returnedEventValue = store.getters.eventBusItem(event.category, event.subCategory);
|
||||
expect(returnedEventValue).toBe('TestEventValueOne');
|
||||
});
|
||||
|
||||
it("Should get eventbus from getter, should have length > 0", () => {
|
||||
// Arrange
|
||||
const event = {category: 'TestCategoryOne', subCategory: 'TestSubCategoryOne', eventValue: 'TestEventValueOne'};
|
||||
|
||||
// Act
|
||||
store.commit("addEventToBus", event);
|
||||
|
||||
//Assert
|
||||
expect(store.getters.eventBus.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue