Completed
Push — master ( f8a75f...a37a81 )
by Dmitry
9s
created

PriceCest::ensureICanSeeAdvancedSearchBox()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 9.344
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace advancedhosters\hipanel\tests\acceptance\module\finance\manager;
4
5
use Codeception\Example;
6
use hipanel\helpers\Url;
7
use hipanel\modules\finance\tests\_support\Page\price\Create as PriceCreatePage;
8
use hipanel\modules\finance\tests\acceptance\manager\PriceCest as BasePriceCest;
9
use hipanel\tests\_support\Page\IndexPage;
10
use hipanel\tests\_support\Page\Widget\Input\Dropdown;
11
use hipanel\tests\_support\Page\Widget\Input\Input;
12
use hipanel\tests\_support\Step\Acceptance\Manager;
13
14
/**
15
 * Class PriceCest
16
 *
17
 * @author Dmytro Naumenko <[email protected]>
18
 */
19
class PriceCest extends BasePriceCest
20
{
21
    /**
22
     * @var string
23
     */
24
    private $templateName;
25
26
    /**
27
     * @var IndexPage
28
     */
29
    private $index;
30
31
    public function _before(Manager $I)
32
    {
33
        $this->index = new IndexPage($I);
34
        $this->ensureIHaveTestTemplate($I);
35
    }
36
37 View Code Duplication
    public function ensureIndexPageWorks(Manager $I)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39
        $I->login();
40
        $I->needPage(Url::to('@price'));
41
        $I->see('Price', 'h1');
42
        $this->ensureICanSeeAdvancedSearchBox();
43
        $this->ensureICanSeeBulkBillSearchBox();
44
    }
45
46
    private function ensureICanSeeAdvancedSearchBox()
47
    {
48
        $this->index->containsFilters([
49
            new Input('Tariff plan buyer'),
50
            new Input('Tariff plan owner'),
51
            new Input('Tariff plan name'),
52
            new Input('Object name'),
53
            new Input('Group model name'),
54
            new Input('Model partno'),
55
            new Input('Price'),
56
            (new Dropdown('pricesearch-type'))->withItems([
57
                'Monthly fee',
58
                'Server traffic monthly fee',
59
                'IP addresses monthly fee',
60
                'Rack unit price in monthly fee',
61
                'Server traffic overuse 95%',
62
                'Domain traffic',
63
                'Number of domains',
64
                'Backup disk usage monthly fee',
65
                'Backup traffic monthly fee',
66
                'IP traffic',
67
                'Number of IP addresses',
68
                'Support time monthly fee',
69
                'Account traffic',
70
                'Number of accounts',
71
                'Account disk usage',
72
                'Biggest directory',
73
                'CDN disk usage',
74
                'Backup traffic',
75
                'Number of mailboxes',
76
                'Support time',
77
                'Quantity',
78
            ]),
79
            new Input('Currency'),
80
        ]);
81
    }
82
83
    private function ensureICanSeeBulkBillSearchBox()
84
    {
85
        $this->index->containsBulkButtons([
86
            'Update',
87
            'Delete',
88
        ]);
89
        $this->index->containsColumns([
90
            'Object',
91
            'Details',
92
            'Price',
93
            'Type',
94
            'Note',
95
            'Tariff plan',
96
        ]);
97
    }
98
99
    /**
100
     * @return array of types that should be included in template plan
101
     *
102
     * ```php
103
     * return [
104
     *     ['vCDN'],
105
     *     ['pCDN']
106
     * ];
107
     * ```
108
     */
109
    protected function templatePriceTypesProvider(): array
110
    {
111
        return [
112
            ['Model groups'],
113
            ['Dedicated Server'],
114
            ['vCDN'],
115
            ['pCDN']
116
        ];
117
    }
118
119
    /**
120
     * @dataProvider templatePriceTypesProvider
121
     * @param Manager $I
122
     * @param Example $example
123
     */
124
    public function ensureICanCreateTemplatePlan(Manager $I, Example $example): void
125
    {
126
        $page = new PriceCreatePage($I, $this->id);
127
        $page->openModal();
128
        $page->choosePriceType($example[0]);
129
        $page->proceedToCreation();
130
        $page->fillRandomPrices('templateprice');
131
        $page->saveForm();
132
        $page->seeRandomPrices();
133
    }
134
135
    private function ensureIHaveTestTemplate(Manager $I): void
136
    {
137
        if (!$this->templateName) {
138
            $this->templateName = uniqid('TemplatePlan', true);
139
            $this->id = $this->createPlan($I, $this->templateName, 'Template');
140
            $I->needPage(Url::to(['@plan/view', 'id' => $this->id]));
141
            $I->see('No prices found');
142
        }
143
    }
144
145
    protected function suggestedPricesOptionsProvider(Manager $I): array
146
    {
147
        return [
148
            [
149
                'type' => 'Server',
150
                'templateName' => $this->templateName,
151
                'priceTypes' => ['Main prices', 'Parts prices'],
152
                'object' => 'DS5000',
153
            ],
154
            [
155
                'type' => 'vCDN',
156
                'templateName' => $this->templateName,
157
                'priceTypes' => ['Main prices'],
158
                'object' => 'vCDN-soltest',
159
            ],
160
        ];
161
    }
162
}
163