-
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
cf324d1
commit 36d2d5d
Showing
3 changed files
with
152 additions
and
1 deletion.
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
63 changes: 63 additions & 0 deletions
63
blocks/subscriptions-block/components/CheckoutCardDetail/index.test.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,63 @@ | ||
import React from "react"; | ||
import { render, screen, act } from "@testing-library/react"; | ||
import '@testing-library/jest-dom'; | ||
|
||
import CheckoutCardDetail from "./index"; | ||
|
||
describe('CheckoutCardDetail component', () => { | ||
|
||
it("summary is shown when card is open", async () => { | ||
render( | ||
<CheckoutCardDetail | ||
type='Account' | ||
isOpen={true} | ||
> | ||
<p>Account placeholder</p> | ||
</CheckoutCardDetail> | ||
) | ||
expect(await screen.getByText('1. checkout-block.account')).toHaveTextContent('1. checkout-block.account'); | ||
expect(await screen.getByText('Account placeholder')).toHaveTextContent('Account placeholder'); | ||
}); | ||
it("do not show summary if card is closed", async () => { | ||
render( | ||
<CheckoutCardDetail | ||
type='Account' | ||
isOpen={false} | ||
> | ||
<p>Account placeholder</p> | ||
</CheckoutCardDetail> | ||
) | ||
expect(await screen.getByText('1. checkout-block.account')).toHaveTextContent('1. checkout-block.account'); | ||
expect(await screen.queryByText('Account placeholder')).toBe(null); | ||
}); | ||
it("renders billing address card", async () => { | ||
render( | ||
<CheckoutCardDetail | ||
type='Billing Address' | ||
isOpen={true} | ||
> | ||
</CheckoutCardDetail> | ||
) | ||
expect(await screen.getByText('2. checkout-block.billingAddress')).toHaveTextContent('2. checkout-block.billingAddress'); | ||
}); | ||
it("renders payment card", async () => { | ||
render( | ||
<CheckoutCardDetail | ||
type='Payment' | ||
isOpen={true} | ||
> | ||
</CheckoutCardDetail> | ||
) | ||
expect(await screen.getByText('3. checkout-block.payment')).toHaveTextContent('3. checkout-block.payment'); | ||
}); | ||
it("renders review card", async () => { | ||
render( | ||
<CheckoutCardDetail | ||
type='Review' | ||
isOpen={true} | ||
> | ||
</CheckoutCardDetail> | ||
) | ||
expect(await screen.getByText('4. checkout-block.review')).toHaveTextContent('4. checkout-block.review'); | ||
}); | ||
}) |
88 changes: 88 additions & 0 deletions
88
blocks/subscriptions-block/features/checkout/default.test.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 { render, screen, act } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
|
||
import { useIdentity, usePhrases } from "@wpmedia/arc-themes-components"; | ||
import useSales from "../../components/useSales"; | ||
import Checkout from "./default"; | ||
|
||
jest.mock("@wpmedia/arc-themes-components"); | ||
jest.mock("../../components/useSales"); | ||
|
||
const assignMock = jest.fn(() => "checkoutURL"); | ||
delete window.location; | ||
window.location = { assign: assignMock, href: "checkoutURL" }; | ||
|
||
describe("Checkout Feature", () => { | ||
afterEach(() => { | ||
assignMock.mockClear(); | ||
}) | ||
it("show billing address card when user is logged in", async () => { | ||
useIdentity.mockImplementation(() => ({ | ||
getSignedInIdentity: jest.fn( | ||
(user) => | ||
user?.identities?.reduce((prev, current) => | ||
prev.lastLoginDate > current.lastLoginDate ? prev : current, | ||
) || null, | ||
), | ||
Identity: { | ||
isLoggedIn: jest.fn(async () => true), | ||
getUserProfile: jest.fn(async () => {}) | ||
}, | ||
})); | ||
|
||
usePhrases.mockImplementation(() => ({ | ||
t: jest.fn((phrase => phrase)) | ||
})) | ||
|
||
useSales.mockReturnValue({ | ||
Sales: {}, | ||
}); | ||
|
||
await act(async () => { | ||
render( | ||
<Checkout | ||
customFields={{ | ||
offerURL: "/offer-url/" | ||
}} | ||
/>, | ||
); | ||
}); | ||
expect(screen.getByText("Billing Address Placeholder")).not.toBeNull(); | ||
}); | ||
it("redirects user to login url when user is not logged in", async () => { | ||
useIdentity.mockImplementation(() => ({ | ||
getSignedInIdentity: jest.fn( | ||
(user) => | ||
user?.identities?.reduce((prev, current) => | ||
prev.lastLoginDate > current.lastLoginDate ? prev : current, | ||
) || null, | ||
), | ||
Identity: { | ||
isLoggedIn: jest.fn(async () => false), | ||
getUserProfile: jest.fn(async () => {}) | ||
}, | ||
})); | ||
|
||
usePhrases.mockImplementation(() => ({ | ||
t: jest.fn((phrase => phrase)) | ||
})) | ||
|
||
useSales.mockReturnValue({ | ||
Sales: {}, | ||
}); | ||
|
||
await act(async () => { | ||
render( | ||
<Checkout | ||
customFields={{ | ||
loginURL: "/login-url/", | ||
}} | ||
/>, | ||
); | ||
}); | ||
expect(screen.getByText("Account Placeholder")).not.toBeNull(); | ||
expect(window.location.href).toBe("/login-url/?redirect=checkoutURL"); | ||
}); | ||
}); |