Unit tests updates
This commit is contained in:
parent
25ea8048df
commit
8958dfe0bb
2 changed files with 130 additions and 42 deletions
|
|
@ -16,7 +16,7 @@ module.exports = {
|
||||||
testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"],
|
testMatch: ["**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"],
|
||||||
coverageThreshold: {
|
coverageThreshold: {
|
||||||
global: {
|
global: {
|
||||||
statements: 70,
|
statements: 80,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,50 +3,138 @@ import { dispatch } from "@/store";
|
||||||
|
|
||||||
jest.mock("@/store", () => ({
|
jest.mock("@/store", () => ({
|
||||||
dispatch: jest.fn(),
|
dispatch: jest.fn(),
|
||||||
|
state: {
|
||||||
|
order: { vehicle: { year: "2019", make: "Acura" } }
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
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 }));
|
describe("cms-content-helper.js", () => {
|
||||||
|
it("Should return data from CMS", () => {
|
||||||
|
// Arrange
|
||||||
|
const cmsMockData = {
|
||||||
|
Result: [
|
||||||
|
{
|
||||||
|
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?",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
// Act
|
dispatch.mockImplementation(() => Promise.resolve({ data: cmsMockData }));
|
||||||
fetchCmsContentForPage("testPage").then((response) => {
|
|
||||||
// Assert
|
// Act
|
||||||
expect(response.PageHeaderWidget[0].HeaderText).toEqual(
|
fetchCmsContentForPage("testPage").then((response) => {
|
||||||
"Select a year to get started"
|
// Assert
|
||||||
);
|
expect(response.PageHeaderWidget[0].HeaderText).toEqual(
|
||||||
|
"Select a year to get started"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("cms-content-helper.js", () => {
|
||||||
|
it("Should replace strings for global state", () => {
|
||||||
|
const cmsMockData = {
|
||||||
|
Result: [
|
||||||
|
{
|
||||||
|
Type: "PageHeaderWidget",
|
||||||
|
Model: {
|
||||||
|
HeaderText: "{globalState:order.vehicle.year}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
dispatch.mockImplementation(() => Promise.resolve({ data: cmsMockData }));
|
||||||
|
|
||||||
|
fetchCmsContentForPage("testPage").then((response) => {
|
||||||
|
// Assert
|
||||||
|
expect(response.PageHeaderWidget[0].HeaderText).toEqual(
|
||||||
|
"2019"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("cms-content-helper.js", () => {
|
||||||
|
it("Should replace strings for global state, and leave others the same", () => {
|
||||||
|
|
||||||
|
const cmsMockData = {
|
||||||
|
Result: [
|
||||||
|
{
|
||||||
|
Type: "PageHeaderWidget",
|
||||||
|
Model: {
|
||||||
|
HeaderText: "{globalState:order.vehicle.year}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: "RadioQuestionWidget",
|
||||||
|
Model: {
|
||||||
|
ExampleText: "My widget value!",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
dispatch.mockImplementation(() => Promise.resolve({ data: cmsMockData }));
|
||||||
|
|
||||||
|
fetchCmsContentForPage("testPage").then((response) => {
|
||||||
|
// Assert
|
||||||
|
expect(response.PageHeaderWidget[0].HeaderText).toEqual("2019");
|
||||||
|
expect(response.RadioQuestionWidget[0].ExampleText).toEqual("My widget value!");
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("cms-content-helper.js", () => {
|
||||||
|
it("Should replace strings for global state in nested objects", () => {
|
||||||
|
|
||||||
|
const cmsMockData = {
|
||||||
|
Result: [
|
||||||
|
{
|
||||||
|
Type: "PageHeaderWidget",
|
||||||
|
Model: {
|
||||||
|
HeaderText: "{globalState:order.vehicle.year}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: "RadioQuestionWidget",
|
||||||
|
Model: {
|
||||||
|
OtherObjectInside: {
|
||||||
|
ExampleText: "{globalState:order.vehicle.make}",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
dispatch.mockImplementation(() => Promise.resolve({ data: cmsMockData }));
|
||||||
|
|
||||||
|
fetchCmsContentForPage("testPage").then((response) => {
|
||||||
|
// Assert
|
||||||
|
|
||||||
|
expect(response.PageHeaderWidget[0].HeaderText).toEqual("2019");
|
||||||
|
expect(response.RadioQuestionWidget[0].OtherObjectInside.ExampleText).toEqual("Acura");
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.todo("String cannot be mapped to global state");
|
||||||
Loading…
Reference in a new issue