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

Select2   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 57
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A open() 0 7 1
A seeIsOpened() 0 6 1
A seeIsClosed() 0 6 1
A chooseOption() 0 8 1
A getSelect2Selector() 0 4 1
A getSelect2OptionSelector() 0 4 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