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

testPageDashboardWidgets.php « selenium « tests « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7be54df99255da9825235769d6a2297648b156dc (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/


require_once dirname(__FILE__) . '/../include/CWebTest.php';

/**
 * @backup dashboard, profiles
 * @dataSource LoginUsers
 */
class testPageDashboardWidgets extends CWebTest {

	/**
	 * Default selected widget type.
	 * The widget type should not be changed in frontend and in DB.
	 */
	public function testPageDashboardWidgets_checkUnchangedWidgetType() {
		// Opening widget configuration form for new widget first time.
		$this->page->login()->open('zabbix.php?action=dashboard.view&dashboardid=1');
		$dashboard = CDashboardElement::find()->one()->edit();
		// Check that widget type isn't changed in frontend and in DB.
		$this->checkLastSelectedWidgetType();

		// Opening edit widget form.
		$form_system_info = $dashboard->getWidget('System information')->edit();
		$this->assertEquals('System information', $form_system_info->getField('Type')->getValue());
		$form_system_info->submit();
		// Check that widget type isn't changed in frontend and in DB.
		$this->checkLastSelectedWidgetType();

		// Making changes in widget form that are not "Widget type".
		$form_problems = $dashboard->getWidget('Current problems')->edit();
		$this->assertEquals('Problems', $form_problems->getField('Type')->getValue());
		$data =[
			'Name' => 'check widget type',
			'Refresh interval' => 'No refresh',
			'Show' => 'Recent problems',
			'Show tags' => 'None'
		];
		$form_problems->fill($data);
		$form_problems->submit();
		$this->checkLastSelectedWidgetType();

		// Add widget with current default type "Action log".
		$dashboard->addWidget();
		$this->query('xpath://div[@role="dialog"]//button[text()="Add"]')->waitUntilPresent()->one()->click();
		// Check if widget was added.
		$dashboard->getWidget('Action log');
		$this->checkLastSelectedWidgetType();

		$dashboard->cancelEditing();
	}

	/**
	 * Check last selected widget type in frontend and in DB.
	 * By default is 'Action log' type and without record in DB.
	 *
	 * @param string $type			widget type name
	 * @param string $db_type		widget type name stored in DB
	 */
	private function checkLastSelectedWidgetType($type = 'Action log', $db_type = null) {
		$dashboard = CDashboardElement::find()->one();
		COverlayDialogElement::ensureNotPresent();
		$overlay = $dashboard->addWidget();
		$form = $overlay->asForm();
		$this->assertEquals($type, $form->getField('Type')->getValue());

		if ($db_type) {
			$this->assertEquals($db_type, CDBHelper::getValue("SELECT value_str FROM profiles".
					" WHERE userid=1 AND idx='web.dashboard.last_widget_type'"));
		}
		else {
			$this->assertEquals(0, CDBHelper::getCount("SELECT * FROM profiles".
					" WHERE userid=1 AND idx='web.dashboard.last_widget_type'"));
		}

		$overlay->close();
	}

	/**
	 * Widget type should be inherited from the one that was selected last time.
	 */
	public function testPageDashboardWidgets_checkWidgetTypeRemembering() {
		$this->page->login()->open('zabbix.php?action=dashboard.view&dashboardid=1');
		$dashboard = CDashboardElement::find()->one()->edit();
		// Opening widget configuration form for new Clock widget.
		$overlay = $dashboard->addWidget();
		$default_form = $overlay->asForm();
		$default_form->fill(['Type' => 'Clock']);
		$default_form->waitUntilReloaded();
		$overlay->close();
		// Check that widget type is remembered as Clock.
		$this->checkLastSelectedWidgetType('Clock', 'clock');

		// Save edit widget form without changing widget type.
		$sys_info_form = $dashboard->getWidget('System information')->edit();
		$this->assertEquals('System information', $sys_info_form->getField('Type')->getValue());
		$sys_info_form->submit();
		$this->page->waitUntilReady();
		// Check that widget type is still remembered as Clock.
		$this->checkLastSelectedWidgetType('Clock', 'clock');

		// Opening edit widget form and change widget type.
		$change_form = $dashboard->getWidget('System information')->edit();
		$change_form->fill(['Type' => 'Data overview']);
		$overlay->close();
		// Check that widget type inherited from previous widget.
		$this->checkLastSelectedWidgetType('Data overview', 'dataover');

		$dashboard->cancelEditing();
	}

	/**
	 * Check "Problem Hosts" widget.
	 */
	public function testPageDashboardWidgets_checkProblemHostsWidget() {
		// Authorize user and open the page with the desired widget.
		$this->page->login()->open('zabbix.php?action=dashboard.view&dashboardid=1000');

		// Find dashboard element.
		$dashboard = CDashboardElement::find()->one();

		// Get dashboard widget element by widget title ('Problem hosts').
		$widget = $dashboard->getWidget('Problem hosts');
		// Check refresh interval of widget.
		$this->assertEquals('1 minute', $widget->getRefreshInterval());

		// Get widget content as table.
		$table = $widget->getContent()->asTable();
		// Check text of the table headers.
		$this->assertSame(['Host group', 'Without problems', 'With problems', 'Total'], $table->getHeadersText());

		// Expected table values.
		$expected = [
			'Host group for tag permissions'	=> 1,
			'Zabbix servers'					=> 17,
			'ZBX6648 All Triggers'				=> 1,
			'ZBX6648 Disabled Triggers'			=> 1,
			'ZBX6648 Enabled Triggers'			=> 1
		];

		/*
		 * Index rows by column "Host group":
		 * Get table data as array where values from column 'Host group' are used as array keys.
		 */
		$data = $table->index('Host group');

		foreach ($expected as $group => $problems) {
			// Get table row by host name.
			$row = $data[$group];

			// Check the value in table.
			$this->assertEquals($problems, $row['Without problems']);
			$this->assertEquals($problems, $row['Total']);
		}
	}

	/**
	 * Create dashboard with clock widget.
	 */
	public function testPageDashboardWidgets_checkDashboardCreate() {
		$this->page->login()->open('zabbix.php?action=dashboard.list');

		$this->query('button:Create dashboard')->one()->click();
		$this->page->waitUntilReady();
		$dialog = COverlayDialogElement::find()->one()->waitUntilReady();

		$this->assertEquals('Dashboard properties', $dialog->getTitle());
		$configuration = $dialog->asForm();
		// Change dashboard owner.
		$owner = $configuration->getField('Owner');
		$owner->clear();
		$owner->select('test-user');
		// Change dashboard name.
		$configuration->getField('Name')->clear()->type('Dashboard create test');
		$configuration->submit();

		if ($this->page->isAlertPresent()) {
			$this->page->acceptAlert();
		}

		$dashboard = CDashboardElement::find()->one();
		// Check the name of dashboard.
		$this->query('id:page-title-general')->waitUntilTextPresent('Dashboard create test');
		$this->assertEquals('Dashboard create test', $dashboard->getTitle());

		// Add widget.
		$overlay = $dashboard->addWidget();
		$form = $overlay->asForm();
		// Set type to "Clock".
		$form->getField('Type')->asDropdown()->select('Clock');
		// Wait until overlay is reloaded.
		$overlay->waitUntilReady();
		// Set name of widget.
		$form->getField('Name')->type('Clock test');
		$form->submit();

		if ($this->page->isAlertPresent()) {
			$this->page->acceptAlert();
		}

		// Check if widget was added.
		$widget = $dashboard->getWidget('Clock test');
		$widget->getContent()->query('class:clock')->waitUntilVisible();

		// Save dashboard.
		$dashboard->save();
		$this->page->waitUntilReady();

		// Get global message.
		$message = CMessageElement::find()->one();
		// Check if message is positive.
		$this->assertTrue($message->isGood());
		// Check message title.
		$this->assertEquals('Dashboard created', $message->getTitle());
	}

	/**
	 * Edit widget.
	 */
	public function testPageDashboardWidgets_checkProblemWidgetEdit() {
		$this->page->login()->open('zabbix.php?action=dashboard.view&dashboardid=1');

		$dashboard = CDashboardElement::find()->one()->edit();
		$widget = $dashboard->getWidget('Problems by severity');

		// Check if widget is editable.
		$this->assertEquals(true, $widget->isEditable());

		// Open widget edit form and get the form element.
		$form = $widget->edit();

		// Get "Host groups" multiselect.
		$groups = $form->getField('Host groups');

		// Select a single group.
		$groups->select('Zabbix servers');

		// Change the name of widget.
		$form->getField('Name')->clear()->type('New widget name');
		// Change show option.
		$form->getField('Show')->select('Host groups');
		// Submit the form.
		$form->submit();

		if ($this->page->isAlertPresent()) {
			$this->page->acceptAlert();
		}

		// Check if widget can be found by a new name.
		$dashboard->getWidget('New widget name');
		$table = $widget->getContent()->asTable();
		// Check if only selected host group is shown.
		$this->assertEquals(['Zabbix servers'], array_keys($table->index('Host group')));

		$dashboard->cancelEditing();
	}
}