Completed
Pull Request — master (#40)
by
unknown
04:29
created

Select2   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 67
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fillSearchField() 0 5 1
A open() 0 7 1
A seeIsOpened() 0 6 1
A seeIsClosed() 0 6 1
A chooseOption() 0 12 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
use hipanel\tests\_support\AcceptanceTester;
6
7
class Select2
8
{
9
    /**
10
     * @var \AcceptanceTester
11
     */
12
    protected $tester;
13
14
    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...
15
    {
16
        $this->tester = $I;
17
    }
18
19
    public function fillSearchField(string $name): void
20
    {
21
        $this->tester->fillField('.select2-search__field', $name);
22
        $this->tester->waitForElementNotVisible('.loading-results', 120);
23
    }
24
25
    public function open($selector)
26
    {
27
        $this->tester->click($this->getSelect2Selector($selector));
28
        $this->seeIsOpened();
29
30
        return $this;
31
    }
32
33
    public function seeIsOpened()
34
    {
35
        $this->tester->seeElement('.select2-container--open');
36
37
        return $this;
38
    }
39
40
    public function seeIsClosed()
41
    {
42
        $this->tester->cantSeeElement('.select2-container--open');
43
44
        return $this;
45
    }
46
47
    /**
48
     * @param $optionName
49
     * @return $this
50
     */
51
    public function chooseOption($optionName)
52
    {
53
        $this->tester->executeJS(<<<JS
54
        $("li:contains('{$optionName}')").each(function() {
55
            if (this.firstChild.data === '{$optionName}') {
56
                $(this).trigger('mouseup');
57
            }
58
        });
59
JS
60
);
61
        return $this;
62
    }
63
64
    protected function getSelect2Selector($selector)
65
    {
66
        return $selector . ' + span [role=combobox]';
67
    }
68
69
    protected function getSelect2OptionSelector()
70
    {
71
        return '.select2-container--open .select2-results__options li';
72
    }
73
}
74