Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applied Gift Cards show current balance #2156

Merged
merged 5 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

exports[`it disables the button when in progress 1`] = `
Array [
<span>
unit test card code
</span>,
<div>
<span>
unit test card code
</span>
<span>
Balance:
<div />
</span>
</div>,
<button
disabled={true}
onClick={[MockFunction]}
Expand All @@ -16,9 +22,15 @@ Array [

exports[`it renders correctly 1`] = `
Array [
<span>
unit test card code
</span>,
<div>
<span>
unit test card code
</span>
<span>
Balance:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no balance in these snaps, not even a zero. Expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected because the value is rendered via the Price component, which gets mocked here to an empty <div /> (see next line).

<div />
</span>
</div>,
<button
disabled={false}
onClick={[MockFunction]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,52 @@
exports[`it renders correctly when it has cards 1`] = `
<div>
<div>
<span>
unit test code 1
</span>
<div>
<span>
unit test code 1
</span>
<span>
Balance:
<span>
$
</span>
<span>
99
</span>
<span>
.
</span>
<span>
00
</span>
</span>
Copy link
Contributor Author

@supernova-at supernova-at Feb 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sirugh I think this Price component doesn't get mocked because we requireActual Peregrine in this .spec.js. Apparently that will ignore mocks in __mocks__ 🤷‍♂

</div>
<button
disabled={false}
onClick={[Function]}
>
Remove
</button>
<span>
unit test code 2
</span>
<div>
<span>
unit test code 2
</span>
<span>
Balance:
<span>
$
</span>
<span>
99
</span>
<span>
.
</span>
<span>
00
</span>
</span>
</div>
<button
disabled={false}
onClick={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ jest.mock(
*/
const props = {
code: 'unit test card code',
removeGiftCard: jest.fn(),
isRemovingCard: false
currentBalance: {
currency: 'USD',
value: 99
},
isRemovingCard: false,
removeGiftCard: jest.fn()
};
const talonProps = {
removeGiftCardWithCode: jest.fn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,20 @@ test('it renders correctly when it has cards', () => {
const myTalonProps = {
...talonProps,
giftCardsData: [
{ code: 'unit test code 1' },
{ code: 'unit test code 2' }
{
code: 'unit test code 1',
current_balance: {
currency: 'USD',
value: 99
}
},
{
code: 'unit test code 2',
current_balance: {
currency: 'USD',
value: 99
}
}
]
};
useGiftCards.mockReturnValueOnce(myTalonProps);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
.card_info {
display: flex;
flex-direction: column;
}

.balance {
font-size: 0.875rem;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is computed based on the Venia Styleguide:

Screen Shot 2020-02-10 at 11 52 40 AM

Since we don't have CSS Properties (variables) for font sizes yet, 0.875rem = 14px.

}

.code {
}

.remove {
Expand Down
14 changes: 12 additions & 2 deletions packages/venia-ui/lib/components/CartPage/GiftCards/giftCard.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { Fragment } from 'react';

import { useGiftCard } from '@magento/peregrine/lib/talons/CartPage/GiftCards/useGiftCard';
import { Price } from '@magento/peregrine';

import { mergeClasses } from '../../../classify';
import defaultClasses from './giftCard.css';

const GiftCard = props => {
const { code, isRemovingCard, removeGiftCard } = props;
const { code, currentBalance, isRemovingCard, removeGiftCard } = props;

const { removeGiftCardWithCode } = useGiftCard({
code,
Expand All @@ -17,7 +18,16 @@ const GiftCard = props => {

return (
<Fragment>
<span className={classes.card_info}>{code}</span>
<div className={classes.card_info}>
<span className={classes.code}>{code}</span>
<span className={classes.balance}>
{`Balance: `}
<Price
value={currentBalance.value}
currencyCode={currentBalance.currency}
/>
</span>
</div>
<button
className={classes.remove}
disabled={isRemovingCard}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export const GiftCardFragment = gql`
fragment GiftCardFragment on Cart {
applied_gift_cards {
code
current_balance {
currency
value
}
}
id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ const GiftCards = props => {
let appliedGiftCards = null;
if (giftCardsData.length > 0) {
const cardList = giftCardsData.map(giftCardData => {
const { code } = giftCardData;
const { code, current_balance } = giftCardData;

return (
<GiftCard
code={code}
removeGiftCard={removeGiftCard}
currentBalance={current_balance}
isRemovingCard={isRemovingCard}
key={code}
removeGiftCard={removeGiftCard}
/>
);
});
Expand Down