Completed
Pull Request — master (#51)
by
unknown
04:10
created

IndexPage::chooseRowMenuOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace hipanel\tests\_support\Page;
4
5
use hipanel\tests\_support\Page\Widget\Input\Input;
6
use hipanel\tests\_support\Page\Widget\Input\TestableInput;
7
use WebDriverKeys;
8
9
class IndexPage extends Authenticated
10
{
11
    /**
12
     * @param TestableInput[] $inputs example:
13
     * ```php
14
     *  [
15
     *      Input::asAdvancedSearch(Tester, 'Name'),
16
     *      Select2::asAdvancedSearch(Tester, 'Status')
17
     *  ]
18
     *```
19
     */
20
    public function containsFilters(array $inputs): void
21
    {
22
        $I = $this->tester;
23
24
        $I->see('Advanced search', 'h3');
25
26
        foreach ($inputs as $input) {
27
            $input->isVisible();
28
        }
29
        $I->see('Search', TestableInput::AS_BASE . "button[type='submit']");
30
        $I->see('Clear', TestableInput::AS_BASE  . "a");
31
    }
32
33
    /**
34
     * @param string[] $list array of legend list
35
     */
36
    public function containsLegend(array $list): void
37
    {
38
        $I = $this->tester;
39
40
        $I->see('Legend', 'h3');
41
42
        foreach ($list as $text) {
43
            $I->see($text, "//h3[text()='Legend']/../../div/ul/li");
44
        }
45
    }
46
47
    /**
48
     * @param string[] $buttons array of buttons
49
     */
50
    public function containsBulkButtons(array $buttons): void
51
    {
52
        $I = $this->tester;
53
54
        foreach ($buttons as $text) {
55
            $I->see($text, "//button[@type='submit' or @type='button']");
56
        }
57
    }
58
59
    /**
60
     * @param string[] $columnNames array of column names
61
     * @param string|null $representation the representation name
62
     */
63
    public function containsColumns(array $columnNames, $representation = null): void
64
    {
65
        $I = $this->tester;
66
        $formId = $I->grabAttributeFrom("//form[contains(@id, 'bulk') " .
67
                                        "and contains(@id, 'search')]", 'id');
68
69
        if ($representation !== null) {
70
            $I->click("//button[contains(text(), 'View:')]");
71
            $I->click("//ul/li/a[contains(text(), '$representation')]");
72
            $I->waitForJS('return $.active == 0;', 30);
73
        }
74
75
        foreach ($columnNames as $column) {
76
            $I->see($column, "//form[@id='$formId']//table/thead/tr/th");
77
        }
78
    }
79
80
    /**
81
     * Filters index page table
82
     *
83
     * @param TestableInput $inputElement
84
     * @param $value
85
     */
86
    public function filterBy(TestableInput $inputElement, $value)
87
    {
88
        $inputElement->setValue($value);
89
        if ($inputElement instanceof Input) {
90
            $this->tester->pressKey($inputElement->getSelector(),WebDriverKeys::ENTER);
91
        }
92
        $this->tester->waitForPageUpdate();
93
    }
94
95
    /**
96
     * Selects table row by its number
97
     *
98
     * @param int $n - number of the row that should be selected
99
     */
100
    public function selectTableRowByNumber(int $n): void
101
    {
102
        $I = $this->tester;
103
104
        $selector = "form tbody tr:nth-child($n) input[type=checkbox]";
105
        $I->click($selector);
106
    }
107
108
    /**
109
     * Opens table row menu by its number
110
     *
111
     * @param int $n - number of the row which menu should be opened
112
     */
113
    public function openRowMenuByNumber(int $n): void
114
    {
115
        $this->tester->click("form tbody tr:nth-child($n) button");
116
    }
117
118
    /**
119
     * Opens table row menu by item id
120
     *
121
     * @param string $id - id of item which menu should be opened
122
     */
123
    public function openRowMenuById(string $id)
124
    {
125
        $this->tester->click("tr[data-key='$id'] button");
126
    }
127
128
    /**
129
     * Clicks to row menu option
130
     *
131
     * @param $option - the name of option that should be clicked
132
     */
133
    public function chooseRowMenuOption($option)
134
    {
135
        $this->tester->click("//ul[@class='nav']//a[contains(text(), '{$option}')]");
136
        $this->tester->waitForPageUpdate();
137
    }
138
}
139