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

specHelper.js « tests « js « core - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d8ac35f827d099cb070c33e701b4bd89048aa833 (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
/**
* ownCloud
*
* @author Vincent Petry
* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library 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 library.  If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
 * Simulate the variables that are normally set by PHP code
 */

// from core/js/config.php
window.TESTING = true;
window.datepickerFormatDate = 'MM d, yy';
window.dayNames = [
	'Sunday',
	'Monday',
	'Tuesday',
	'Wednesday',
	'Thursday',
	'Friday',
	'Saturday'
];
window.dayNamesShort = [
	'Sun.',
	'Mon.',
	'Tue.',
	'Wed.',
	'Thu.',
	'Fri.',
	'Sat.'
];
window.dayNamesMin = [
	'Su',
	'Mo',
	'Tu',
	'We',
	'Th',
	'Fr',
	'Sa'
];
window.monthNames = [
	'January',
	'February',
	'March',
	'April',
	'May',
	'June',
	'July',
	'August',
	'September',
	'October',
	'November',
	'December'
];
window.monthNamesShort = [
	'Jan.',
	'Feb.',
	'Mar.',
	'Apr.',
	'May.',
	'Jun.',
	'Jul.',
	'Aug.',
	'Sep.',
	'Oct.',
	'Nov.',
	'Dec.'
];
window.firstDay = 0;

// setup dummy webroots
/* jshint camelcase: false */
window.oc_debug = true;
// FIXME: OC.webroot is supposed to be only the path!!!
OC.webroot = location.href + '/';
OC.appswebroots = {
	"files": window.webroot + '/apps/files/',
	"files_sharing": window.webroot + '/apps/files_sharing/'
};
OC.config = {
	session_lifetime: 600 * 1000,
	session_keepalive: false,
	blacklist_files_regex: '\.(part|filepart)$',
};
OC.appConfig = {
	core: {}
};
OC.theme = {
	docPlaceholderUrl: 'https://docs.example.org/PLACEHOLDER'
};
window.oc_capabilities = {
}

/* jshint camelcase: true */

// mock for Snap.js plugin
window.Snap = function() {};
window.Snap.prototype = {
	enable: function() {},
	disable: function() {},
	close: function() {}
};

window.isPhantom = /phantom/i.test(navigator.userAgent);
document.documentElement.lang = navigator.language;

// global setup for all tests
(function setupTests() {
	var fakeServer = null,
		$testArea = null,
		ajaxErrorStub = null;

	/**
	 * Utility functions for testing
	 */
	var TestUtil = {
		/**
		 * Returns the image URL set on the given element
		 * @param $el element
		 * @return {String} image URL
		 */
		getImageUrl: function($el) {
			// might be slightly different cross-browser
			var url = $el.css('background-image');
			var r = url.match(/url\(['"]?([^'")]*)['"]?\)/);
			if (!r) {
				return url;
			}
			return r[1];
		}
	};

	beforeEach(function() {
		// test area for elements that need absolute selector access or measure widths/heights
		// which wouldn't work for detached or hidden elements
		$testArea = $('<div id="testArea" style="position: absolute; width: 1280px; height: 800px; top: -3000px; left: -3000px; opacity: 0;"></div>');
		$('body').append($testArea);
		// enforce fake XHR, tests should not depend on the server and
		// must use fake responses for expected calls
		fakeServer = sinon.fakeServer.create();

		// make it globally available, so that other tests can define
		// custom responses
		window.fakeServer = fakeServer;

		if (!OC.TestUtil) {
			OC.TestUtil = TestUtil;
		}

		moment.locale('en');

		// reset plugins
		OC.Plugins._plugins = [];

		// dummy select2 (which isn't loaded during the tests)
		$.fn.select2 = function() { return this; };

		ajaxErrorStub = sinon.stub(OC, '_processAjaxError');
	});

	afterEach(function() {
		// uncomment this to log requests
		// console.log(window.fakeServer.requests);
		fakeServer.restore();

		$testArea.remove();

		delete($.fn.select2);

		ajaxErrorStub.restore();

		// reset pop state handlers
		OC.Util.History._handlers = [];

	});
})();