-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97c07f8
commit 21b0374
Showing
10 changed files
with
502 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
blocks/subscriptions-block/components/OrderInformation/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from "react"; | ||
|
||
import { usePhrases, Link, Heading, Paragraph, Stack } from "@wpmedia/arc-themes-components"; | ||
import { FeatureDetails } from "../OfferCard"; | ||
import currency from "../../utils/currency"; | ||
|
||
const OrderSummary = ({ orderDetails, className }) => { | ||
const phrases = usePhrases(); | ||
|
||
return ( | ||
<Stack className={`${className}__summary`}> | ||
<Heading>{phrases.t("checkout-block.order-summary")}</Heading> | ||
<Stack className={`${className}__summary--details`}> | ||
<Stack direction="horizontal" justification="space-between" className={`${className}__summary--details--item`}> | ||
<p>{phrases.t("checkout-block.subtotal")}</p> | ||
<p>{`${currency(orderDetails?.currency)}${orderDetails?.subtotal}`}</p> | ||
</Stack> | ||
<Stack direction="horizontal" justification="space-between" className={`${className}__summary--details--item`}> | ||
<p>{phrases.t("checkout-block.salesTax")}</p> | ||
<p> | ||
{orderDetails?.tax > 0 | ||
? `${currency(orderDetails?.currency)}${orderDetails?.tax}` | ||
: "--"} | ||
</p> | ||
</Stack> | ||
</Stack> | ||
<div className={`${className}__summary--dueToday`}> | ||
<p>{phrases.t("checkout-block.due-today")}</p> | ||
<p>{`${currency(orderDetails?.currency)}${orderDetails?.total}`}</p> | ||
</div> | ||
</Stack> | ||
); | ||
}; | ||
|
||
const OrderInformation = ({ | ||
offerURL, | ||
showOfferURL, | ||
showPriceDescription, | ||
showProductFeatures, | ||
orderDetails, | ||
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`}> | ||
<ProductPriceDetails | ||
details={orderDetails} | ||
showPriceDescription={showPriceDescription} | ||
showProductFeatures={showProductFeatures} | ||
className={className} | ||
/> | ||
{showOfferURL && ( | ||
<Link href={offerURL}>{phrases.t("checkout-block.view-subscription-offers")}</Link> | ||
)} | ||
<OrderSummary orderDetails={orderDetails} className={`${className}__orderCard`} /> | ||
</section> | ||
); | ||
}; | ||
|
||
export default OrderInformation; |
104 changes: 104 additions & 0 deletions
104
blocks/subscriptions-block/components/OrderInformation/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import React from "react"; | ||
import { screen, render, within } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import OrderInformation from "./index"; | ||
import currency from "../../utils/currency"; | ||
|
||
|
||
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", | ||
}), | ||
})); | ||
|
||
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>", | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
describe("OfferCard", () => { | ||
it("renders order info", ()=>{ | ||
render(<OrderInformation 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/'); | ||
}); | ||
}); |
Oops, something went wrong.