Completed
Push — master ( b864d9...3fa98b )
by Dmitry
07:42 queued 03:17
created

Create::seeNoSuggestions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace hipanel\modules\finance\tests\_support\Page\price\certificate;
4
5
use hipanel\modules\finance\tests\_support\Page\price\Create as PriceCreate;
6
7
class Create extends PriceCreate
8
{
9
    public function fillRandomPrices(string $type): void
10
    {
11
        $I = $this->tester;
12
13
        $this->priceValues = $I->executeJS("
14
        var prices = [];
15
        $('.price-input').each(function(){
16
            var randomValue = Math.floor(Math.random() * 2147483647);
17
            $(this).val(randomValue);
18
            prices.push(randomValue);
19
        });
20
        return prices;
21
        ");
22
    }
23
24
    public function addPrices(string $templateName): void
25
    {
26
        $this->prepareForCreation($templateName);
27
        $this->fillRandomPrices('');
28
        $this->saveForm();
29
        $this->seeRandomPrices();
30
    }
31
32
    private function prepareForCreation(string $templateName): void
33
    {
34
        $this->loadPage();
35
        $this->openModal();
36
        $this->chooseTemplate($templateName);
37
        $this->proceedToCreation();
38
    }
39
40
    public function chooseTemplate(string $templateName): void
41
    {
42
        $this->select2->open('#template_plan_id');
43
        $this->select2->fillSearchField($templateName);
44
        $this->select2->chooseOption($templateName);
45
    }
46
47
    public function ensureThereNoSuggestions(string $templateName): void
48
    {
49
        $this->prepareForCreation($templateName);
50
        $this->seeNoSuggestions();
51
    }
52
53
    private function seeNoSuggestions(): void
54
    {
55
        $I = $this->tester;
56
57
        $I->see("No price suggestions for this object");
58
        $I->see('We could not suggest any new prices of type "Certificate" for the selected object.');
59
        $I->see('Probably, they were already created earlier or this suggestion type is not compatible with this object type');
60
        $I->see("You can return back to plan");
61
    }
62
}
63