Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TalkAppContext.php « bootstrap « features « acceptance « tests - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b583b4b3a0d1a679163afd1b978b2a59953b9fc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php

/**
 *
 * @copyright Copyright (c) 2018, Daniel Calviño Sánchez (danxuliu@gmail.com)
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

use Behat\Behat\Context\Context;

class TalkAppContext implements Context, ActorAwareInterface {
	use ActorAware;

	/**
	 * @return Locator
	 */
	private static function appMenu() {
		return Locator::forThe()->id("appmenu")->
				describedAs("App menu in header");
	}

	/**
	 * @return Locator
	 */
	public static function talkItemInAppMenu() {
		return Locator::forThe()->xpath("/li[@data-id = 'spreed']")->
				descendantOf(self::appMenu())->
				describedAs("Talk item in app menu in header");
	}

	/**
	 * @return Locator
	 */
	public static function mainView() {
		return Locator::forThe()->id("app-content-wrapper")->
				describedAs("Main view in Talk app");
	}

	/**
	 * @return Locator
	 */
	public static function emptyContent() {
		return Locator::forThe()->id("emptycontent")->
				descendantOf(self::mainView())->
				describedAs("Empty content in main view");
	}

	/**
	 * @return Locator
	 */
	public static function sidebar() {
		return Locator::forThe()->id("app-sidebar")->
				describedAs("Sidebar in Talk app");
	}

	/**
	 * @return Locator
	 */
	private static function select2Dropdown() {
		return Locator::forThe()->css("#select2-drop")->
				describedAs("Select2 dropdown in Talk app");
	}

	/**
	 * @return Locator
	 */
	public static function searchInputInSelect2Dropdown() {
		return Locator::forThe()->css(".select2-search .select2-input")->
				descendantOf(self::select2Dropdown())->
				describedAs("Search input in select2 dropdown in Talk app");
	}

	/**
	 * @return Locator
	 */
	public static function itemInSelect2DropdownFor($text) {
		return Locator::forThe()->xpath("//*[contains(concat(' ', normalize-space(@class), ' '), ' select2-result-label ')]//span/text()[normalize-space() = '$text']/ancestor::li")->
				descendantOf(self::select2Dropdown())->
				describedAs("Item in select2 dropdown for $text in Talk app");
	}

	/**
	 * @Given I open the Talk app
	 */
	public function iOpenTheTalkApp() {
		$this->actor->find(self::talkItemInAppMenu(), 10)->click();
	}

	/**
	 * @Then I see that the current page is the Talk app
	 */
	public function iSeeThatTheCurrentPageIsTheTalkApp() {
		PHPUnit_Framework_Assert::assertStringStartsWith(
				$this->actor->locatePath("/apps/spreed/"),
				$this->actor->getSession()->getCurrentUrl());
	}

	/**
	 * @Then I see that the :text empty content message is shown in the main view
	 */
	public function iSeeThatTheEmptyContentMessageIsShownInTheMainView($text) {
		// The empty content always exists in the DOM, so it has to be explictly
		// waited for it to be visible instead of relying on the implicit wait
		// made to find the element.
		if (!WaitFor::elementToBeEventuallyShown(
				$this->actor,
				self::emptyContent(),
				$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
			PHPUnit_Framework_Assert::fail("The empty content was not shown yet after $timeout seconds");
		}

		PHPUnit_Framework_Assert::assertEquals($text, $this->actor->find(self::emptyContent())->getText());
	}

	/**
	 * @Then I see that the sidebar is open
	 */
	public function iSeeThatTheSidebarIsOpen() {
		// The sidebar always exists in the DOM, so it has to be explicitly
		// waited for it to be visible instead of relying on the implicit wait
		// made to find the element.
		if (!WaitFor::elementToBeEventuallyShown(
				$this->actor,
				self::sidebar(),
				$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
			PHPUnit_Framework_Assert::fail("The sidebar was not shown yet after $timeout seconds");
		}
	}

	/**
	 * @Then I see that the sidebar is closed
	 */
	public function iSeeThatTheSidebarIsClosed() {
		if (!WaitFor::elementToBeEventuallyNotShown(
				$this->actor,
				self::sidebar(),
				$timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
			PHPUnit_Framework_Assert::fail("The sidebar is still shown after $timeout seconds");
		}
	}

	/**
	 * @Given I have opened the Talk app
	 */
	public function iHaveOpenedTheTalkApp() {
		$this->iOpenTheTalkApp();
		$this->iSeeThatTheCurrentPageIsTheTalkApp();
	}
}