|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hipanel\modules\finance\tests\_support\Page\price; |
|
4
|
|
|
|
|
5
|
|
|
use hipanel\tests\_support\Page\Widget\Input\Select2; |
|
6
|
|
|
use hipanel\tests\_support\Page\Widget\Input\XEditable; |
|
7
|
|
|
|
|
8
|
|
|
class Create extends View |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @param string $objectName |
|
12
|
|
|
* @param string $templateName |
|
13
|
|
|
* @param string $priceType |
|
14
|
|
|
*/ |
|
15
|
|
|
public function createRandomPrices(string $objectName, string $templateName, string $priceType): void |
|
16
|
|
|
{ |
|
17
|
|
|
$note = 'test note'; |
|
18
|
|
|
|
|
19
|
|
|
$this->loadPage(); |
|
20
|
|
|
$this->openModal(); |
|
21
|
|
|
$this->chooseObject($objectName); |
|
22
|
|
|
$this->chooseTemplate($templateName); |
|
23
|
|
|
$this->choosePriceType($priceType); |
|
24
|
|
|
$this->proceedToCreation(); |
|
25
|
|
|
$this->fillRandomPrices('price'); |
|
26
|
|
|
$howNotes = $this->fillNote($note); |
|
27
|
|
|
$this->saveForm(); |
|
28
|
|
|
$this->seeNoteInTbodyRow($note, $howNotes); |
|
29
|
|
|
$this->seeRandomPrices(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function openModal(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$I = $this->tester; |
|
35
|
|
|
|
|
36
|
|
|
$I->click('Create'); |
|
37
|
|
|
$I->waitForElement('#create-prices'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function chooseObject(string $objectName): void |
|
41
|
|
|
{ |
|
42
|
|
|
(new Select2($this->tester, '#object_id')) |
|
43
|
|
|
->setValue($objectName); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function chooseTemplate(string $templateName): void |
|
47
|
|
|
{ |
|
48
|
|
|
(new Select2($this->tester, '#template_plan_id')) |
|
49
|
|
|
->fillSearchField($templateName) |
|
50
|
|
|
->chooseOptionLike($templateName); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function choosePriceType(string $priceType): void |
|
54
|
|
|
{ |
|
55
|
|
|
(new Select2($this->tester, '#type')) |
|
56
|
|
|
->setValue($priceType); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function proceedToCreation(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$I = $this->tester; |
|
62
|
|
|
|
|
63
|
|
|
$I->pressButton('Proceed to creation'); |
|
64
|
|
|
$I->waitForText('Create suggested prices', 60); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function saveForm(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$I = $this->tester; |
|
70
|
|
|
|
|
71
|
|
|
$I->click('Save'); |
|
72
|
|
|
$I->closeNotification('Prices were successfully created'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param string $note |
|
77
|
|
|
* @return int |
|
78
|
|
|
*/ |
|
79
|
|
|
public function fillNote(string $note): int |
|
80
|
|
|
{ |
|
81
|
|
|
$how = count($this->tester->grabMultiple("//a[contains(@class, 'editable')]")); |
|
82
|
|
|
foreach (range(1, $how) as $i) { |
|
83
|
|
|
(new XEditable($this->tester, "div.price-item:nth-child($i)")) |
|
84
|
|
|
->setValue("$note $i"); |
|
85
|
|
|
} |
|
86
|
|
|
return $how; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param string $note |
|
91
|
|
|
* @param int $how |
|
92
|
|
|
*/ |
|
93
|
|
|
public function seeNoteInTbodyRow(string $note, int $how): void |
|
94
|
|
|
{ |
|
95
|
|
|
foreach (range(1, $how) as $i) { |
|
96
|
|
|
$this->tester->see("$note $i", "//tbody"); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|