-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Store Orders: Update status labels for "cash on delivery" orders #18983
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
95ec7f3
Refactor & add tests for `OrderStatus`
ryelle 7d81194
Pass whole order object through to OrderStatus, so that we can check …
ryelle 30da2ed
Switch places component is used to pass through the order object
ryelle 1f6fa9d
Update payment string
ryelle 621bdb0
Fix status variable (now inside order) so the classes are applied cor…
ryelle b2d14d5
Update payment card for cash-on-delivery orders
ryelle 631f23c
Remove unused `method` from translate call
ryelle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
114 changes: 71 additions & 43 deletions
114
client/extensions/woocommerce/components/order-status/index.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 |
---|---|---|
@@ -1,52 +1,80 @@ | ||
/** @format */ | ||
/** | ||
* External dependencies | ||
* | ||
* @format | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { localize } from 'i18n-calypso'; | ||
import React from 'react'; | ||
|
||
function OrderStatus( { showPayment = true, showShipping = true, status, translate } ) { | ||
const classes = `order-status__item is-${ status }`; | ||
let paymentLabel; | ||
let shippingLabel; | ||
switch ( status ) { | ||
case 'pending': | ||
shippingLabel = translate( 'New order' ); | ||
paymentLabel = translate( 'Payment pending' ); | ||
break; | ||
case 'processing': | ||
shippingLabel = translate( 'New order' ); | ||
paymentLabel = translate( 'Paid in full' ); | ||
break; | ||
case 'on-hold': | ||
shippingLabel = translate( 'On hold' ); | ||
paymentLabel = translate( 'Payment pending' ); | ||
break; | ||
case 'completed': | ||
shippingLabel = translate( 'Fulfilled' ); | ||
paymentLabel = translate( 'Paid in full' ); | ||
break; | ||
case 'cancelled': | ||
paymentLabel = translate( 'Cancelled' ); | ||
break; | ||
case 'refunded': | ||
paymentLabel = translate( 'Refunded' ); | ||
break; | ||
case 'failed': | ||
paymentLabel = translate( 'Payment failed' ); | ||
break; | ||
} | ||
export class OrderStatus extends Component { | ||
static propTypes = { | ||
order: PropTypes.shape( { | ||
payment_method: PropTypes.string, | ||
status: PropTypes.string.isRequired, | ||
} ), | ||
showPayment: PropTypes.bool, | ||
showShipping: PropTypes.bool, | ||
translate: PropTypes.func.isRequired, | ||
}; | ||
|
||
getPaymentLabel = () => { | ||
const { order, translate } = this.props; | ||
const { status, payment_method } = order; | ||
switch ( status ) { | ||
case 'pending': | ||
case 'on-hold': | ||
return translate( 'Payment pending' ); | ||
case 'processing': | ||
if ( 'cod' === payment_method ) { | ||
return translate( 'Paid on delivery' ); | ||
} | ||
return translate( 'Paid in full' ); | ||
case 'completed': | ||
return translate( 'Paid in full' ); | ||
case 'cancelled': | ||
return translate( 'Cancelled' ); | ||
case 'refunded': | ||
return translate( 'Refunded' ); | ||
case 'failed': | ||
return translate( 'Payment failed' ); | ||
} | ||
return false; | ||
}; | ||
|
||
getShippingLabel = () => { | ||
const { order, translate } = this.props; | ||
switch ( order.status ) { | ||
case 'pending': | ||
case 'processing': | ||
return translate( 'New order' ); | ||
case 'on-hold': | ||
return translate( 'On hold' ); | ||
case 'completed': | ||
return translate( 'Fulfilled' ); | ||
} | ||
return false; | ||
}; | ||
|
||
return ( | ||
<span className={ classes }> | ||
{ shippingLabel && showShipping ? ( | ||
<span className="order-status__shipping">{ shippingLabel }</span> | ||
) : null } | ||
{ showPayment ? <span className="order-status__payment">{ paymentLabel }</span> : null } | ||
</span> | ||
); | ||
render() { | ||
const { order: { status }, showPayment = true, showShipping = true } = this.props; | ||
const classes = `order-status__item is-${ status }`; | ||
const paymentLabel = this.getPaymentLabel(); | ||
const shippingLabel = this.getShippingLabel(); | ||
|
||
// Status was unrecognized, there is no label content to display | ||
if ( ! shippingLabel && ! paymentLabel ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<span className={ classes }> | ||
{ shippingLabel && showShipping ? ( | ||
<span className="order-status__shipping">{ shippingLabel }</span> | ||
) : null } | ||
{ showPayment ? <span className="order-status__payment">{ paymentLabel }</span> : null } | ||
</span> | ||
); | ||
} | ||
} | ||
|
||
export default localize( OrderStatus ); |
79 changes: 79 additions & 0 deletions
79
client/extensions/woocommerce/components/order-status/test/index.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,79 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice! |
||
* External dependencies | ||
* | ||
* @format | ||
*/ | ||
|
||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { identity } from 'lodash'; | ||
import { shallow } from 'enzyme'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { OrderStatus } from '../'; | ||
|
||
describe( 'OrderStatus', () => { | ||
test( 'should render a label with shipping and payment content', () => { | ||
const order = { | ||
status: 'pending', | ||
payment_method: 'paypal', | ||
}; | ||
const wrapper = shallow( <OrderStatus order={ order } translate={ identity } /> ); | ||
expect( wrapper.find( '.order-status__item' ) ).to.have.length( 1 ); | ||
expect( wrapper.find( '.order-status__item' ).hasClass( 'is-pending' ) ).to.equal( true ); | ||
expect( wrapper.find( '.order-status__shipping' ) ).to.have.length( 1 ); | ||
expect( wrapper.find( '.order-status__payment' ) ).to.have.length( 1 ); | ||
} ); | ||
|
||
test( 'should render only payment label when showShipping is false', () => { | ||
const order = { status: 'pending' }; | ||
const wrapper = shallow( | ||
<OrderStatus order={ order } showShipping={ false } translate={ identity } /> | ||
); | ||
expect( wrapper.find( '.order-status__item' ) ).to.have.length( 1 ); | ||
expect( wrapper.find( '.order-status__shipping' ) ).to.have.length( 0 ); | ||
expect( wrapper.find( '.order-status__payment' ) ).to.have.length( 1 ); | ||
} ); | ||
|
||
test( 'should render only payment label when shipping does not apply to this status', () => { | ||
const order = { status: 'refunded' }; | ||
const wrapper = shallow( | ||
<OrderStatus order={ order } showShipping={ false } translate={ identity } /> | ||
); | ||
expect( wrapper.find( '.order-status__item' ) ).to.have.length( 1 ); | ||
expect( wrapper.find( '.order-status__item' ).hasClass( 'is-refunded' ) ).to.equal( true ); | ||
expect( wrapper.find( '.order-status__shipping' ) ).to.have.length( 0 ); | ||
expect( wrapper.find( '.order-status__payment' ) ).to.have.length( 1 ); | ||
} ); | ||
|
||
test( 'should render only shipping label when showPayment is false', () => { | ||
const order = { status: 'completed' }; | ||
const wrapper = shallow( | ||
<OrderStatus order={ order } showPayment={ false } translate={ identity } /> | ||
); | ||
expect( wrapper.find( '.order-status__item' ) ).to.have.length( 1 ); | ||
expect( wrapper.find( '.order-status__item' ).hasClass( 'is-completed' ) ).to.equal( true ); | ||
expect( wrapper.find( '.order-status__shipping' ) ).to.have.length( 1 ); | ||
expect( wrapper.find( '.order-status__payment' ) ).to.have.length( 0 ); | ||
} ); | ||
|
||
test( 'should render correct labels for a processing cash-on-delivery order', () => { | ||
const order = { | ||
status: 'processing', | ||
payment_method: 'cod', | ||
}; | ||
const wrapper = shallow( <OrderStatus order={ order } translate={ identity } /> ); | ||
expect( wrapper.find( '.order-status__item' ) ).to.have.length( 1 ); | ||
expect( wrapper.find( '.order-status__item' ).hasClass( 'is-processing' ) ).to.equal( true ); | ||
expect( wrapper.find( '.order-status__shipping' ).text() ).to.eql( 'New order' ); | ||
expect( wrapper.find( '.order-status__payment' ).text() ).to.eql( 'Paid on delivery' ); | ||
} ); | ||
|
||
test( 'should not render anything if the status is not recognized', () => { | ||
const order = { status: 'fake-status' }; | ||
const wrapper = shallow( <OrderStatus order={ order } translate={ identity } /> ); | ||
expect( wrapper.getNode() ).to.be.null; | ||
} ); | ||
} ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate logic from line 86, maybe we should extract it out - or just leave it - 6 one way, half dozen the other 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had the same thought, but then I'd have to write tests for another status function 😆