-
Notifications
You must be signed in to change notification settings - Fork 72
fix: attribute selection from PDPs with tokenized ECE #10306
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dd81f08
fix: attribute selection from PDPs with tokenized ECE
frosso 91fafd9
Merge branch 'develop' into fix/tokenized-ece-attribute-selection
frosso 41a8d97
Merge branch 'develop' into fix/tokenized-ece-attribute-selection
frosso 70decea
Merge branch 'develop' into fix/tokenized-ece-attribute-selection
frosso 3e4d683
further fix
frosso 72043d3
WIP tests
frosso 049ec12
more compatibility
frosso f4565b6
Merge branch 'develop' into fix/tokenized-ece-attribute-selection
frosso d555708
Merge branch 'develop' into fix/tokenized-ece-attribute-selection
brettshumaker 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 hidden or 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,4 @@ | ||
Significance: patch | ||
Type: fix | ||
|
||
fix: attribute selection from PDPs with tokenized ECE |
203 changes: 203 additions & 0 deletions
203
client/tokenized-express-checkout/compatibility/__tests__/wc-product-page.test.js
This file contains hidden or 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,203 @@ | ||
/* eslint-disable jsx-a11y/accessible-emoji */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { applyFilters } from '@wordpress/hooks'; | ||
import { render } from '@testing-library/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import '../wc-product-page'; | ||
|
||
describe( 'ECE product page compatibility', () => { | ||
it( 'returns the variation data', () => { | ||
render( | ||
<form className="variations_form"> | ||
<table className="variations" role="presentation"> | ||
<tbody> | ||
<tr> | ||
<th className="label"> | ||
<label htmlFor="pa_color">Color</label> | ||
</th> | ||
<td className="value"> | ||
<select | ||
id="pa_color" | ||
name="attribute_pa_color" | ||
data-attribute_name="attribute_pa_color" | ||
defaultValue="red" | ||
> | ||
<option value="">Choose an option</option> | ||
<option value="blue">Blue</option> | ||
<option value="green">Green</option> | ||
<option value="red">Red</option> | ||
</select> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th className="label"> | ||
<label htmlFor="logo">Logo</label> | ||
</th> | ||
<td className="value"> | ||
<select | ||
id="logo" | ||
name="attribute_logo" | ||
data-attribute_name="attribute_logo" | ||
defaultValue="Yes" | ||
> | ||
<option value="">Choose an option</option> | ||
<option value="Yes">Yes</option> | ||
<option value="No">No</option> | ||
</select> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<div className="single_variation_wrap"> | ||
<input type="hidden" name="product_id" value="10" /> | ||
</div> | ||
</form> | ||
); | ||
const productData = applyFilters( | ||
'wcpay.express-checkout.cart-add-item', | ||
{ | ||
variation: [], | ||
} | ||
); | ||
|
||
expect( productData ).toStrictEqual( { | ||
id: 10, | ||
variation: [ | ||
{ | ||
attribute: 'Color', | ||
value: 'red', | ||
}, | ||
{ | ||
attribute: 'attribute_pa_color', | ||
value: 'red', | ||
}, | ||
{ | ||
attribute: 'Logo', | ||
value: 'Yes', | ||
}, | ||
{ | ||
attribute: 'attribute_logo', | ||
value: 'Yes', | ||
}, | ||
], | ||
} ); | ||
} ); | ||
it( 'ensures compatibility with plugins modifying the DOM with additional markup', () => { | ||
// this markup is simulating the output of the "woo-variation-swatches" plugin. | ||
render( | ||
<form className="variations_form"> | ||
<table className="variations"> | ||
<tbody> | ||
<tr> | ||
<th className="label"> | ||
<label htmlFor="size%f0%9f%98%86"> | ||
Size😆 | ||
<span className="cfvsw-selected-label"> | ||
Medium | ||
</span> | ||
</label> | ||
</th> | ||
<td className="value woo-variation-items-wrapper"> | ||
<select | ||
id="size%f0%9f%98%86" | ||
name="attribute_size%f0%9f%98%86" | ||
data-attribute_name="attribute_size%f0%9f%98%86" | ||
defaultValue="Medium" | ||
> | ||
<option value="">Choose an option</option> | ||
<option value="Small">Small</option> | ||
<option value="Medium">Medium</option> | ||
</select> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th className="label"> | ||
<label htmlFor="color-%e2%9c%8f%ef%b8%8f"> | ||
Color ✏️ | ||
</label> | ||
<span>: Blue</span> | ||
</th> | ||
<td className="value woo-variation-items-wrapper"> | ||
<select | ||
id="color-%e2%9c%8f%ef%b8%8f" | ||
name="attribute_color-%e2%9c%8f%ef%b8%8f" | ||
data-attribute_name="attribute_color-%e2%9c%8f%ef%b8%8f" | ||
defaultValue="Green" | ||
> | ||
<option value="">Choose an option</option> | ||
<option value="Blue">Blue</option> | ||
<option value="Green">Green</option> | ||
</select> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th className="label"> | ||
<label htmlFor="autograph-choice-%e2%9c%8f%ef%b8%8f"> | ||
Autograph choice ✏️ | ||
</label> | ||
<span>: Yes 👍</span> | ||
</th> | ||
<td className="value woo-variation-items-wrapper"> | ||
<select | ||
id="autograph-choice-%e2%9c%8f%ef%b8%8f" | ||
name="attribute_autograph-choice-%e2%9c%8f%ef%b8%8f" | ||
data-attribute_name="attribute_autograph-choice-%e2%9c%8f%ef%b8%8f" | ||
defaultValue="Yes 👍" | ||
> | ||
<option value="">Choose an option</option> | ||
<option value="Yes 👍">Yes 👍</option> | ||
<option value="No 👎">No 👎</option> | ||
</select> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<div className="single_variation_wrap"> | ||
<input type="hidden" name="product_id" value="10" /> | ||
</div> | ||
</form> | ||
); | ||
const productData = applyFilters( | ||
'wcpay.express-checkout.cart-add-item', | ||
{ | ||
variation: [], | ||
} | ||
); | ||
|
||
expect( productData ).toStrictEqual( { | ||
id: 10, | ||
variation: [ | ||
{ | ||
attribute: 'Size😆', | ||
value: 'Medium', | ||
}, | ||
{ | ||
attribute: 'attribute_size%f0%9f%98%86', | ||
value: 'Medium', | ||
}, | ||
{ | ||
attribute: 'Color ✏️', | ||
value: 'Green', | ||
}, | ||
{ | ||
attribute: 'attribute_color-%e2%9c%8f%ef%b8%8f', | ||
value: 'Green', | ||
}, | ||
{ | ||
attribute: 'Autograph choice ✏️', | ||
value: 'Yes 👍', | ||
}, | ||
{ | ||
attribute: 'attribute_autograph-choice-%e2%9c%8f%ef%b8%8f', | ||
value: 'Yes 👍', | ||
}, | ||
], | ||
} ); | ||
} ); | ||
} ); |
This file contains hidden or 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
Oops, something went wrong.
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.
I moved away from the jQuery selectors and switched to vanilla JS selectors, so that testing would be more reliable and easier (without having to mock jQuery)