Merge branch 'feature/CSR-6' into feature/CSR-121_button-click-function
This commit is contained in:
commit
f5ce0106c8
7 changed files with 86 additions and 31 deletions
|
|
@ -15,7 +15,7 @@ module.exports = {
|
|||
testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"],
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
statements: 60,
|
||||
statements: 70,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import store from "@/store";
|
|||
|
||||
export function fetchCmsContentForPage(fmgPage) {
|
||||
return store.dispatch(storeActions.GET_PAGE_DATA, { pageName: fmgPage }).then((response) => {
|
||||
|
||||
const pageDataFromCms = {
|
||||
isCmsContentReady: false
|
||||
};
|
||||
|
|
|
|||
53
src/helpers/cms-helper.spec.js
Normal file
53
src/helpers/cms-helper.spec.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
||||
import { dispatch } from "@/store";
|
||||
|
||||
jest.mock("@/store", () => ({
|
||||
dispatch: jest.fn()
|
||||
}));
|
||||
|
||||
it("cms-content-helper: Should return data from CMS", () => {
|
||||
|
||||
// Arrange
|
||||
const cmsMockData = {
|
||||
Result: [
|
||||
{
|
||||
Type: "VehicleBannerWidget",
|
||||
Model: {
|
||||
ImageId: "28452dcb-7762-4cc9-ab09-7643d0b89203",
|
||||
GenericVehicleImage: "https://digitalconsumercms-dev.safelite.com/images/default-source/default-album/blurred-image.jpg?sfvrsn=a6ce3034_3",
|
||||
GenericVehicleImageFilePath: "images/default-source/default-album/blurred-image.jpg"
|
||||
}
|
||||
},
|
||||
{
|
||||
Type: "PageHeaderWidget",
|
||||
Model: {
|
||||
"HeaderText": "Select a year to get started"
|
||||
}
|
||||
},
|
||||
{
|
||||
Type: "PageHeaderWidget",
|
||||
Model: {
|
||||
"HeaderText": "Select a model"
|
||||
}
|
||||
},
|
||||
{
|
||||
Type: "RadioQuestionWidget",
|
||||
Model: {
|
||||
"QuestionText": "What year is your vehicle?"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
dispatch.mockImplementation(() => Promise.resolve({ data: cmsMockData }));
|
||||
|
||||
// Act
|
||||
fetchCmsContentForPage('testPage').then((response) => {
|
||||
|
||||
// Assert
|
||||
expect(response.isCmsContentReady).toBe(true);
|
||||
expect(response.PageHeaderWidget[0].HeaderText).toEqual('Select a year to get started');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
export function settleAllPromises(layoutPromiseTable) {
|
||||
export function settleAllPromises(promiseResultMap) {
|
||||
|
||||
// Pull our keys out of the promise 'table'
|
||||
const promiseNames = Object.entries(layoutPromiseTable);
|
||||
const promiseNames = Object.entries(promiseResultMap);
|
||||
|
||||
return Promise.allSettled(promiseNames.map(e => e[1]).map(n => n.promise))
|
||||
.then(results => {
|
||||
|
|
@ -11,8 +11,8 @@ export function settleAllPromises(layoutPromiseTable) {
|
|||
// Build a map of the results
|
||||
for (let i = 0; i < results.length; ++i) {
|
||||
|
||||
const promiseName = promiseNames[i][1].key;
|
||||
|
||||
const promiseName = promiseNames[i][1].resultKey;
|
||||
|
||||
// Some Promises like the cms content call don't have a 'data' field
|
||||
// when returned, so other promises do. Map the results to the object
|
||||
// so that the object is the return data.
|
||||
|
|
|
|||
28
src/helpers/layout-helper.spec.js
Normal file
28
src/helpers/layout-helper.spec.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { settleAllPromises } from "@/helpers/layout-helper";
|
||||
|
||||
it("layout-helper: Should settle all promises and return mapped promise results", () => {
|
||||
|
||||
// Arrange
|
||||
const mockPromiseOne = Promise.resolve({ data: "test-data" });
|
||||
const mockPromiseTwo = Promise.resolve({ data: "test-data-two" });
|
||||
|
||||
const promiseResultMap = [
|
||||
{
|
||||
resultKey: "MockResultOne",
|
||||
promise: mockPromiseOne,
|
||||
},
|
||||
{
|
||||
resultKey: "MockResultTwo",
|
||||
promise: mockPromiseTwo,
|
||||
},
|
||||
];
|
||||
|
||||
// Act
|
||||
settleAllPromises(promiseResultMap).then(results => {
|
||||
|
||||
// Assert
|
||||
expect(results.MockResultOne).toEqual('test-data');
|
||||
expect(results.MockResultTwo).toEqual('test-data-two');
|
||||
});
|
||||
|
||||
})
|
||||
|
|
@ -24,30 +24,6 @@ export default {
|
|||
|
||||
return this.$store.dispatch(type, payload);
|
||||
},
|
||||
GetContentFromCms() {
|
||||
return this.dispatchNonBlockingStoreAction(this.storeActions.GET_PAGE_DATA,{ pageName: this.$route.query.fmgPage }).then((response) => {
|
||||
|
||||
const pageDataFromCms = {};
|
||||
|
||||
response.data.Result.forEach((widget) => {
|
||||
if (Object.values(this.widgetNames).includes(widget.Type)) {
|
||||
// If we already have this widget, push it on the collection
|
||||
if (widget.Type in pageDataFromCms) {
|
||||
pageDataFromCms[widget.Type].push(widget.Model);
|
||||
return;
|
||||
}
|
||||
|
||||
pageDataFromCms[widget.Type] = [widget.Model];
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// Our 'Page' is ready because we have data now
|
||||
this.isCmsContentReady = true;
|
||||
|
||||
return pageDataFromCms;
|
||||
});
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
storeActions() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import baseMixin from "@/mixins/base-mixin"
|
||||
import { storeActions } from "@/constants/store-actions.js";
|
||||
import { widgetNames } from "@/constants/widget-names.js";
|
||||
import { flushPromises } from "@vue/test-utils";
|
||||
|
||||
describe("baseMixin.js", () => {
|
||||
test('dispatchNonblockingStoreAction: calls dispatch with type and payload', () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue