Completed
Push — master ( 77bcd8...d53364 )
by Dmitry
08:45
created

Select2::getSelect2Selector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 1
1
<?php
2
namespace hipanel\tests\_support\Page\Widget;
3
4
use Codeception\Util\Locator;
5
6
class Select2
7
{
8
    /**
9
     * @var \AcceptanceTester
10
     */
11
    protected $tester;
12
13
    function __construct(\AcceptanceTester $I)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14
    {
15
        $this->tester = $I;
16
    }
17
18
    public function open($selector)
19
    {
20
        $this->tester->click($this->getSelect2Selector($selector));
21
        $this->seeIsOpened();
22
23
        return $this;
24
    }
25
26
    public function seeIsOpened()
27
    {
28
        $this->tester->seeElement('.select2-container--open');
29
30
        return $this;
31
    }
32
33
    public function seeIsClosed()
34
    {
35
        $this->tester->cantSeeElement('.select2-container--open');
36
37
        return $this;
38
    }
39
40
    /**
41
     * @param $optionName
42
     * @return $this
43
     */
44
    public function chooseOption($optionName)
45
    {
46
        $this->seeIsOpened();
47
        $this->tester->clickWithLeftButton(Locator::contains($this->getSelect2OptionSelector(), $optionName), 5, 5);
48
        $this->seeIsClosed();
49
50
        return $this;
51
    }
52
53
    protected function getSelect2Selector($selector)
54
    {
55
        return $selector . ' + span [role=combobox]';
56
    }
57
58
    protected function getSelect2OptionSelector()
59
    {
60
        return '.select2-container--open .select2-results__options li';
61
    }
62
}
63