aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/core/core.js
blob: 94c1261236f44e9557273e1bf5d384fe07a4eaf7 (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
define( [
	"qunit",
	"jquery",
	"lib/common",
	"lib/helper",
	"ui/form",
	"ui/labels",
	"ui/unique-id"
], function( QUnit, $, common, helper ) {

QUnit.module( "core - jQuery extensions", { afterEach: helper.moduleAfterEach }  );

common.testJshint( "core" );

QUnit.test( "innerWidth - getter", function( assert ) {
	assert.expect( 2 );
	var el = $( "#dimensions" );

	assert.equal( el.innerWidth(), 122, "getter passthru" );
	el.hide();
	assert.equal( el.innerWidth(), 122, "getter passthru when hidden" );
} );

QUnit.test( "innerWidth - setter", function( assert ) {
	assert.expect( 2 );
	var el = $( "#dimensions" );

	el.innerWidth( 120 );
	assert.equal( el.width(), 98, "width set properly" );
	el.hide();
	el.innerWidth( 100 );
	assert.equal( el.width(), 78, "width set properly when hidden" );
} );

QUnit.test( "innerHeight - getter", function( assert ) {
	assert.expect( 2 );
	var el = $( "#dimensions" );

	assert.equal( el.innerHeight(), 70, "getter passthru" );
	el.hide();
	assert.equal( el.innerHeight(), 70, "getter passthru when hidden" );
} );

QUnit.test( "innerHeight - setter", function( assert ) {
	assert.expect( 2 );
	var el = $( "#dimensions" );

	el.innerHeight( 60 );
	assert.equal( el.height(), 40, "height set properly" );
	el.hide();
	el.innerHeight( 50 );
	assert.equal( el.height(), 30, "height set properly when hidden" );
} );

QUnit.test( "outerWidth - getter", function( assert ) {
	assert.expect( 2 );
	var el = $( "#dimensions" );

	assert.equal( el.outerWidth(), 140, "getter passthru" );
	el.hide();
	assert.equal( el.outerWidth(), 140, "getter passthru when hidden" );
} );

QUnit.test( "outerWidth - setter", function( assert ) {
	assert.expect( 2 );
	var el = $( "#dimensions" );

	el.outerWidth( 130 );
	assert.equal( el.width(), 90, "width set properly" );
	el.hide();
	el.outerWidth( 120 );
	assert.equal( el.width(), 80, "width set properly when hidden" );
} );

QUnit.test( "outerWidth(true) - getter", function( assert ) {
	assert.expect( 2 );
	var el = $( "#dimensions" );

	assert.equal( el.outerWidth( true ), 154, "getter passthru w/ margin" );
	el.hide();
	assert.equal( el.outerWidth( true ), 154, "getter passthru w/ margin when hidden" );
} );

QUnit.test( "outerWidth(true) - setter", function( assert ) {
	assert.expect( 2 );
	var el = $( "#dimensions" );

	el.outerWidth( 130, true );
	assert.equal( el.width(), 76, "width set properly" );
	el.hide();
	el.outerWidth( 120, true );
	assert.equal( el.width(), 66, "width set properly when hidden" );
} );

QUnit.test( "outerHeight - getter", function( assert ) {
	assert.expect( 2 );
	var el = $( "#dimensions" );

	assert.equal( el.outerHeight(), 86, "getter passthru" );
	el.hide();
	assert.equal( el.outerHeight(), 86, "getter passthru when hidden" );
} );

QUnit.test( "outerHeight - setter", function( assert ) {
	assert.expect( 2 );
	var el = $( "#dimensions" );

	el.outerHeight( 80 );
	assert.equal( el.height(), 44, "height set properly" );
	el.hide();
	el.outerHeight( 70 );
	assert.equal( el.height(), 34, "height set properly when hidden" );
} );

QUnit.test( "outerHeight(true) - getter", function( assert ) {
	assert.expect( 2 );
	var el = $( "#dimensions" );

	assert.equal( el.outerHeight( true ), 98, "getter passthru w/ margin" );
	el.hide();
	assert.equal( el.outerHeight( true ), 98, "getter passthru w/ margin when hidden" );
} );

QUnit.test( "outerHeight(true) - setter", function( assert ) {
	assert.expect( 2 );
	var el = $( "#dimensions" );

	el.outerHeight( 90, true );
	assert.equal( el.height(), 42, "height set properly" );
	el.hide();
	el.outerHeight( 80, true );
	assert.equal( el.height(), 32, "height set properly when hidden" );
} );

QUnit.test( "uniqueId / removeUniqueId", function( assert ) {
	assert.expect( 3 );
	var el = $( "img" ).eq( 0 );
	assert.equal( el.attr( "id" ), null, "element has no initial id" );
	el.uniqueId();
	assert.ok( /ui-id-\d+$/.test( el.attr( "id" ) ), "element has generated id" );
	el.removeUniqueId();
	assert.equal( el.attr( "id" ), null, "unique id has been removed from element" );
} );

QUnit.test( "Labels", function( assert ) {
	assert.expect( 3 );

	var expected = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ];
	var dom = $( "#labels-fragment" );

	function testLabels( testType ) {
		var labels = dom.find( "#test" ).labels();
		var found = labels.map( function() {

				// Support: Core 1.9 Only
				// We use String.prototype.trim because core 1.9.x silently fails
				// when white space is present
				return String.prototype.trim.call( $( this ).text() );
			} ).get();

		assert.deepEqual( found, expected,
			".labels() finds all labels in " + testType + ", and sorts them in DOM order" );
	}

	testLabels( "the DOM" );

	// Detach the dom to test on a fragment
	dom.detach();
	testLabels( "document fragments" );

	assert.equal( $().labels().length, 0, "No element" );
} );

( function() {
	var domAttached = $( "#form-test" );
	var domDetached = $( "#form-test-detached" ).detach();

	function testForm( name, dom ) {
		var inputs = dom.find( "input" );

		inputs.each( function() {
			var input = $( this );

			QUnit.test( name + this.id.replace( /_/g, " " ), function( assert ) {
				var ready = assert.async();
				assert.expect( 1 );
				var form = input._form();

				// If input has a form the value should reset to "" if not it should be "changed"
				var value = form.length ? "" : "changed";

				input.val( "changed" );

				// If there is a form we reset just that. If there is not a form, reset every form.
				// The idea is if a form is found resetting that form should reset the input.
				// If no form is found no amount of resetting should change the value.
				( form.length ? form : dom.find( "form" ).addBack( "form" ) ).each( function() {
					this.reset();
				} );

				setTimeout( function() {
					assert.equal( input.val(), value, "Proper form found for #" + input.attr( "id" ) );
					ready();
				} );
			} );
		} );
	}

	testForm( "form: attached: ", domAttached );
	testForm( "form: detached: ", domDetached );
} )();
} );
table28 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Settings/Admin/TipsTricks.php
blob: 0df690dbbeb274993191fe658465b78ec1924525 (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
<?php
/**
 * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
 *
 * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
 *
 * @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/>.
 *
 */

namespace OC\Settings\Admin;

use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\Settings\ISettings;

class TipsTricks implements ISettings {
	/** @var IConfig */
	private $config;

	/**
	 * @param IConfig $config
	 */
	public function __construct(IConfig $config) {
		$this->config = $config;
	}

	/**
	 * @return TemplateResponse
	 */
	public function getForm() {
		$databaseOverload = (strpos($this->config->getSystemValue('dbtype'), 'sqlite') !== false);

		$parameters = [
			'databaseOverload' => $databaseOverload,
		];

		return new TemplateResponse('settings', 'settings/admin/tipstricks', $parameters, '');
	}

	/**
	 * @return string the section ID, e.g. 'sharing'
	 */
	public function getSection() {
		return 'tips-tricks';
	}

	/**
	 * @return int whether the form should be rather on the top or bottom of
	 * the admin section. The forms are arranged in ascending order of the
	 * priority values. It is required to return a value between 0 and 100.
	 *
	 * E.g.: 70
	 */
	public function getPriority() {
		return 0;
	}
}