Skip to content

Commit

Permalink
Port product-price test cases from template-compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
jmariconda committed Nov 26, 2024
1 parent 63385a8 commit 4aea92e
Show file tree
Hide file tree
Showing 44 changed files with 1,295 additions and 38 deletions.
142 changes: 136 additions & 6 deletions __tests__/plugins/formatters.commerce.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ loader.paths('f-product-quick-view-%N.html').forEach((path) => {
test(`product quick view - ${path}`, () => loader.execute(path));
});

// TODO product-price

// loader.paths('f-product-price-%N.html', 8).forEach((path) => {
// test(`product price - ${path}`, () => loader.execute(path));
// });

loader.paths('f-product-restock-notification-%N.html').forEach((path) => {
test(`product-restock-notification - ${path}`, () => loader.execute(path));
});
Expand Down Expand Up @@ -170,3 +164,139 @@ loader.paths('f-subscription-price-variants-with-same-pricing.html').forEach((pa
loader.paths('f-subscription-price-no-pricing-options.html').forEach((path) => {
test(`subscription price no pricing options - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-%N.html').forEach((path) => {
test(`product price - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-weekly.html').forEach((path) => {
test(`product price subscription weekly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-bi-weekly.html').forEach((path) => {
test(`product price subscription bi-weekly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-monthly.html').forEach((path) => {
test(`product price subscription monthly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-bi-monthly.html').forEach((path) => {
test(`product price subscription bi-monthly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-from-weekly.html').forEach((path) => {
test(`product price subscription from weekly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-from-bi-weekly.html').forEach((path) => {
test(`product price subscription from bi-weekly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-from-monthly.html').forEach((path) => {
test(`product price subscription from monthly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-from-bi-monthly.html').forEach((path) => {
test(`product price subscription from bi-monthly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-from-weekly-on-sale.html').forEach((path) => {
test(`product price subscription from weekly on-sale - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-on-sale-bi-monthly.html').forEach((path) => {
test(`product price subscription on-sale bi-monthly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-on-sale-bi-weekly.html').forEach((path) => {
test(`product price subscription on-sale bi-weekly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-on-sale-monthly.html').forEach((path) => {
test(`product price subscription on-sale monthly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-on-sale-weekly.html').forEach((path) => {
test(`product price subscription on-sale weekly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-weekly-localized.html').forEach((path) => {
test(`product price subscription weekly localized - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-weekly-localized-multiple.html').forEach((path) => {
test(`product price subscription weekly localized multiple - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-weekly.html').forEach((path) => {
test(`product price finite subscription weekly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-bi-weekly.html').forEach((path) => {
test(`product price finite subscription bi-weekly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-monthly.html').forEach((path) => {
test(`product price finite subscription monthly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-bi-monthly.html').forEach((path) => {
test(`product price finite subscription bi-monthly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-bi-weekly-for-a-year.html').forEach((path) => {
test(`product price finite subscription bi-weekly for a year - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-monthly-for-a-year.html').forEach((path) => {
test(`product price finite subscription monthly for a year - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-from-weekly.html').forEach((path) => {
test(`product price finite subscription from weekly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-from-bi-weekly.html').forEach((path) => {
test(`product price finite subscription from bi-weekly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-from-monthly.html').forEach((path) => {
test(`product price finite subscription from monthly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-from-bi-monthly.html').forEach((path) => {
test(`product price finite subscription from bi-monthly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-from-weekly-on-sale.html').forEach((path) => {
test(`product price finite subscription from weekly on-sale - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-on-sale-bi-monthly.html').forEach((path) => {
test(`product price finite subscription on-sale bi-monthly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-on-sale-bi-weekly.html').forEach((path) => {
test(`product price finite subscription on-sale bi-weekly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-on-sale-monthly.html').forEach((path) => {
test(`product price finite subscription on-sale monthly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-on-sale-weekly.html').forEach((path) => {
test(`product price finite subscription on-sale weekly - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-weekly-localized.html').forEach((path) => {
test(`product price finite subscription weekly localized - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-finite-subscription-weekly-localized-multiple.html').forEach((path) => {
test(`product price finite subscription weekly localized multiple - ${path}`, () => loader.execute(path));
});

loader.paths('f-product-price-subscription-weekly-plan-unavailable.html').forEach((path) => {
test(`product price subscription weekly plan unavailable - ${path}`, () => loader.execute(path));
});
9 changes: 6 additions & 3 deletions __tests__/plugins/resources/f-product-price-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"structuredContent": {
"productType": 1,
"variants": [
{"price": 10000},
{"price": 20000}
{"price": 10000, "priceMoney": { "value": "100" } },
{"price": 20000, "priceMoney": { "value": "200" } }
]
}
}
Expand All @@ -13,4 +13,7 @@
{@|product-price}

:OUTPUT
<div class="product-price">from <span class="sqs-money-native">100.00</span></div>
<div class="product-price">
from <span class="sqs-money-native">100.00</span>

</div>
29 changes: 29 additions & 0 deletions __tests__/plugins/resources/f-product-price-10.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
:PARAMS
{
"locale": "de-DE"
}

:JSON
{
"structuredContent": {
"productType": 2,
"priceMoney": {
"value": "2500",
"currency": "EUR"
}
},
"website": {
"useCLDRMoneyFormat": true
},
"featureFlags": {
"useCLDRMoneyFormat": true
}
}

:TEMPLATE
{@|product-price}

:OUTPUT
<div class="product-price">
2.500,00 €
</div>
9 changes: 6 additions & 3 deletions __tests__/plugins/resources/f-product-price-2.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"structuredContent": {
"productType": 1,
"variants": [
{"price": 10000},
{"onSale": true, "salePrice": 5000}
{"price": 10000, "priceMoney": { "value": "100" } },
{"onSale": true, "salePrice": 5000, "salePriceMoney": { "value": "50" } }
]
}
}
Expand All @@ -13,4 +13,7 @@
{@|product-price}

:OUTPUT
<div class="product-price">from <span class="sqs-money-native">50.00</span></div>
<div class="product-price">
from <span class="sqs-money-native">50.00</span>

</div>
7 changes: 4 additions & 3 deletions __tests__/plugins/resources/f-product-price-3.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"structuredContent": {
"productType": 1,
"variants": [
{"onSale": true, "salePrice": 5000, "price": 10000}
{"onSale": true, "salePriceMoney": { "value": "50.00" }, "priceMoney": { "value": "100.00" } }
]
}
}
Expand All @@ -12,6 +12,7 @@
{@|product-price}

:OUTPUT
<div class="product-price"><span class="sqs-money-native">50.00</span> <span class="original-price"><span class="sqs-money-native">100.00</span></span></div>

<div class="product-price">
<span class="visually-hidden v6-visually-hidden">Sale Price:</span><span class="sqs-money-native">50.00</span> <span class="visually-hidden v6-visually-hidden">Original Price:</span><span class="original-price"><span class="sqs-money-native">100.00</span></span>

</div>
7 changes: 4 additions & 3 deletions __tests__/plugins/resources/f-product-price-4.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"structuredContent": {
"productType": 1,
"variants": [
{"price": 20000}
{"priceMoney": { "value": "200.00" } }
]
}
}
Expand All @@ -12,5 +12,6 @@
{@|product-price}

:OUTPUT
<div class="product-price"><span class="sqs-money-native">200.00</span></div>

<div class="product-price">
<span class="sqs-money-native">200.00</span>
</div>
7 changes: 4 additions & 3 deletions __tests__/plugins/resources/f-product-price-5.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
{
"structuredContent": {
"productType": 2,
"priceCents": 20000
"priceMoney": { "value": "200" }
}
}

:TEMPLATE
{@|product-price}

:OUTPUT
<div class="product-price"><span class="sqs-money-native">200.00</span></div>

<div class="product-price">
<span class="sqs-money-native">200.00</span>
</div>
9 changes: 5 additions & 4 deletions __tests__/plugins/resources/f-product-price-6.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"structuredContent": {
"productType": 2,
"onSale": true,
"priceCents": 40000,
"salePriceCents": 20000
"priceMoney": { "value": "400.00" },
"salePriceMoney": { "value": "200.00" }
}
}

:TEMPLATE
{@|product-price}

:OUTPUT
<div class="product-price"><span class="sqs-money-native">200.00</span> <span class="original-price"><span class="sqs-money-native">400.00</span></span></div>

<div class="product-price">
<span class="visually-hidden v6-visually-hidden">Sale Price:</span><span class="sqs-money-native">200.00</span> <span class="visually-hidden v6-visually-hidden">Original Price:</span><span class="original-price"><span class="sqs-money-native">400.00</span></span>

</div>
3 changes: 2 additions & 1 deletion __tests__/plugins/resources/f-product-price-7.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
{@|product-price}

:OUTPUT
<div class="product-price"></div>
<div class="product-price">

</div>
28 changes: 16 additions & 12 deletions __tests__/plugins/resources/f-product-price-8.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@

:JSON
{
"structuredContent": {
"productType": 1,
"variants": [
{"price": 10000},
{"price": 20000}
]
},
"localizedStrings": {
"productPriceStartingFromText": "hello {0}"
}
"structuredContent": {
"productType": 2,
"priceMoney": {
"value": "2500",
"currency": "USD"
}
},
"website": {
"useCLDRMoneyFormat": true
},
"featureFlags": {
"useCLDRMoneyFormat": true
}
}

:TEMPLATE
{@|product-price}

:OUTPUT
<div class="product-price">hello <span class="sqs-money-native">100.00</span></div>
<div class="product-price">
$2,500.00
</div>
24 changes: 24 additions & 0 deletions __tests__/plugins/resources/f-product-price-9.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
:JSON
{
"structuredContent": {
"productType": 2,
"priceMoney": {
"value": "2500",
"currency": "EUR"
}
},
"website": {
"useCLDRMoneyFormat": true
},
"featureFlags": {
"useCLDRMoneyFormat": true
}
}

:TEMPLATE
{@|product-price}

:OUTPUT
<div class="product-price">
€2,500.00
</div>
Loading

0 comments on commit 4aea92e

Please sign in to comment.