Skip to content

Commit

Permalink
linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraPinilla committed Mar 29, 2024
1 parent 21b0374 commit 4ed45d0
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 151 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import PropTypes from "@arc-fusion/prop-types";
import useSales from "../useSales";
import { Grid } from "@wpmedia/arc-themes-components";
import useSales from "../useSales";
import OfferCard from "../OfferCard";

export const ARCXP_CART = 'ArcXP_cart';
Expand Down Expand Up @@ -43,7 +43,8 @@ const OfferToProductList = ({ offer, isLoggedIn, checkoutURL, loginURL, classNam
quantity: 1,
},
]);
const maxEndDate = Math.max(...offer?.campaigns?.map(c => c.validUntil));
const allValidUntil = offer?.campaigns?.map(c => c.validUntil !== undefined && !Number.isNaN(c.validUntil));
const maxEndDate = allValidUntil.length ? Math.max(allValidUntil) : null;
const liveCampaing = offer?.campaigns?.find(c => c.validUntil === null || c.validUntil === maxEndDate);
localStorage.setItem(ARCXP_CAMPAIGN, liveCampaing?.name);
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { act, render } from "@testing-library/react";
import { act, render, waitFor } from "@testing-library/react";
import OfferToProductList from "./index";
import useOffer from "../useOffer";
import OfferCard from "../OfferCard";
Expand Down Expand Up @@ -177,31 +177,34 @@ jest.mock("fusion:properties", () =>
script: "https://corecomponents-the-gazette-prod.cdn.arcpublishing.com/arc/subs/p.min.js",
},
},
}))
})),
);

jest.mock("../OfferCard", () => {
return jest.fn(() => null);
});

jest.mock("@arc-publishing/sdk-sales");
jest.mock("../../components/useOffer");

useOffer.mockReturnValue({
offer: sampleOffer,
fetchOffer: () => sampleOffer,
});

describe("The OfferToProductList component", () => {
it("renders the correct number of offer cards", () => {
const { container } = render(
it("renders the correct number of offer cards", async () => {
render(
<OfferToProductList
isLoggedIn
loginURL="/login/"
checkoutURL="/checkout/"
offer={sampleOffer}
/>
/>,
);

act(() => {
container.setProps({});
});
const mockedChildComponent = OfferCard;

expect(container.find(OfferCard)).toHaveLength(4);
await waitFor(() => expect(mockedChildComponent).toHaveBeenCalledTimes(4));
});
});
});
57 changes: 28 additions & 29 deletions blocks/subscriptions-block/components/OrderInformation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,33 @@ const OrderSummary = ({ orderDetails, className }) => {
);
};

const ProductPriceDetails = ({
details = [],
showPriceDescription,
showProductFeatures,
className,
}) => {
if (details?.items?.length) {
return details?.items?.map((item) =>
<Stack as="div" className={`${className}__orderCard--productPrice`}>
<Heading> {item.priceName}</Heading>
{showPriceDescription && (
<Paragraph dangerouslySetInnerHTML={{ __html: item?.priceDescription }} />
)}
{showProductFeatures && (
<FeatureDetails
features={item?.productAttributes}
className={`${className}__orderCard`}
/>
)}
</Stack>
);
}
return null;
};

