Skip to content

Commit 2210e2a

Browse files
committed
HP-2804: refactor e2e test and presenters for progressive price handling
- Updated `progressive-price.spec.ts` to improve string formatting and enhance price assertions. - Refined `TemplatePricePresenter` and `CertificatePricePresenter` to utilize `RepresentablePrice` for improved type consistency. - Added exception annotations (`InvalidConfigException`, `NotInstantiableException`) for better error handling. - Enhanced overall code clarity and consistency.
1 parent a80ddb2 commit 2210e2a

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

src/grid/presenters/price/CertificatePricePresenter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
namespace hipanel\modules\finance\grid\presenters\price;
1212

13-
use hipanel\modules\finance\models\Price;
13+
use hipanel\modules\finance\models\CertificatePrice;
14+
use hipanel\modules\finance\models\RepresentablePrice;
1415
use Money\MoneyFormatter;
1516
use yii\i18n\Formatter;
1617
use yii\web\User;
@@ -32,13 +33,13 @@ public function __construct(Formatter $formatter, User $user, MoneyFormatter $mo
3233
}
3334

3435
/**
35-
* @param \hipanel\modules\finance\models\CertificatePrice $price
36+
* @param CertificatePrice $price
3637
* @return string
3738
*/
38-
public function renderPrice(Price $price): string
39+
public function renderPrice(RepresentablePrice $price): string
3940
{
4041
$result = [];
41-
foreach ($price->sums as $period => $amount) {
42+
foreach ($price->sums as $amount) {
4243
$result[] = $this->moneyFormatter->format($amount);
4344
}
4445

src/grid/presenters/price/TemplatePricePresenter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
namespace hipanel\modules\finance\grid\presenters\price;
1212

1313
use hipanel\helpers\StringHelper;
14-
use hipanel\modules\finance\models\Price;
14+
use hipanel\modules\finance\models\RepresentablePrice;
15+
use hipanel\modules\finance\models\TemplatePrice;
1516
use Yii;
1617
use yii\base\InvalidConfigException;
18+
use yii\di\NotInstantiableException;
1719
use yii\helpers\Html;
1820

1921
/**
@@ -24,10 +26,12 @@
2426
class TemplatePricePresenter extends PricePresenter
2527
{
2628
/**
27-
* @param \hipanel\modules\finance\models\TemplatePrice $price
29+
* @param TemplatePrice $price
2830
* @return string
31+
* @throws InvalidConfigException
32+
* @throws NotInstantiableException
2933
*/
30-
public function renderPrice(Price $price): string
34+
public function renderPrice(RepresentablePrice $price): string
3135
{
3236
$formatter = Yii::$app->formatter;
3337

tests/playwright/e2e/manager/progressive-price.spec.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PriceHelper from "@hipanel-module-finance/Helper/PriceHelper";
44
import ViewTableHelper from "@hipanel-module-finance/Helper/ViewTableHelper";
55

66
test("Test the Progressive Price feature works @hipanel-module-finance @manager", {
7-
tag: '@dedicated-server',
7+
tag: "@dedicated-server",
88
}, async ({ page }) => {
99
const planName = "TEST-PROGRESSIVE-PRICE-TEMPLATE" + Math.random().toString(36).substring(7);
1010
const priceHelper = new PriceHelper(page);
@@ -14,13 +14,18 @@ test("Test the Progressive Price feature works @hipanel-module-finance @manager"
1414

1515
await expect(page.locator("h1")).toContainText(planName);
1616

17-
await viewTable.assertCellEquals('Name', planName);
18-
await viewTable.assertCellEquals('Type', 'template');
19-
await viewTable.assertCellEquals('Status', 'ok');
17+
await viewTable.assertCellEquals("Name", planName);
18+
await viewTable.assertCellEquals("Type", "template");
19+
await viewTable.assertCellEquals("Status", "ok");
2020

2121
await priceHelper.createProgressivePrice(planName);
2222

23-
await expect(page.getByRole("cell", { name: "$30.00 per Item over 0 Item $0.0085 per Item over 1 Item $0.008 per Item over 2 Item $0.0075 per Item over 3 Item" })).toBeVisible();
23+
await expect(page.getByRole("cell", {
24+
name: "First 1 Item $30.00 "
25+
+ "Next 1 Item $0.0085 (-100%) "
26+
+ "Next 1 Item $0.008 (-6%) "
27+
+ "Over 3 Item $0.0075 (-6%) ",
28+
})).toBeVisible();
2429

2530
await expect(page.getByText("Number of IPs")).toBeVisible();
2631

@@ -30,9 +35,9 @@ test("Test the Progressive Price feature works @hipanel-module-finance @manager"
3035

3136
await priceHelper.deleteProgressivePriceItems();
3237

33-
await page.locator('input[name="selection_all"]').check();
38+
await page.locator("input[name=\"selection_all\"]").check();
3439
await page.getByRole("button", { name: "Update" }).click();
35-
await expect( page.locator('input#templateprice-0-class')).toBeHidden();
40+
await expect(page.locator("input#templateprice-0-class")).toBeHidden();
3641
await page.getByRole("button", { name: "Cancel" }).click();
3742

3843
await page.getByTestId("delete").click();

0 commit comments

Comments
 (0)