Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 5 additions & 4 deletions src/grid/presenters/price/CertificatePricePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

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

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

/**
* @param \hipanel\modules\finance\models\CertificatePrice $price
* @param CertificatePrice $price
* @return string
*/
public function renderPrice(Price $price): string
public function renderPrice(RepresentablePrice $price): string
{
$result = [];
foreach ($price->sums as $period => $amount) {
foreach ($price->sums as $amount) {
$result[] = $this->moneyFormatter->format($amount);
}

Expand Down
10 changes: 7 additions & 3 deletions src/grid/presenters/price/TemplatePricePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
namespace hipanel\modules\finance\grid\presenters\price;

use hipanel\helpers\StringHelper;
use hipanel\modules\finance\models\Price;
use hipanel\modules\finance\models\RepresentablePrice;
use hipanel\modules\finance\models\TemplatePrice;
use Yii;
use yii\base\InvalidConfigException;
use yii\di\NotInstantiableException;
use yii\helpers\Html;

/**
Expand All @@ -24,10 +26,12 @@
class TemplatePricePresenter extends PricePresenter
{
/**
* @param \hipanel\modules\finance\models\TemplatePrice $price
* @param TemplatePrice $price
* @return string
* @throws InvalidConfigException
* @throws NotInstantiableException
*/
public function renderPrice(Price $price): string
public function renderPrice(RepresentablePrice $price): string
{
$formatter = Yii::$app->formatter;

Expand Down
5 changes: 2 additions & 3 deletions tests/playwright/e2e/client/account-recharging.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { test } from "@hipanel-core/fixtures";
import { expect } from "@playwright/test";
import { expect, test } from "@hipanel-core/fixtures";

test("Test the Account recharging page works @hipanel-module-finance @client @seller", async ({ clientPage, sellerPage }) => {
const pageUrl = "/merchant/pay/deposit";
for (let page of [clientPage, sellerPage]) {
await page.goto(pageUrl);
await expect(page).toHaveTitle("Account recharging");
await expect(page.locator("//input[@id='depositform-amount']")).toBeVisible();
await expect(page.getByRole('button', { name: 'Proceed' })).toBeVisible();
await expect(page.getByRole("button", { name: "Proceed" })).toBeVisible();
await expect(page.locator("h4:text('Important information')")).toBeVisible();
await expect(page.locator("p:text('Remember to return to the site after successful payment!')")).toBeVisible();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/playwright/e2e/manager/currency-exchange.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from "@hipanel-core/fixtures";
import { expect } from "@playwright/test";
import Select2 from "@hipanel-core/input/Select2";
import Alert from "@hipanel-core/ui/Alert";
import { Alert } from "@hipanel-core/shared/ui/components";
import AdvancedSearch from "@hipanel-core/helper/AdvancedSearch";

test("the currency exchange operation works and creates a bill @hipanel-module-finance @manager", async ({ page }) => {
Expand All @@ -28,7 +28,7 @@ test("the currency exchange operation works and creates a bill @hipanel-module-f

await advancedSearch.setFilter("client_id", "hipanel_test_user");
await advancedSearch.setFilter("descr", "Exchanging 200.00 USD");
await advancedSearch.submitButton();
await advancedSearch.search();

await page.locator("div[role=grid] a:has-text(\"-$200.00\")").first().click();

Expand Down
19 changes: 12 additions & 7 deletions tests/playwright/e2e/manager/progressive-price.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PriceHelper from "@hipanel-module-finance/Helper/PriceHelper";
import ViewTableHelper from "@hipanel-module-finance/Helper/ViewTableHelper";

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

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

await viewTable.assertCellEquals('Name', planName);
await viewTable.assertCellEquals('Type', 'template');
await viewTable.assertCellEquals('Status', 'ok');
await viewTable.assertCellEquals("Name", planName);
await viewTable.assertCellEquals("Type", "template");
await viewTable.assertCellEquals("Status", "ok");

await priceHelper.createProgressivePrice(planName);

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();
await expect(page.getByRole("cell", {
name: "First 1 Item $30.00 "
+ "Next 1 Item $0.0085 (-100%) "
+ "Next 1 Item $0.008 (-6%) "
+ "Over 3 Item $0.0075 (-6%) ",
})).toBeVisible();

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

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

await priceHelper.deleteProgressivePriceItems();

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

await page.getByTestId("delete").click();
Expand Down
2 changes: 1 addition & 1 deletion tests/playwright/e2e/sales.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ServerView from "@hipanel-module-finance/page/bill/ServerView";
import SaleHelper from "@hipanel-module-finance/Helper/SaleHelper";
import Index from "@hipanel-core/page/Index";
import SaleUpdate from "@hipanel-module-finance/page/bill/SaleUpdate";
import Alert from "@hipanel-core/ui/Alert";
import { Alert } from "@hipanel-core/shared/ui/components";
import DateHelper from "@hipanel-core/helper/DateHelper";

const sales: Array<Sale> = [
Expand Down
3 changes: 1 addition & 2 deletions tests/playwright/e2e/seller/bill-copy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import BillForm from "@hipanel-module-finance/page/bill/BillForm";
import BillHelper from "@hipanel-module-finance/Helper/BillHelper";
import Bill from "@hipanel-module-finance/model/Bill";
import Index from "@hipanel-core/page/Index";
import Alert from "@hipanel-core/ui/Alert";
import { Alert } from "@hipanel-core/shared/ui/components";

const bill: Bill = {
client: "hipanel_test_user",
Expand Down Expand Up @@ -48,4 +48,3 @@ test("Create and copy bill with charges @hipanel-module-finance @seller", async
await billHelper.ensureBillDidntChange(bill, billId);

});

3 changes: 1 addition & 2 deletions tests/playwright/e2e/seller/bill-creation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@hipanel-core/fixtures";
import BillForm from "@hipanel-module-finance/page/bill/BillForm";
import Alert from "@hipanel-core/ui/Alert";
import { Alert } from "@hipanel-core/shared/ui/components";

let billId;

Expand Down Expand Up @@ -92,4 +92,3 @@ test.describe("Bill creation", () => {
await expect(page.locator(`table >> text=${chargeDescr}`)).toBeVisible();
});
});

2 changes: 1 addition & 1 deletion tests/playwright/e2e/seller/bill-with-charges.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@hipanel-core/fixtures";
import BillForm from "@hipanel-module-finance/page/bill/BillForm";
import Alert from "@hipanel-core/ui/Alert";
import { Alert } from "@hipanel-core/shared/ui/components";
import BillView from "@hipanel-module-finance/page/bill/BillView";

test("Test we add the charges to created bill @hipanel-module-finance @seller", async ({ page }) => {
Expand Down
22 changes: 12 additions & 10 deletions tests/playwright/e2e/seller/generate-invoice.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { test, expect } from "@hipanel-core/fixtures";
import { expect, test } from "@hipanel-core/fixtures";
import { Page } from "@playwright/test";
import BillForm from "@hipanel-module-finance/page/bill/BillForm";
import BillView from "@hipanel-module-finance/page/bill/BillView";
import Alert from "@hipanel-core/ui/Alert";
import { Alert } from "@hipanel-core/shared/ui/components";
import Index from "@hipanel-core/page/Index";
import Select2 from "@hipanel-core/input/Select2";
import Bill from "@hipanel-module-finance/model/Bill";

const bill = {
const bill: Bill = {
client: "hipanel_test_user",
type: "Positive balance correction",
requisite: "Test Reseller",
Expand All @@ -14,7 +16,7 @@ const bill = {
quantity: 1,
};

async function createBill(page) {
async function createBill(page: Page) {
await page.goto("/finance/bill/create");
const form = new BillForm(page);
await form.fill([bill]);
Expand All @@ -24,29 +26,29 @@ async function createBill(page) {
return await form.getSavedBillId();
}

async function deleteBill(page, billId) {
async function deleteBill(page: Page, billId) {
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add type annotation for billId parameter.

The billId parameter lacks a type annotation, which is inconsistent with the type safety improvements made elsewhere in this file (e.g., page: Page annotations).

Apply this diff to add the missing type:

-async function deleteBill(page: Page, billId) {
+async function deleteBill(page: Page, billId: string | number) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async function deleteBill(page: Page, billId) {
async function deleteBill(page: Page, billId: string | number) {
🤖 Prompt for AI Agents
In tests/playwright/e2e/seller/generate-invoice.spec.ts around line 29, the
deleteBill function signature is missing a type annotation for the billId
parameter; update the function declaration to add an explicit type for billId
(e.g., billId: string) so it matches the file's type-safety conventions, and
update any callers if necessary to ensure they pass the correctly typed value.

await page.goto("/finance/bill/view?id=" + billId);
const viewPage = await new BillView(page);
const viewPage = new BillView(page);
await viewPage.detailMenuItem("Delete", true).click();

// Handle the confirmation alert
await page.once("dialog", async (dialog) => {
page.once("dialog", async (dialog) => {
await dialog.accept();
});

await Alert.on(page).hasText("Payment was deleted successfully");
}

test("Test 'Generate invoice' button is work and the form opens @hipanel-module-finance @seller", {
tag: '@missing-requisites',
tag: "@missing-requisites",
}, async ({ page }) => {
const billId = await createBill(page);
const action = '/finance/bill/index';
const action = "/finance/bill/index";

await page.goto(action);
const index = new Index(page);
await Select2.fieldByName(page, `BillSearch[requisite_id]`).setValue(bill.requisite);
await index.advancedSearch.submitButton();
await index.advancedSearch.search();

const rowNumber = await index.getRowNumberInColumnByValue("Description", bill.requisite);
await index.chooseNumberRowOnTable(rowNumber);
Expand Down
3 changes: 1 addition & 2 deletions tests/playwright/e2e/seller/internal-transfer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import BillHelper from "@hipanel-module-finance/Helper/BillHelper";
import Bill from "@hipanel-module-finance/model/Bill";
import TransferForm from "@hipanel-module-finance/page/bill/TransferForm";
import Transfer from "@hipanel-module-finance/model/Transfer";
import Alert from "@hipanel-core/ui/Alert";
import { Alert } from "@hipanel-core/shared/ui/components";

const transfer: Transfer = {
sum: 100,
Expand Down Expand Up @@ -52,4 +52,3 @@ test("Ensure transfer is working correctly @hipanel-module-finance @seller", asy
await transferForm.submit();
await Alert.on(sellerPage).hasText('Transfer was completed');
});

2 changes: 1 addition & 1 deletion tests/playwright/e2e/seller/toggle-sign.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from "@hipanel-core/fixtures";
import { expect } from "@playwright/test";
import BillForm from "@hipanel-module-finance/page/bill/BillForm";
import Alert from "@hipanel-core/ui/Alert";
import { Alert } from "@hipanel-core/shared/ui/components";

const bill = {
client: "hipanel_test_user",
Expand Down
26 changes: 13 additions & 13 deletions tests/playwright/model/Bill.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Charge from "@hipanel-module-finance/model/Charge";
import Charge from "./Charge";

export default class Bill {
public client: string;
public type: string;
public currency: string;
public sum: number;
public quantity: number;
public requisite?: string;
public time?: string | null;
public description?: string | null;
public class?: string | null;
public object?: string | null;
public charges?: Array<Charge> | null;
export default interface Bill {
client: string;
type: string;
currency: string;
sum: number;
quantity: number;
requisite?: string;
time?: string | null;
description?: string | null;
class?: string | null;
object?: string | null;
charges?: Array<Charge> | null;
}
16 changes: 8 additions & 8 deletions tests/playwright/model/Charge.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default class Charge {
public class: string;
public object: string;
public type: string;
public quantity: number;
public sum: number;
public description?: string | null;
public time?: string | null;
export default interface Charge {
class: string;
object: string;
type: string;
quantity: number;
sum: number;
description?: string | null;
time?: string | null;
}
12 changes: 6 additions & 6 deletions tests/playwright/model/Sale.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default class Sale {
public client: string;
public tariff: string;
public column: string;
public server: string;
public type: string;
export default interface Sale {
client: string;
tariff: string;
column: string;
server: string;
type: string;
}
12 changes: 5 additions & 7 deletions tests/playwright/model/Transfer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Bill from "@hipanel-module-finance/model/Bill";

export default class Transfer {
sum: number;
client: string;
receiverId: string;
currency: string;
export default interface Transfer {
sum: number;
client: string;
receiverId: string;
currency: string;
}
4 changes: 2 additions & 2 deletions tests/playwright/page/bill/BillForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TreeSelect from "@hipanel-core/input/TreeSelect";
import SumWithCurrency from "@hipanel-core/input/SumWithCurrency";
import Bill from "@hipanel-module-finance/model/Bill";
import Charge from "@hipanel-module-finance/model/Charge";
import Alert from "@hipanel-core/ui/Alert";
import { Alert } from "@hipanel-core/shared/ui/components";

export default class BillForm {
private page: Page;
Expand All @@ -30,7 +30,7 @@ export default class BillForm {
await SumWithCurrency.field(this.page, "billform", k).setSumAndCurrency(bill.sum, bill.currency);
await this.page.locator(`#billform-${k}-quantity`).fill(bill.quantity.toString());
if (bill.requisite) {
await Select2.field(this.page, `#billform-${k}-requisite_id`).setValue(bill.requisite)
await Select2.field(this.page, `#billform-${k}-requisite_id`).setValue(bill.requisite);
}

if (bill.charges) {
Expand Down
8 changes: 4 additions & 4 deletions tests/playwright/page/bill/BillView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ export default class BillView {
private page: Page;
private detailMenuFunctionsLocator: Locator;

public constructor(page: Page) {
constructor(page: Page) {
this.page = page;
this.detailMenuFunctionsLocator = page.locator(".widget-user-2 .nav");
}

public async checkCharge(charge: Charge) {
async checkCharge(charge: Charge) {
await expect(this.page.locator(`tr td a:text("${charge.object}")`).first()).toBeVisible();
await expect(this.page.locator(`tr td b:text("${charge.type}")`).first()).toBeVisible();
await expect(this.page.locator(`tr td a >> text=/.*${charge.sum}.*/i`).first()).toBeVisible();
}

public detailMenuItem(item: string, withAcceptDialog: boolean = false): Locator {
detailMenuItem(item: string, withAcceptDialog: boolean = false): Locator {
if (withAcceptDialog) {
this.page.on("dialog", dialog => dialog.accept());
}

return this.detailMenuFunctionsLocator.locator(`:scope a:text("${item}")`);
}

public async checkBillData(bill: Bill) {
async checkBillData(bill: Bill) {
// TODO: Implement
}
}
Loading