const OrderInformation = ({
id,
offerURL,
showOfferURL,
showPriceDescription,
Expand All @@ -41,36 +67,9 @@ const OrderInformation = ({
className,
}) => {
const phrases = usePhrases();

const ProductPriceDetails = ({
details = [],
showPriceDescription,
showProductFeatures,
className,
}) => {
if (details?.items?.length) {
return details?.items?.map((item) => {
return (
<Stack as="div" className={`${className}__orderCard--productPrice`}>
<Heading> {item.priceName}</Heading>
{showPriceDescription && (
<Paragraph dangerouslySetInnerHTML={{ __html: item?.priceDescription }} />
)}
{showProductFeatures && (
<FeatureDetails
features={item?.productAttributes}
className={`${className}__orderCard`}
/>
)}
</Stack>
);
});
}
return null;
};


return (
<section className={`${className}__orderCard`}>
<section key={`orderInfo${id && `-${id}`}`} className={`${className}__orderCard`}>
<ProductPriceDetails
details={orderDetails}
showPriceDescription={showPriceDescription}
Expand Down
104 changes: 0 additions & 104 deletions blocks/subscriptions-block/components/OrderInformation/index.test.js

This file was deleted.

141 changes: 141 additions & 0 deletions blocks/subscriptions-block/components/OrderInformation/index.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import React from "react";
import { render, screen, within } from "@testing-library/react";
import '@testing-library/jest-dom';
import OrderInformation from "./index";
import currency from "../../utils/currency";

const orderDetails = {
currency: "COP",
shipping: 0,
subtotal: 20000,
tax: 100,
taxSupported: true,
total: 20100,
items: [
{
name: "COP Currency",
price: 20000,
priceCode: "Q6R7UO",
priceDescription: "<p>with tax description price</p>",
priceName: "All access Annual",
priceSummary: "<p>with tax summary price</p>",
productDescription: "<p>COP Currency description</p>",
quantity: 1,
shortDescription: "<p>COP Currency description</p>",
sku: "0987",
subtotal: 20100,
tax: 0,
taxInclusive: undefined,
total: 20000,
productAttributes: [
{
featureText: "<p>Unlimited access to The Daily Intelligencer</p>",
},
{
featureText: "<p>Save $40</p>",
},
{
featureText: "<p>A <strong>bonus subscription</strong> to share</p>",
},
],
},
],
};

jest.mock("@arc-publishing/sdk-identity", () => ({
__esModule: true,
default: {
apiOrigin: "",
options: jest.fn(),
},
}));

jest.mock("fusion:properties", () =>
jest.fn(() => ({
api: {
identity: {
origin: "https://corecomponents-arc-demo-3-prod.api.cdn.arcpublishing.com",
},
retail: {
origin: "https://corecomponents-arc-demo-3-prod.api.cdn.arcpublishing.com",
endpoint: "/retail/public/v1/offer/live/",
},
},
})),
);

jest.mock("fusion:context", () => ({
__esModule: true,
useFusionContext: () => ({
arcSite: "Test Site",
}),
}));

describe('Order Information component', () => {
it("renders order info", () => {
render(
<OrderInformation
id={1}
orderDetails={orderDetails}
offerURL={"/offer/"}
showOfferURL={false}
showPriceDescription={false}
showProductFeatures={true}
/>,
);
expect(screen.getByText(orderDetails?.items?.[0]?.priceName)).toBeVisible();
expect(screen.getByText("checkout-block.order-summary")).toBeVisible();
expect(screen.getByText("checkout-block.subtotal")).toBeVisible();
expect(
screen.getByText(`${currency(orderDetails?.currency)}${orderDetails?.subtotal}`),
).toBeVisible();
expect(screen.getByText("checkout-block.salesTax")).toBeVisible();
expect(
screen.getByText(`${currency(orderDetails?.currency)}${orderDetails?.total}`),
).toBeVisible();
expect(screen.getByText("checkout-block.due-today")).toBeVisible();
});

it("renders price description", () => {
render(
<OrderInformation
orderDetails={orderDetails}
showOfferURL={false}
showPriceDescription={true}
showProductFeatures={true}
/>,
);
expect(screen.getByText("with tax description price")).toBeVisible();
});

it("renders features", () => {
render(
<OrderInformation
orderDetails={orderDetails}
offerURL={"/offer/"}
showOfferURL={true}
showPriceDescription={false}
showProductFeatures={true}
/>,
);
const list = screen.getByRole("list");
const { getAllByRole } = within(list);
const items = getAllByRole("listitem");
expect(items.length).toBe(3);
});

it("renders link to offer", () => {
render(
<OrderInformation
orderDetails={orderDetails}
offerURL={"/offer/"}
showOfferURL={true}
showPriceDescription={false}
showProductFeatures={true}
/>,
);
expect(
screen.getByRole("link", { name: "checkout-block.view-subscription-offers" }),
).toHaveAttribute("href", "/offer/");
});
});
Loading

0 comments on commit 4ed45d0

Please sign in to comment.