How to use mount method in Cypress

Best JavaScript code snippet using cypress

statusmanager.js

Source:statusmanager.js Github

copy

Full Screen

1/**2 * ownCloud3 *4 * @author Juan Pablo Villafañez Ramos <jvillafanez@owncloud.com>5 * @author Jesus Macias Portela <jesus@owncloud.com>6 * @copyright Copyright (c) 2018, ownCloud GmbH7 *8 * This file is licensed under the Affero General Public License version 39 * or later.10 *11 * See the COPYING-README file.12 *13 */14if (!OCA.External) {15	OCA.External = {};16}17if (!OCA.External.StatusManager) {18	OCA.External.StatusManager = {};19}20OCA.External.StatusManager = {21	mountStatus: null,22	mountPointList: null,23	/**24	 * Function25	 * @param {callback} afterCallback26	 */27	getMountStatus: function (afterCallback) {28		var self = this;29		if (typeof afterCallback !== 'function' || self.isGetMountStatusRunning) {30			return;31		}32		if (self.mountStatus) {33			afterCallback(self.mountStatus);34		}35	},36	/**37	 * Function Check mount point status from cache38	 * @param {string} mount_point39	 */40	getMountPointListElement: function (mount_point) {41		var element;42		$.each(this.mountPointList, function (key, value) {43			if (value.mount_point === mount_point) {44				element = value;45				return false;46			}47		});48		return element;49	},50	/**51	 * Function Check mount point status from cache52	 * @param {string} mount_point53	 * @param {string} mount_point54	 */55	getMountStatusForMount: function (mountData, afterCallback) {56		var self = this;57		if (typeof afterCallback !== 'function' || self.isGetMountStatusRunning) {58			return $.Deferred().resolve();59		}60		var defObj;61		if (self.mountStatus[mountData.mount_point]) {62			defObj = $.Deferred();63			afterCallback(mountData, self.mountStatus[mountData.mount_point]);64			defObj.resolve();  // not really useful, but it'll keep the same behaviour65		} else {66			defObj = $.ajax({67				type: 'GET',68				url: OC.webroot + '/index.php/apps/files_external/' + ((mountData.type === 'personal') ? 'userstorages' : 'userglobalstorages') + '/' + mountData.id,69				data: {'testOnly' : false},70				success: function (response) {71					if (response && response.status === 0) {72						self.mountStatus[mountData.mount_point] = response;73					} else {74						var statusCode = response.status ? response.status : 1;75						var statusMessage = response.statusMessage ? response.statusMessage : t('files_external', 'Empty response from the server')76						// failure response with error message77						self.mountStatus[mountData.mount_point] = {78							type: mountData.type,79							status: statusCode,80							id: mountData.id,81							error: statusMessage,82							userProvided: response.userProvided83						};84					}85					afterCallback(mountData, self.mountStatus[mountData.mount_point]);86				},87				error: function (jqxhr, state, error) {88					var message;89					if (mountData.location === 3) {90						// In this case the error is because  mount point use Login credentials and don't exist in the session91						message = t('files_external', 'Couldn\'t access. Please logout and login to activate this mount point');92					} else {93						message = t('files_external', 'Couldn\'t get the information from the ownCloud server: {code} {type}', {94							code: jqxhr.status,95							type: error96						});97					}98					self.mountStatus[mountData.mount_point] = {99						type: mountData.type,100						status: 1,101						location: mountData.location,102						error: message103					};104					afterCallback(mountData, self.mountStatus[mountData.mount_point]);105				}106			});107		}108		return defObj;109	},110	/**111	 * Function to get external mount point list from the files_external API112	 * @param {function} afterCallback function to be executed113	 */114	getMountPointList: function (afterCallback) {115		var self = this;116		if (typeof afterCallback !== 'function' || self.isGetMountPointListRunning) {117			return;118		}119		if (self.mountPointList) {120			afterCallback(self.mountPointList);121		} else {122			self.isGetMountPointListRunning = true;123			$.ajax({124				type: 'GET',125				url: OC.linkToOCS('apps/files_external/api/v1') + 'mounts?format=json',126				success: function (response) {127					self.mountPointList = [];128					_.each(response.ocs.data, function (mount) {129						var element = {};130						element.mount_point = mount.name;131						element.type = mount.scope;132						element.location = "";133						element.id = mount.id;134						element.backendText = mount.backend;135						element.backend = mount.class;136						self.mountPointList.push(element);137					});138					afterCallback(self.mountPointList);139				},140				error: function (jqxhr, state, error) {141					self.mountPointList = [];142					OC.Notification.show(t('files_external', 'Couldn\'t get the list of external mount points: {type}', 143						{type: error}), {type: 'error'}144					);145				},146				complete: function () {147					self.isGetMountPointListRunning = false;148				}149			});150		}151	},152	/**153	 * Function to manage action when a mountpoint status = 1 (Errored). Show a dialog to be redirected to settings page.154	 * @param {string} name MountPoint Name155	 */156	manageMountPointError: function (name) {157		this.getMountStatus($.proxy(function (allMountStatus) {158			if (allMountStatus.hasOwnProperty(name) && allMountStatus[name].status > 0 && allMountStatus[name].status < 7) {159				var mountData = allMountStatus[name];160				if (mountData.type === "system") {161					if (mountData.userProvided) {162						// personal mount whit credentials problems163						this.showCredentialsDialog(name, mountData);164					} else {165						OC.dialogs.confirm(t('files_external', 'There was an error with message: ') + mountData.error + '. Do you want to review mount point config in admin settings page?', t('files_external', 'External mount error'), function (e) {166							if (e === true) {167								if (OC.isUserAdmin()) {168									OC.redirect(OC.generateUrl('/settings/admin?sectionid=storage'));169								}170								else {171									OC.redirect(OC.generateUrl('/settings/personal?sectionid=storage'));172								}173							}174						}, true);175					}176				} else {177					OC.dialogs.confirm(t('files_external', 'There was an error with message: ') + mountData.error + '. Do you want to review mount point config in personal settings page?', t('files_external', 'External mount error'), function (e) {178						if (e === true) {179							OC.redirect(OC.generateUrl('/settings/personal?sectionid=storage'));180						}181					}, true);182				}183			}184		}, this));185	},186	/**187	 * Function to process a mount point in relation with their status, Called from Async Queue.188	 * @param {object} mountData189	 * @param {object} mountStatus190	 */191	processMountStatusIndividual: function (mountData, mountStatus) {192		var mountPoint = mountData.mount_point;193		if (mountStatus.status > 0) {194			var trElement = FileList.findFileEl(OCA.External.StatusManager.Utils.jqSelEscape(mountPoint));195			var route = OCA.External.StatusManager.Utils.getIconRoute(trElement) + '-error';196			if (OCA.External.StatusManager.Utils.isCorrectViewAndRootFolder()) {197				OCA.External.StatusManager.Utils.showIconError(mountPoint, $.proxy(OCA.External.StatusManager.manageMountPointError, OCA.External.StatusManager), route);198			}199			return false;200		} else {201			if (OCA.External.StatusManager.Utils.isCorrectViewAndRootFolder()) {202				OCA.External.StatusManager.Utils.restoreFolder(mountPoint);203				OCA.External.StatusManager.Utils.toggleLink(mountPoint, true, true);204			}205			return true;206		}207	},208	/**209	 * Function to process a mount point in relation with their status210	 * @param {object} mountData211	 * @param {object} mountStatus212	 */213	processMountList: function (mountList) {214		var elementList = null;215		$.each(mountList, function (name, value) {216			var trElement = $('#fileList tr[data-file=\"' + OCA.External.StatusManager.Utils.jqSelEscape(value.mount_point) + '\"]'); //FileList.findFileEl(OCA.External.StatusManager.Utils.jqSelEscape(value.mount_point));217			trElement.attr('data-external-backend', value.backend);218			if (elementList) {219				elementList = elementList.add(trElement);220			} else {221				elementList = trElement;222			}223		});224		if (elementList instanceof $) {225			if (OCA.External.StatusManager.Utils.isCorrectViewAndRootFolder()) {226				// Put their custom icon227				OCA.External.StatusManager.Utils.changeFolderIcon(elementList);228				// Save default view229				OCA.External.StatusManager.Utils.storeDefaultFolderIconAndBgcolor(elementList);230				// Disable row until check status231				elementList.addClass('externalDisabledRow');232				OCA.External.StatusManager.Utils.toggleLink(elementList.find('a.name'), false, false);233			}234		}235	},236	/**237	 * Function to process the whole mount point list in relation with their status (Async queue)238	 */239	launchFullConnectivityCheckOneByOne: function () {240		var self = this;241		this.getMountPointList(function (list) {242			// check if we have a list first243			if (list === undefined && !self.emptyWarningShown) {244				self.emptyWarningShown = true;245				OC.Notification.show(t('files_external', 'Couldn\'t get the list of Windows network drive mount points: empty response from the server'), 246					{type: 'error'}247				);248				return;249			}250			if (list && list.length > 0) {251				self.processMountList(list);252				if (!self.mountStatus) {253					self.mountStatus = {};254				}255				var ajaxQueue = [];256				$.each(list, function (key, value) {257					var queueElement = {258						funcName: $.proxy(self.getMountStatusForMount, self),259						funcArgs: [value,260							$.proxy(self.processMountStatusIndividual, self)]261					};262					ajaxQueue.push(queueElement);263				});264				var rolQueue = new OCA.External.StatusManager.RollingQueue(ajaxQueue, 4, function () {265					if (!self.notificationHasShown) {266						var showNotification = false;267						$.each(self.mountStatus, function (key, value) {268							if (value.status === 1) {269								self.notificationHasShown = true;270								showNotification = true;271							}272						});273						if (showNotification) {274							OC.Notification.show(t('files_external', 'Some of the configured external mount points are not connected. Please click on the red row(s) for more information'), 275								{type: 'error'}276							);277						}278					}279				});280				rolQueue.runQueue();281			}282		});283	},284	/**285	 * Function to process a mount point list in relation with their status (Async queue)286	 * @param {object} mountListData287	 * @param {boolean} recheck delete cached info and force api call to check mount point status288	 */289	launchPartialConnectivityCheck: function (mountListData, recheck) {290		if (mountListData.length === 0) {291			return;292		}293		var self = this;294		var ajaxQueue = [];295		$.each(mountListData, function (key, value) {296			if (recheck && value.mount_point in self.mountStatus) {297				delete self.mountStatus[value.mount_point];298			}299			var queueElement = {300				funcName: $.proxy(self.getMountStatusForMount, self),301				funcArgs: [value,302					$.proxy(self.processMountStatusIndividual, self)]303			};304			ajaxQueue.push(queueElement);305		});306		new OCA.External.StatusManager.RollingQueue(ajaxQueue, 4).runQueue();307	},308	/**309	 * Function to relaunch some mount point status check310	 * @param {string} mountListNames311	 * @param {boolean} recheck delete cached info and force api call to check mount point status312	 */313	recheckConnectivityForMount: function (mountListNames, recheck) {314		if (mountListNames.length === 0) {315			return;316		}317		var self = this;318		var mountListData = [];319		if (!self.mountStatus) {320			self.mountStatus = {};321		}322		$.each(mountListNames, function (key, value) {323			var mountData = self.getMountPointListElement(value);324			if (mountData) {325				mountListData.push(mountData);326			}327		});328		// for all mounts in the list, delete the cached status values329		if (recheck) {330			$.each(mountListData, function (key, value) {331				if (value.mount_point in self.mountStatus) {332					delete self.mountStatus[value.mount_point];333				}334			});335		}336		self.processMountList(mountListData);337		self.launchPartialConnectivityCheck(mountListData, recheck);338	},339	credentialsDialogTemplate:340		'<div id="files_external_div_form"><div>' +341		'<div>{{credentials_text}}</div>' +342		'<form>' +343		'<input type="text" name="username" placeholder="{{placeholder_username}}"/>' +344		'<input type="password" name="password" placeholder="{{placeholder_password}}" autocomplete="off"/>' +345		'</form>' +346		'</div></div>',347	/**348	 * Function to display custom dialog to enter credentials349	 * @param mountPoint350	 * @param mountData351	 */352	showCredentialsDialog: function (mountPoint, mountData) {353		var template = Handlebars.compile(OCA.External.StatusManager.credentialsDialogTemplate);354		var dialog = $(template({355			credentials_text: t('files_external', 'Please enter the credentials for the {mount} mount', {356				'mount': mountPoint357			}),358			placeholder_username: t('files_external', 'Username'),359			placeholder_password: t('files_external', 'Password')360		}));361		$('body').append(dialog);362		var apply = function () {363			var username = dialog.find('[name=username]').val();364			var password = dialog.find('[name=password]').val();365			var endpoint = OC.generateUrl('apps/files_external/userglobalstorages/{id}', {366				id: mountData.id367			});368			$('.oc-dialog-close').hide();369			$.ajax({370				type: 'PUT',371				url: endpoint,372				data: {373					backendOptions: {374						user: username,375						password: password376					}377				},378				success: function (data) {379					OC.Notification.show(t('files_external', 'Credentials saved'), {type: 'error'});380					dialog.ocdialog('close');381					/* Trigger status check again */382					OCA.External.StatusManager.recheckConnectivityForMount([OC.basename(data.mountPoint)], true);383				},384				error: function () {385					$('.oc-dialog-close').show();386					OC.Notification.show(t('files_external', 'Credentials saving failed'), {type: 'error'});387				}388			});389			return false;390		};391		var ocdialogParams = {392			modal: true,393			title: t('files_external', 'Credentials required'),394			buttons: [{395				text: t('files_external', 'Save'),396				click: apply,397				closeOnEscape: true398			}],399			closeOnExcape: true400		};401		dialog.ocdialog(ocdialogParams)402			.bind('ocdialogclose', function () {403				dialog.ocdialog('destroy').remove();404			});405		dialog.find('form').on('submit', apply);406		dialog.find('form input:first').focus();407		dialog.find('form input').keyup(function (e) {408			if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {409				$(e.target).closest('form').submit();410				return false;411			} else {412				return true;413			}414		});415	}416};417OCA.External.StatusManager.Utils = {418	showIconError: function (folder, clickAction, errorImageUrl) {419		var imageUrl = "url(" + errorImageUrl + ")";420		var trFolder = $('#fileList tr[data-file=\"' + OCA.External.StatusManager.Utils.jqSelEscape(folder) + '\"]'); //FileList.findFileEl(OCA.External.StatusManager.Utils.jqSelEscape(folder));421		this.changeFolderIcon(folder, imageUrl);422		this.toggleLink(folder, false, clickAction);423		trFolder.addClass('externalErroredRow');424	},425	/**426	 * @param folder string with the folder or jQuery element pointing to the tr element427	 */428	storeDefaultFolderIconAndBgcolor: function (folder) {429		var trFolder;430		if (folder instanceof $) {431			trFolder = folder;432		} else {433			trFolder = $('#fileList tr[data-file=\"' + OCA.External.StatusManager.Utils.jqSelEscape(folder) + '\"]'); //FileList.findFileEl(OCA.External.StatusManager.Utils.jqSelEscape(folder)); //$('#fileList tr[data-file=\"' + OCA.External.StatusManager.Utils.jqSelEscape(folder) + '\"]');434		}435		trFolder.each(function () {436			var thisElement = $(this);437			if (thisElement.data('oldbgcolor') === undefined) {438				thisElement.data('oldbgcolor', thisElement.css('background-color'));439			}440		});441		var icon = trFolder.find('td:first-child div.thumbnail');442		icon.each(function () {443			var thisElement = $(this);444			if (thisElement.data('oldImage') === undefined) {445				thisElement.data('oldImage', thisElement.css('background-image'));446			}447		});448	},449	/**450	 * @param folder string with the folder or jQuery element pointing to the tr element451	 */452	restoreFolder: function (folder) {453		var trFolder;454		if (folder instanceof $) {455			trFolder = folder;456		} else {457			// can't use here FileList.findFileEl(OCA.External.StatusManager.Utils.jqSelEscape(folder)); return incorrect instance of filelist458			trFolder = $('#fileList tr[data-file=\"' + OCA.External.StatusManager.Utils.jqSelEscape(folder) + '\"]');459		}460		trFolder.removeClass('externalErroredRow').removeClass('externalDisabledRow');461		tdChilds = trFolder.find("td:first-child div.thumbnail");462		tdChilds.each(function () {463			var thisElement = $(this);464			thisElement.css('background-image', thisElement.data('oldImage'));465		});466	},467	/**468	 * @param folder string with the folder or jQuery element pointing to the first td element469	 * of the tr matching the folder name470	 */471	changeFolderIcon: function (filename) {472		var file;473		var route;474		if (filename instanceof $) {475			//trElementList476			$.each(filename, function (index) {477				route = OCA.External.StatusManager.Utils.getIconRoute($(this));478				$(this).attr("data-icon", route);479				$(this).find('td:first-child div.thumbnail').css('background-image', "url(" + route + ")").css('display', 'none').css('display', 'inline');480			});481		} else {482			file = $("#fileList tr[data-file=\"" + this.jqSelEscape(filename) + "\"] > td:first-child div.thumbnail");483			parentTr = file.parents('tr:first');484			route = OCA.External.StatusManager.Utils.getIconRoute(parentTr);485			parentTr.attr("data-icon", route);486			file.css('background-image', "url(" + route + ")").css('display', 'none').css('display', 'inline');487		}488	},489	/**490	 * @param backend string with the name of the external storage backend491	 * of the tr matching the folder name492	 */493	getIconRoute: function (tr) {494		var icon = OC.MimeType.getIconUrl('dir-external');495		var backend = null;496		if (tr instanceof $) {497			backend = tr.attr('data-external-backend');498		}499		switch (backend) {500			case 'windows_network_drive':501				icon = OC.imagePath('windows_network_drive', 'folder-windows');502				break;503			case 'sharepoint':504				icon = OC.imagePath('sharepoint', 'folder-sharepoint');505				break;506		}507		return icon;508	},509	toggleLink: function (filename, active, action) {510		var link;511		if (filename instanceof $) {512			link = filename;513		} else {514			link = $("#fileList tr[data-file=\"" + this.jqSelEscape(filename) + "\"] > td:first-child a.name");515		}516		if (active) {517			link.off('click.connectivity');518			OCA.Files.App.fileList.fileActions.display(link.parent(), true, OCA.Files.App.fileList);519		} else {520			link.find('.fileactions, .nametext .action').remove();  // from files/js/fileactions (display)521			link.off('click.connectivity');522			link.on('click.connectivity', function (e) {523				if (action && $.isFunction(action)) {524					action(filename);525				}526				e.preventDefault();527				return false;528			});529		}530	},531	isCorrectViewAndRootFolder: function () {532		// correct views = files & extstoragemounts533		if (OCA.Files.App.getActiveView() === 'files' || OCA.Files.App.getActiveView() === 'extstoragemounts') {534			return OCA.Files.App.getCurrentAppContainer().find('#dir').val() === '/';535		}536		return false;537	},538	/* escape a selector expression for jQuery */539	jqSelEscape: function (expression) {540		if (expression) {541			return expression.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~]/g, '\\$&');542		}543		return null;544	},545	/* Copied from http://stackoverflow.com/questions/2631001/javascript-test-for-existence-of-nested-object-key */546	checkNested: function (cobj /*, level1, level2, ... levelN*/) {547		var args = Array.prototype.slice.call(arguments),548			obj = args.shift();549		for (var i = 0; i < args.length; i++) {550			if (!obj || !obj.hasOwnProperty(args[i])) {551				return false;552			}553			obj = obj[args[i]];554		}555		return true;556	}...

Full Screen

Full Screen

volume_manager.js

Source:volume_manager.js Github

copy

Full Screen

1// Copyright (c) 2012 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4/**5 * VolumeManager is responsible for tracking list of mounted volumes.6 *7 * @constructor8 * @extends {cr.EventTarget}9 */10function VolumeManager() {11  /**12   * The list of archives requested to mount. We will show contents once13   * archive is mounted, but only for mounts from within this filebrowser tab.14   * @type {Object.<string, Object>}15   * @private16   */17  this.requests_ = {};18  /**19   * @type {Object.<string, Object>}20   * @private21   */22  this.mountedVolumes_ = {};23  this.initMountPoints_();24  this.driveStatus_ = VolumeManager.DriveStatus.UNMOUNTED;25}26/**27 * VolumeManager extends cr.EventTarget.28 */29VolumeManager.prototype.__proto__ = cr.EventTarget.prototype;30/**31 * @enum32 */33VolumeManager.Error = {34  /* Internal errors */35  NOT_MOUNTED: 'not_mounted',36  TIMEOUT: 'timeout',37  /* System events */38  UNKNOWN: 'error_unknown',39  INTERNAL: 'error_internal',40  UNKNOWN_FILESYSTEM: 'error_unknown_filesystem',41  UNSUPPORTED_FILESYSTEM: 'error_unsupported_filesystem',42  INVALID_ARCHIVE: 'error_invalid_archive',43  AUTHENTICATION: 'error_authentication',44  PATH_UNMOUNTED: 'error_path_unmounted'45};46/**47 * @enum48 */49VolumeManager.DriveStatus = {50  UNMOUNTED: 'unmounted',51  MOUNTING: 'mounting',52  ERROR: 'error',53  MOUNTED: 'mounted'54};55/**56 * Time in milliseconds that we wait a respone for. If no response on57 * mount/unmount received the request supposed failed.58 */59VolumeManager.TIMEOUT = 15 * 60 * 1000;60/**61 * Delay in milliseconds DRIVE changes its state from |UNMOUNTED| to62 * |MOUNTING|. Used to display progress in the UI.63 */64VolumeManager.MOUNTING_DELAY = 500;65/**66 * @return {VolumeManager} Singleton instance.67 */68VolumeManager.getInstance = function() {69  return VolumeManager.instance_ = VolumeManager.instance_ ||70                                   new VolumeManager();71};72/**73 * @param {VolumeManager.DriveStatus} newStatus New DRIVE status.74 * @private75 */76VolumeManager.prototype.setDriveStatus_ = function(newStatus) {77  if (this.driveStatus_ != newStatus) {78    this.driveStatus_ = newStatus;79    cr.dispatchSimpleEvent(this, 'drive-status-changed');80  }81};82/**83 * @return {VolumeManager.DriveStatus} Current DRIVE status.84 */85VolumeManager.prototype.getDriveStatus = function() {86  return this.driveStatus_;87};88/**89 * @param {string} mountPath Volume root path.90 * @return {boolean} True if mounted.91 */92VolumeManager.prototype.isMounted = function(mountPath) {93  this.validateMountPath_(mountPath);94  return mountPath in this.mountedVolumes_;95};96/**97 * Initialized mount points.98 * @private99 */100VolumeManager.prototype.initMountPoints_ = function() {101  var mountedVolumes = [];102  var self = this;103  var index = 0;104  this.deferredQueue_ = [];105  function step(mountPoints) {106    if (index < mountPoints.length) {107      var info = mountPoints[index];108      if (info.mountType == 'drive')109        console.error('Drive is not expected initially mounted');110      var error = info.mountCondition ? 'error_' + info.mountCondition : '';111      function onVolumeInfo(volume) {112        mountedVolumes.push(volume);113        index++;114        step(mountPoints);115      }116      self.makeVolumeInfo_('/' + info.mountPath, error, onVolumeInfo);117    } else {118      for (var i = 0; i < mountedVolumes.length; i++) {119        var volume = mountedVolumes[i];120        self.mountedVolumes_[volume.mountPath] = volume;121      }122      // Subscribe to the mount completed event when mount points initialized.123      chrome.fileBrowserPrivate.onMountCompleted.addListener(124          self.onMountCompleted_.bind(self));125      var deferredQueue = self.deferredQueue_;126      self.deferredQueue_ = null;127      for (var i = 0; i < deferredQueue.length; i++) {128        deferredQueue[i]();129      }130      if (mountedVolumes.length > 0)131        cr.dispatchSimpleEvent(self, 'change');132    }133  }134  chrome.fileBrowserPrivate.getMountPoints(step);135};136/**137 * Event handler called when some volume was mounted or unmouted.138 * @param {MountCompletedEvent} event Received event.139 * @private140 */141VolumeManager.prototype.onMountCompleted_ = function(event) {142  if (event.eventType == 'mount') {143    if (event.mountPath) {144      var requestKey = this.makeRequestKey_(145          'mount', event.mountType, event.sourcePath);146      var error = event.status == 'success' ? '' : event.status;147      this.makeVolumeInfo_(event.mountPath, error, function(volume) {148        this.mountedVolumes_[volume.mountPath] = volume;149        this.finishRequest_(requestKey, event.status, event.mountPath);150        cr.dispatchSimpleEvent(this, 'change');151      }.bind(this));152    } else {153      console.log('No mount path');154      this.finishRequest_(requestKey, event.status);155    }156  } else if (event.eventType == 'unmount') {157    var mountPath = event.mountPath;158    this.validateMountPath_(mountPath);159    var status = event.status;160    if (status == VolumeManager.Error.PATH_UNMOUNTED) {161      console.log('Volume already unmounted: ', mountPath);162      status = 'success';163    }164    var requestKey = this.makeRequestKey_('unmount', '', event.mountPath);165    var requested = requestKey in this.requests_;166    if (event.status == 'success' && !requested &&167        mountPath in this.mountedVolumes_) {168      console.log('Mounted volume without a request: ', mountPath);169      var e = new cr.Event('externally-unmounted');170      e.mountPath = mountPath;171      this.dispatchEvent(e);172    }173    this.finishRequest_(requestKey, status);174    if (event.status == 'success') {175      delete this.mountedVolumes_[mountPath];176      cr.dispatchSimpleEvent(this, 'change');177    }178  }179  if (event.mountType == 'drive') {180    if (event.status == 'success') {181      if (event.eventType == 'mount') {182        // If the mount is not requested, the mount status will not be changed183        // at mountDrive(). Sets it here in such a case.184        var self = this;185        var timeout = setTimeout(function() {186          if (self.getDriveStatus() == VolumeManager.DriveStatus.UNMOUNTED)187            self.setDriveStatus_(VolumeManager.DriveStatus.MOUNTING);188          timeout = null;189        }, VolumeManager.MOUNTING_DELAY);190        this.waitDriveLoaded_(event.mountPath, function(success) {191          if (timeout != null)192            clearTimeout(timeout);193          this.setDriveStatus_(success ? VolumeManager.DriveStatus.MOUNTED :194                                         VolumeManager.DriveStatus.ERROR);195        }.bind(this));196      } else if (event.eventType == 'unmount') {197        this.setDriveStatus_(VolumeManager.DriveStatus.UNMOUNTED);198      }199    } else {200      this.setDriveStatus_(VolumeManager.DriveStatus.ERROR);201    }202  }203};204/**205 * First access to GDrive takes time (to fetch data from the cloud).206 * We want to change state to MOUNTED (likely from MOUNTING) when the207 * drive ready to operate.208 *209 * @param {string} mountPath Drive mount path.210 * @param {function(boolean, FileError=)} callback To be called when waiting211 *     finishes. If the case of error, there may be a FileError parameter.212 * @private213 */214VolumeManager.prototype.waitDriveLoaded_ = function(mountPath, callback) {215  chrome.fileBrowserPrivate.requestLocalFileSystem(function(filesystem) {216    filesystem.root.getDirectory(mountPath, {},217        callback.bind(null, true),218        callback.bind(null, false));219  });220};221/**222 * @param {string} mountPath Path to the volume.223 * @param {VolumeManager?} error Mounting error if any.224 * @param {function(Object)} callback Result acceptor.225 * @private226 */227VolumeManager.prototype.makeVolumeInfo_ = function(228    mountPath, error, callback) {229  if (error)230    this.validateError_(error);231  this.validateMountPath_(mountPath);232  function onVolumeMetadata(metadata) {233   callback({234     mountPath: mountPath,235     error: error,236     deviceType: metadata && metadata.deviceType,237     readonly: !!metadata && metadata.isReadOnly238   });239  }240  chrome.fileBrowserPrivate.getVolumeMetadata(241      util.makeFilesystemUrl(mountPath), onVolumeMetadata);242};243/**244 * Creates string to match mount events with requests.245 * @param {string} requestType 'mount' | 'unmount'.246 * @param {string} mountType 'device' | 'file' | 'network' | 'drive'.247 * @param {string} mountOrSourcePath Source path provided by API after248 *     resolving mount request or mountPath for unmount request.249 * @return {string} Key for |this.requests_|.250 * @private251 */252VolumeManager.prototype.makeRequestKey_ = function(requestType,253                                                   mountType,254                                                   mountOrSourcePath) {255  return requestType + ':' + mountType + ':' + mountOrSourcePath;256};257/**258 * @param {Function} successCallback Success callback.259 * @param {Function} errorCallback Error callback.260 */261VolumeManager.prototype.mountDrive = function(successCallback, errorCallback) {262  if (this.getDriveStatus() == VolumeManager.DriveStatus.ERROR) {263    this.setDriveStatus_(VolumeManager.DriveStatus.UNMOUNTED);264  }265  var self = this;266  this.mount_('', 'drive', function(mountPath) {267    this.waitDriveLoaded_(mountPath, function(success, error) {268      if (success) {269        successCallback(mountPath);270      } else {271        errorCallback(error);272      }273    });274  }, function(error) {275    if (self.getDriveStatus() != VolumeManager.DriveStatus.MOUNTED)276      self.setDriveStatus_(VolumeManager.DriveStatus.ERROR);277    errorCallback(error);278  });279};280/**281 * @param {string} fileUrl File url to the archive file.282 * @param {Function} successCallback Success callback.283 * @param {Function} errorCallback Error callback.284 */285VolumeManager.prototype.mountArchive = function(fileUrl, successCallback,286                                                errorCallback) {287  this.mount_(fileUrl, 'file', successCallback, errorCallback);288};289/**290 * Unmounts volume.291 * @param {string} mountPath Volume mounted path.292 * @param {Function} successCallback Success callback.293 * @param {Function} errorCallback Error callback.294 */295VolumeManager.prototype.unmount = function(mountPath,296                                           successCallback,297                                           errorCallback) {298  this.validateMountPath_(mountPath);299  if (this.deferredQueue_) {300    this.deferredQueue_.push(this.unmount.bind(this,301        mountPath, successCallback, errorCallback));302    return;303  }304  var volumeInfo = this.mountedVolumes_[mountPath];305  if (!volumeInfo) {306    errorCallback(VolumeManager.Error.NOT_MOUNTED);307    return;308  }309  chrome.fileBrowserPrivate.removeMount(util.makeFilesystemUrl(mountPath));310  var requestKey = this.makeRequestKey_('unmount', '', volumeInfo.mountPath);311  this.startRequest_(requestKey, successCallback, errorCallback);312};313/**314 * @param {string} mountPath Volume mounted path.315 * @return {VolumeManager.Error?} Returns mount error code316 *                                or undefined if no error.317 */318VolumeManager.prototype.getMountError = function(mountPath) {319  return this.getVolumeInfo_(mountPath).error;320};321/**322 * @param {string} mountPath Volume mounted path.323 * @return {boolean} True if volume at |mountedPath| is mounted but not usable.324 */325VolumeManager.prototype.isUnreadable = function(mountPath) {326  var error = this.getMountError(mountPath);327  return error == VolumeManager.Error.UNKNOWN_FILESYSTEM ||328         error == VolumeManager.Error.UNSUPPORTED_FILESYSTEM;329};330/**331 * @param {string} mountPath Volume mounted path.332 * @return {string} Device type ('usb'|'sd'|'optical'|'mobile'|'unknown')333 *   (as defined in chromeos/disks/disk_mount_manager.cc).334 */335VolumeManager.prototype.getDeviceType = function(mountPath) {336  return this.getVolumeInfo_(mountPath).deviceType;337};338/**339 * @param {string} mountPath Volume mounted path.340 * @return {boolean} True if volume at |mountedPath| is read only.341 */342VolumeManager.prototype.isReadOnly = function(mountPath) {343  return !!this.getVolumeInfo_(mountPath).readonly;344};345/**346 * Helper method.347 * @param {string} mountPath Volume mounted path.348 * @return {Object} Structure created in |startRequest_|.349 * @private350 */351VolumeManager.prototype.getVolumeInfo_ = function(mountPath) {352  this.validateMountPath_(mountPath);353  return this.mountedVolumes_[mountPath] || {};354};355/**356 * @param {string} url URL for for |fileBrowserPrivate.addMount|.357 * @param {'drive'|'file'} mountType Mount type for358 *     |fileBrowserPrivate.addMount|.359 * @param {Function} successCallback Success callback.360 * @param {Function} errorCallback Error callback.361 * @private362 */363VolumeManager.prototype.mount_ = function(url, mountType,364                                          successCallback, errorCallback) {365  if (this.deferredQueue_) {366    this.deferredQueue_.push(this.mount_.bind(this,367        url, mountType, successCallback, errorCallback));368    return;369  }370  chrome.fileBrowserPrivate.addMount(url, mountType, {},371                                     function(sourcePath) {372    console.log('Mount request: url=' + url + '; mountType=' + mountType +373                '; sourceUrl=' + sourcePath);374    var requestKey = this.makeRequestKey_('mount', mountType, sourcePath);375    this.startRequest_(requestKey, successCallback, errorCallback);376  }.bind(this));377};378/**379 * @param {sting} key Key produced by |makeRequestKey_|.380 * @param {Function} successCallback To be called when request finishes381 *                                   successfully.382 * @param {Function} errorCallback To be called when request fails.383 * @private384 */385VolumeManager.prototype.startRequest_ = function(key,386    successCallback, errorCallback) {387  if (key in this.requests_) {388    var request = this.requests_[key];389    request.successCallbacks.push(successCallback);390    request.errorCallbacks.push(errorCallback);391  } else {392    this.requests_[key] = {393      successCallbacks: [successCallback],394      errorCallbacks: [errorCallback],395      timeout: setTimeout(this.onTimeout_.bind(this, key),396                          VolumeManager.TIMEOUT)397    };398  }399};400/**401 * Called if no response received in |TIMEOUT|.402 * @param {sting} key Key produced by |makeRequestKey_|.403 * @private404 */405VolumeManager.prototype.onTimeout_ = function(key) {406  this.invokeRequestCallbacks_(this.requests_[key],407                               VolumeManager.Error.TIMEOUT);408  delete this.requests_[key];409};410/**411 * @param {sting} key Key produced by |makeRequestKey_|.412 * @param {VolumeManager.Error|'success'} status Status received from the API.413 * @param {string} opt_mountPath Mount path.414 * @private415 */416VolumeManager.prototype.finishRequest_ = function(key, status, opt_mountPath) {417  var request = this.requests_[key];418  if (!request)419    return;420  clearTimeout(request.timeout);421  this.invokeRequestCallbacks_(request, status, opt_mountPath);422  delete this.requests_[key];423};424/**425 * @param {object} request Structure created in |startRequest_|.426 * @param {VolumeManager.Error|string} status If status == 'success'427 *     success callbacks are called.428 * @param {string} opt_mountPath Mount path. Required if success.429 * @private430 */431VolumeManager.prototype.invokeRequestCallbacks_ = function(request, status,432                                                           opt_mountPath) {433  function callEach(callbacks, self, args) {434    for (var i = 0; i < callbacks.length; i++) {435      callbacks[i].apply(self, args);436    }437  }438  if (status == 'success') {439    callEach(request.successCallbacks, this, [opt_mountPath]);440  } else {441    this.validateError_(status);442    callEach(request.errorCallbacks, this, [status]);443  }444};445/**446 * @param {VolumeManager.Error} error Status string iusually received from API.447 * @private448 */449VolumeManager.prototype.validateError_ = function(error) {450  for (var i in VolumeManager.Error) {451    if (error == VolumeManager.Error[i])452      return;453  }454  throw new Error('Invalid mount error: ', error);455};456/**457 * @param {string} mountPath Mount path.458 * @private459 */460VolumeManager.prototype.validateMountPath_ = function(mountPath) {461  if (!/^\/(((archive|removable)\/[^\/]+)|drive|Downloads)$/.test(mountPath))462    throw new Error('Invalid mount path: ', mountPath);...

Full Screen

Full Screen

settings.js

Source:settings.js Github

copy

Full Screen

1(function(){2function updateStatus(statusEl, result){3	statusEl.removeClass('success error loading-small');4	if (result && result.status == 'success' && result.data.message) {5		statusEl.addClass('success');6		return true;7	} else {8		statusEl.addClass('error');9		return false;10	}11}12function getSelection($row) {13	var values = $row.find('.applicableUsers').select2('val');14	if (!values || values.length === 0) {15		values = ['all'];16	}17	return values;18}19OC.MountConfig={20	saveStorage:function(tr, callback) {21		var mountPoint = $(tr).find('.mountPoint input').val();22		var oldMountPoint = $(tr).find('.mountPoint input').data('mountpoint');23		if (mountPoint == '') {24			return false;25		}26		var statusSpan = $(tr).closest('tr').find('.status span');27		var backendClass = $(tr).find('.backend').data('class');28		var configuration = $(tr).find('.configuration input');29		var addMountPoint = true;30		if (configuration.length < 1) {31			return false;32		}33		var classOptions = {};34		$.each(configuration, function(index, input) {35			if ($(input).val() == '' && !$(input).hasClass('optional')) {36				addMountPoint = false;37				return false;38			}39			if ($(input).is(':checkbox')) {40				if ($(input).is(':checked')) {41					classOptions[$(input).data('parameter')] = true;42				} else {43					classOptions[$(input).data('parameter')] = false;44				}45			} else {46				classOptions[$(input).data('parameter')] = $(input).val();47			}48		});49		if ($('#externalStorage').data('admin') === true) {50			var multiselect = getSelection($(tr));51		}52		if (addMountPoint) {53			var status = false;54			if ($('#externalStorage').data('admin') === true) {55				var isPersonal = false;56				var oldGroups = $(tr).find('.applicable').data('applicable-groups');57				var oldUsers = $(tr).find('.applicable').data('applicable-users');58				var groups = [];59				var users = [];60				$.each(multiselect, function(index, value) {61					var pos = value.indexOf('(group)');62					if (pos != -1) {63						var mountType = 'group';64						var applicable = value.substr(0, pos);65						if ($.inArray(applicable, oldGroups) != -1) {66							oldGroups.splice($.inArray(applicable, oldGroups), 1);67						}68						groups.push(applicable);69					} else {70						var mountType = 'user';71						var applicable = value;72						if ($.inArray(applicable, oldUsers) != -1) {73							oldUsers.splice($.inArray(applicable, oldUsers), 1);74						}75						users.push(applicable);76					}77					statusSpan.addClass('loading-small').removeClass('error success');78					$.ajax({type: 'POST',79						url: OC.filePath('files_external', 'ajax', 'addMountPoint.php'),80						data: {81							mountPoint: mountPoint,82							'class': backendClass,83							classOptions: classOptions,84							mountType: mountType,85							applicable: applicable,86							isPersonal: isPersonal,87							oldMountPoint: oldMountPoint88						},89						success: function(result) {90							$(tr).find('.mountPoint input').data('mountpoint', mountPoint);91							status = updateStatus(statusSpan, result);92							if (callback) {93								callback(status);94							}95						},96						error: function(result){97							status = updateStatus(statusSpan, result);98							if (callback) {99								callback(status);100							}101						}102					});103				});104				$(tr).find('.applicable').data('applicable-groups', groups);105				$(tr).find('.applicable').data('applicable-users', users);106				var mountType = 'group';107				$.each(oldGroups, function(index, applicable) {108					$.ajax({type: 'POST',109						url: OC.filePath('files_external', 'ajax', 'removeMountPoint.php'),110						data: {111							mountPoint: mountPoint,112							'class': backendClass,113							classOptions: classOptions,114							mountType: mountType,115							applicable: applicable,116							isPersonal: isPersonal117						}118					});119				});120				var mountType = 'user';121				$.each(oldUsers, function(index, applicable) {122					$.ajax({type: 'POST',123						url: OC.filePath('files_external', 'ajax', 'removeMountPoint.php'),124						data: {125							mountPoint: mountPoint,126							'class': backendClass,127							classOptions: classOptions,128							mountType: mountType,129							applicable: applicable,130							isPersonal: isPersonal131						}132					});133				});134			} else {135				var isPersonal = true;136				var mountType = 'user';137				var applicable = OC.currentUser;138				statusSpan.addClass('loading-small').removeClass('error success');139				$.ajax({type: 'POST',140					url: OC.filePath('files_external', 'ajax', 'addMountPoint.php'),141					data: {142						mountPoint: mountPoint,143						'class': backendClass,144						classOptions: classOptions,145						mountType: mountType,146						applicable: applicable,147						isPersonal: isPersonal,148						oldMountPoint: oldMountPoint149					},150					success: function(result) {151						$(tr).find('.mountPoint input').data('mountpoint', mountPoint);152						status = updateStatus(statusSpan, result);153						if (callback) {154							callback(status);155						}156					},157					error: function(result){158						status = updateStatus(statusSpan, result);159						if (callback) {160							callback(status);161						}162					}163				});164			}165			return status;166		}167	}168};169$(document).ready(function() {170	//initialize hidden input field with list of users and groups171	$('#externalStorage').find('tr:not(#addMountPoint)').each(function(i,tr) {172		var applicable = $(tr).find('.applicable');173		if (applicable.length > 0) {174			var groups = applicable.data('applicable-groups');175			var groupsId = [];176			$.each(groups, function () {177				groupsId.push(this+"(group)");178			});179			var users = applicable.data('applicable-users');180			if (users.indexOf('all') > -1) {181				$(tr).find('.applicableUsers').val('');182			} else {183				$(tr).find('.applicableUsers').val(groupsId.concat(users).join(','));184			}185		}186	});187	var userListLimit = 30;188	function addSelect2 ($elements) {189		if ($elements.length > 0) {190			$elements.select2({191				placeholder: t('files_external', 'All users. Type to select user or group.'),192				allowClear: true,193				multiple: true,194				//minimumInputLength: 1,195				ajax: {196					url: OC.generateUrl('apps/files_external/applicable'),197					dataType: 'json',198					quietMillis: 100,199					data: function (term, page) { // page is the one-based page number tracked by Select2200						return {201							pattern: term, //search term202							limit: userListLimit, // page size203							offset: userListLimit*(page-1) // page number starts with 0204						};205					},206					results: function (data, page) {207						if (data.status === "success") {208							var results = [];209							var userCount = 0; // users is an object210							// add groups211							$.each(data.groups, function(i, group) {212								results.push({name:group+'(group)', displayname:group, type:'group' });213							});214							// add users215							$.each(data.users, function(id, user) {216								userCount++;217								results.push({name:id, displayname:user, type:'user' });218							});219							var more = (userCount >= userListLimit) || (data.groups.length >= userListLimit);220							return {results: results, more: more};221						} else {222							//FIXME add error handling223						}224					}225				},226				initSelection: function(element, callback) {227					var promises = [];228					var results = [];229					$(element.val().split(",")).each(function (i,userId) {230						var def = new $.Deferred();231						promises.push(def.promise());232						var pos = userId.indexOf('(group)');233						if (pos !== -1) {234							//add as group235							results.push({name:userId, displayname:userId.substr(0, pos), type:'group'});236							def.resolve();237						} else {238							$.ajax(OC.generateUrl('apps/files_external/applicable'), {239								data: {240									pattern: userId241								},242								dataType: "json"243							}).done(function(data) {244								if (data.status === "success") {245									if (data.users[userId]) {246										results.push({name:userId, displayname:data.users[userId], type:'user'});247									}248									def.resolve();249								} else {250									//FIXME add error handling251								}252							});253						}254					});255					$.when.apply(undefined, promises).then(function(){256						callback(results);257					});258				},259				id: function(element) {260					return element.name;261				},262				formatResult: function (element) {263					var $result = $('<span><div class="avatardiv"/><span>'+escapeHTML(element.displayname)+'</span></span>');264					var $div = $result.find('.avatardiv')265						.attr('data-type', element.type)266						.attr('data-name', element.name)267						.attr('data-displayname', element.displayname);268					if (element.type === 'group') {269						var url = OC.imagePath('core','places/contacts-dark'); // TODO better group icon270						$div.html('<img width="32" height="32" src="'+url+'">');271					}272					return $result.get(0).outerHTML;273				},274				formatSelection: function (element) {275					if (element.type === 'group') {276						return '<span title="'+escapeHTML(element.name)+'" class="group">'+escapeHTML(element.displayname+' '+t('files_external', '(group)'))+'</span>';277					} else {278						return '<span title="'+escapeHTML(element.name)+'" class="user">'+escapeHTML(element.displayname)+'</span>';279					}280				},281				escapeMarkup: function (m) { return m; } // we escape the markup in formatResult and formatSelection282			}).on("select2-loaded", function() {283				$.each($(".avatardiv"), function(i, div) {284					$div = $(div);285					if ($div.data('type') === 'user') {286						$div.avatar($div.data('name'),32);287					}288				})289			});290		}291	}292	addSelect2($('tr:not(#addMountPoint) .applicableUsers'));293	294	$('#externalStorage').on('change', '#selectBackend', function() {295		var tr = $(this).parent().parent();296		$('#externalStorage tbody').append($(tr).clone());297		$('#externalStorage tbody tr').last().find('.mountPoint input').val('');298		var selected = $(this).find('option:selected').text();299		var backendClass = $(this).val();300		$(this).parent().text(selected);301		if ($(tr).find('.mountPoint input').val() == '') {302			$(tr).find('.mountPoint input').val(suggestMountPoint(selected));303		}304		$(tr).addClass(backendClass);305		$(tr).find('.status').append('<span></span>');306		$(tr).find('.backend').data('class', backendClass);307		var configurations = $(this).data('configurations');308		var td = $(tr).find('td.configuration');309		$.each(configurations, function(backend, parameters) {310			if (backend == backendClass) {311				$.each(parameters['configuration'], function(parameter, placeholder) {312					var is_optional = false;313					if (placeholder.indexOf('&') === 0) {314						is_optional = true;315						placeholder = placeholder.substring(1);316					}317					if (placeholder.indexOf('*') === 0) {318						var class_string = is_optional ? ' optional' : '';319						td.append('<input type="password" class="added' + class_string + '" data-parameter="'+parameter+'" placeholder="'+placeholder.substring(1)+'" />');320					} else if (placeholder.indexOf('!') === 0) {321						td.append('<label><input type="checkbox" class="added" data-parameter="'+parameter+'" />'+placeholder.substring(1)+'</label>');322					} else if (placeholder.indexOf('#') === 0) {323						td.append('<input type="hidden" class="added" data-parameter="'+parameter+'" />');324					} else {325						var class_string = is_optional ? ' optional' : '';326						td.append('<input type="text" class="added' + class_string + '" data-parameter="'+parameter+'" placeholder="'+placeholder+'" />');327					}328				});329				if (parameters['custom'] && $('#externalStorage tbody tr.'+backendClass.replace(/\\/g, '\\\\')).length == 1) {330					OC.addScript('files_external', parameters['custom']);331				}332				return false;333			}334		});335		$(tr).find('td').last().attr('class', 'remove');336		$(tr).find('td').last().removeAttr('style');337		$(tr).removeAttr('id');338		$(this).remove();339		addSelect2(tr.find('.applicableUsers'));340	});341	function suggestMountPoint(defaultMountPoint) {342		var pos = defaultMountPoint.indexOf('/');343		if (pos !== -1) {344			defaultMountPoint = defaultMountPoint.substring(0, pos);345		}346		defaultMountPoint = defaultMountPoint.replace(/\s+/g, '');347		var i = 1;348		var append = '';349		var match = true;350		while (match && i < 20) {351			match = false;352			$('#externalStorage tbody td.mountPoint input').each(function(index, mountPoint) {353				if ($(mountPoint).val() == defaultMountPoint+append) {354					match = true;355					return false;356				}357			});358			if (match) {359				append = i;360				i++;361			} else {362				break;363			}364		}365		return defaultMountPoint+append;366	}367	$('#externalStorage').on('paste', 'td', function() {368		var tr = $(this).parent();369		setTimeout(function() {370			OC.MountConfig.saveStorage(tr);371		}, 20);372	});373	var timer;374	$('#externalStorage').on('keyup', 'td input', function() {375		clearTimeout(timer);376		var tr = $(this).parent().parent();377		if ($(this).val) {378			timer = setTimeout(function() {379				OC.MountConfig.saveStorage(tr);380			}, 2000);381		}382	});383	$('#externalStorage').on('change', 'td input:checkbox', function() {384		OC.MountConfig.saveStorage($(this).parent().parent().parent());385	});386	$('#externalStorage').on('change', '.applicable', function() {387		OC.MountConfig.saveStorage($(this).parent());388	});389	$('#sslCertificate').on('click', 'td.remove>img', function() {390		var $tr = $(this).parent().parent();391		var row = this.parentNode.parentNode;392		$.post(OC.filePath('files_external', 'ajax', 'removeRootCertificate.php'), {cert: row.id});393		$tr.remove();394		return true;395	});396	$('#externalStorage').on('click', 'td.remove>img', function() {397		var tr = $(this).parent().parent();398		var mountPoint = $(tr).find('.mountPoint input').val();399		if ($('#externalStorage').data('admin') === true) {400			var isPersonal = false;401			var multiselect = getSelection($(tr));402			$.each(multiselect, function(index, value) {403				var pos = value.indexOf('(group)');404				if (pos != -1) {405					var mountType = 'group';406					var applicable = value.substr(0, pos);407				} else {408					var mountType = 'user';409					var applicable = value;410				}411				$.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });412			});413		} else {414			var mountType = 'user';415			var applicable = OC.currentUser;416			var isPersonal = true;417			$.post(OC.filePath('files_external', 'ajax', 'removeMountPoint.php'), { mountPoint: mountPoint, mountType: mountType, applicable: applicable, isPersonal: isPersonal });418		}419		$(tr).remove();420	});421	$('#allowUserMounting').bind('change', function() {422		OC.msg.startSaving('#userMountingMsg');423		if (this.checked) {424			OC.AppConfig.setValue('files_external', 'allow_user_mounting', 'yes');425			$('input[name="allowUserMountingBackends\\[\\]"]').prop('checked', true);426			$('#userMountingBackends').removeClass('hidden');427			$('input[name="allowUserMountingBackends\\[\\]"]').eq(0).trigger('change');428		} else {429			OC.AppConfig.setValue('files_external', 'allow_user_mounting', 'no');430			$('#userMountingBackends').addClass('hidden');431		}432		OC.msg.finishedSaving('#userMountingMsg', {status: 'success', data: {message: t('settings', 'Saved')}});433	});434	$('input[name="allowUserMountingBackends\\[\\]"]').bind('change', function() {435		OC.msg.startSaving('#userMountingMsg');436		var userMountingBackends = $('input[name="allowUserMountingBackends\\[\\]"]:checked').map(function(){return $(this).val();}).get();437		OC.AppConfig.setValue('files_external', 'user_mounting_backends', userMountingBackends.join());438		OC.msg.finishedSaving('#userMountingMsg', {status: 'success', data: {message: t('settings', 'Saved')}});439		// disable allowUserMounting440		if(userMountingBackends.length === 0) {441			$('#allowUserMounting').prop('checked', false);442			$('#allowUserMounting').trigger('change');443		}444	});445});...

Full Screen

Full Screen

ReactDoubleInvokeEvents-test.internal.js

Source:ReactDoubleInvokeEvents-test.internal.js Github

copy

Full Screen

...211      componentDidUpdate() {212        this.test();213        Scheduler.unstable_yieldValue('componentDidUpdate');214      }215      componentWillUnmount() {216        this.test();217        Scheduler.unstable_yieldValue('componentWillUnmount');218      }219      render() {220        return null;221      }222    }223    ReactNoop.act(() => {224      ReactNoop.render(<App />);225    });226    if (__DEV__ && __VARIANT__) {227      expect(Scheduler).toHaveYielded([228        'componentDidMount',229        'componentWillUnmount',230        'componentDidMount',231      ]);232    } else {233      expect(Scheduler).toHaveYielded(['componentDidMount']);234    }235  });236  it('double invoking works for class components', () => {237    class App extends React.PureComponent {238      componentDidMount() {239        Scheduler.unstable_yieldValue('componentDidMount');240      }241      componentDidUpdate() {242        Scheduler.unstable_yieldValue('componentDidUpdate');243      }244      componentWillUnmount() {245        Scheduler.unstable_yieldValue('componentWillUnmount');246      }247      render() {248        return this.props.text;249      }250    }251    ReactNoop.act(() => {252      ReactNoop.render(<App text={'mount'} />);253    });254    if (__DEV__ && __VARIANT__) {255      expect(Scheduler).toHaveYielded([256        'componentDidMount',257        'componentWillUnmount',258        'componentDidMount',259      ]);260    } else {261      expect(Scheduler).toHaveYielded(['componentDidMount']);262    }263    ReactNoop.act(() => {264      ReactNoop.render(<App text={'update'} />);265    });266    expect(Scheduler).toHaveYielded(['componentDidUpdate']);267    ReactNoop.act(() => {268      ReactNoop.render(null);269    });270    expect(Scheduler).toHaveYielded(['componentWillUnmount']);271  });272  it('double flushing passive effects only results in one double invoke', () => {273    function App({text}) {274      const [state, setState] = React.useState(0);275      React.useEffect(() => {276        if (state !== 1) {277          setState(1);278        }279        Scheduler.unstable_yieldValue('useEffect mount');280        return () => Scheduler.unstable_yieldValue('useEffect unmount');281      });282      React.useLayoutEffect(() => {283        Scheduler.unstable_yieldValue('useLayoutEffect mount');284        return () => Scheduler.unstable_yieldValue('useLayoutEffect unmount');285      });286      Scheduler.unstable_yieldValue(text);287      return text;288    }289    ReactNoop.act(() => {290      ReactNoop.render(<App text={'mount'} />);291    });292    if (__DEV__ && __VARIANT__) {293      expect(Scheduler).toHaveYielded([294        'mount',295        'useLayoutEffect mount',296        'useEffect mount',297        'useLayoutEffect unmount',298        'useEffect unmount',299        'useLayoutEffect mount',300        'useEffect mount',301        'mount',302        'useLayoutEffect unmount',303        'useLayoutEffect mount',304        'useEffect unmount',305        'useEffect mount',306      ]);307    } else {308      expect(Scheduler).toHaveYielded([309        'mount',310        'useLayoutEffect mount',311        'useEffect mount',312        'mount',313        'useLayoutEffect unmount',314        'useLayoutEffect mount',315        'useEffect unmount',316        'useEffect mount',317      ]);318    }319  });320  it('newly mounted components after initial mount get double invoked', () => {321    let _setShowChild;322    function Child() {323      React.useEffect(() => {324        Scheduler.unstable_yieldValue('Child useEffect mount');325        return () => Scheduler.unstable_yieldValue('Child useEffect unmount');326      });327      React.useLayoutEffect(() => {328        Scheduler.unstable_yieldValue('Child useLayoutEffect mount');329        return () =>330          Scheduler.unstable_yieldValue('Child useLayoutEffect unmount');331      });332      return null;333    }334    function App() {335      const [showChild, setShowChild] = React.useState(false);336      _setShowChild = setShowChild;337      React.useEffect(() => {338        Scheduler.unstable_yieldValue('App useEffect mount');339        return () => Scheduler.unstable_yieldValue('App useEffect unmount');340      });341      React.useLayoutEffect(() => {342        Scheduler.unstable_yieldValue('App useLayoutEffect mount');343        return () =>344          Scheduler.unstable_yieldValue('App useLayoutEffect unmount');345      });346      return showChild && <Child />;347    }348    ReactNoop.act(() => {349      ReactNoop.render(<App />);350    });351    if (__DEV__ && __VARIANT__) {352      expect(Scheduler).toHaveYielded([353        'App useLayoutEffect mount',354        'App useEffect mount',355        'App useLayoutEffect unmount',356        'App useEffect unmount',357        'App useLayoutEffect mount',358        'App useEffect mount',359      ]);360    } else {361      expect(Scheduler).toHaveYielded([362        'App useLayoutEffect mount',363        'App useEffect mount',364      ]);365    }366    ReactNoop.act(() => {367      _setShowChild(true);368    });369    if (__DEV__ && __VARIANT__) {370      expect(Scheduler).toHaveYielded([371        'App useLayoutEffect unmount',372        'Child useLayoutEffect mount',373        'App useLayoutEffect mount',374        'App useEffect unmount',375        'Child useEffect mount',376        'App useEffect mount',377        'Child useLayoutEffect unmount',378        'Child useEffect unmount',379        'Child useLayoutEffect mount',380        'Child useEffect mount',381      ]);382    } else {383      expect(Scheduler).toHaveYielded([384        'App useLayoutEffect unmount',385        'Child useLayoutEffect mount',386        'App useLayoutEffect mount',387        'App useEffect unmount',388        'Child useEffect mount',389        'App useEffect mount',390      ]);391    }392  });393  it('classes and functions are double invoked together correctly', () => {394    class ClassChild extends React.PureComponent {395      componentDidMount() {396        Scheduler.unstable_yieldValue('componentDidMount');397      }398      componentWillUnmount() {399        Scheduler.unstable_yieldValue('componentWillUnmount');400      }401      render() {402        return this.props.text;403      }404    }405    function FunctionChild({text}) {406      React.useEffect(() => {407        Scheduler.unstable_yieldValue('useEffect mount');408        return () => Scheduler.unstable_yieldValue('useEffect unmount');409      });410      React.useLayoutEffect(() => {411        Scheduler.unstable_yieldValue('useLayoutEffect mount');412        return () => Scheduler.unstable_yieldValue('useLayoutEffect unmount');...

Full Screen

Full Screen

index.spec.js

Source:index.spec.js Github

copy

Full Screen

...22    expect(wrapper).toMatchSnapshot();23  });24  testCommonProps(Input); 25  it("type='url' should show error state",function(){26    const wrapper = mount(27      <Input 28        name="test"29        type="url"30        value="test"31      />32    );33    const antdInputMount = getAntdFormComponentMount(wrapper);34    const antdFormItemMount = getAntdFormItemMount(wrapper);35    //有label时,className="ant-form-item-label"36    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-error");37  })38  it("type='url' should show success state",function(){39    const wrapper = mount(40      <Input 41        name="test"42        type="url"43        value="http://www.github.com/"44      />45    );46    const antdInputMount = getAntdFormComponentMount(wrapper);47    const antdFormItemMount = getAntdFormItemMount(wrapper);48    //有label时,className="ant-form-item-label"49    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-success");50  })51  it("type='email' should show error state",function(){52    const wrapper = mount(53      <Input 54        name="test"55        type="email"56        value="test"57      />58    );59    const antdInputMount = getAntdFormComponentMount(wrapper);60    const antdFormItemMount = getAntdFormItemMount(wrapper);61    //有label时,className="ant-form-item-label"62    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-error");63  })64  it("type='email' should show success state",function(){65    const wrapper = mount(66      <Input 67        name="test"68        type="email"69        value="xianshannan@qq.com"70      />71    );72    const antdInputMount = getAntdFormComponentMount(wrapper);73    const antdFormItemMount = getAntdFormItemMount(wrapper);74    //有label时,className="ant-form-item-label"75    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-success");76  })77  it("type='phone' should show error state",function(){78    const wrapper = mount(79      <Input 80        name="test"81        type="phone"82        value="111"83      />84    );85    const antdInputMount = getAntdFormComponentMount(wrapper);86    const antdFormItemMount = getAntdFormItemMount(wrapper);87    //有label时,className="ant-form-item-label"88    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-error");89  })90  it("type='phone' should show success state",function(){91    const wrapper = mount(92      <Input 93        name="test"94        type="phone"95        value="15989350865"96      />97    );98    const antdInputMount = getAntdFormComponentMount(wrapper);99    const antdFormItemMount = getAntdFormItemMount(wrapper);100    //有label时,className="ant-form-item-label"101    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-success");102  })103  it("type='textarea' should work",function(){104    const wrapper = mount(105      <Input 106        name="test"107        type="textarea"108      />109    );110    const antdInputMount = getAntdFormComponentMount(wrapper);111    const antdFormItemMount = getAntdFormItemMount(wrapper);112    expect(antdInputMount.props().type).toEqual("textarea");113  })114  it("type='hidden' should work",function(){115    const wrapper = mount(116      <Input 117        name="test"118        type="hidden"119      />120    );121    expect(wrapper.props().type).toEqual("hidden");122  })123  it("min='5' should show success state",function(){124    const wrapper = mount(125      <Input 126        name="test"127        type="text"128        value="111111"129        min={ 5 }130      />131    );132    const antdInputMount = getAntdFormComponentMount(wrapper);133    const antdFormItemMount = getAntdFormItemMount(wrapper);134    //有label时,className="ant-form-item-label"135    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-success");136  })137  it("min='5' should show error state",function(){138    const wrapper = mount(139      <Input 140        name="test"141        type="text"142        value="111"143        min={ 6 }144      />145    );146    const antdInputMount = getAntdFormComponentMount(wrapper);147    const antdFormItemMount = getAntdFormItemMount(wrapper);148    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-error");149  })150  it("max='5' should show success state",function(){151    const wrapper = mount(152      <Input 153        name="test"154        type="text"155        value="111"156        max={ 5 }157      />158    );159    const antdInputMount = getAntdFormComponentMount(wrapper);160    const antdFormItemMount = getAntdFormItemMount(wrapper);161    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-success");162  })163  it("max='5' should show error state",function(){164    const wrapper = mount(165      <Input 166        name="test"167        type="text"168        value="1111111"169        max={ 5 }170      />171    );172    const antdInputMount = getAntdFormComponentMount(wrapper);173    const antdFormItemMount = getAntdFormItemMount(wrapper);174    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-error");175  })176  it("min='2' && max='5' should show success state",function(){177    const wrapper = mount(178      <Input 179        name="test"180        type="text"181        value="111"182        min={ 2 }183        max={ 5 }184      />185    );186    const antdInputMount = getAntdFormComponentMount(wrapper);187    const antdFormItemMount = getAntdFormItemMount(wrapper);188    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-success");189  })190  it("min='2' && max='5' && value='1111111111' should show error state",function(){191    const wrapper = mount(192      <Input 193        name="test"194        type="text"195        value="1111111111"196        min="2"197        max="5"198      />199    );200    const antdInputMount = getAntdFormComponentMount(wrapper);201    const antdFormItemMount = getAntdFormItemMount(wrapper);202    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-error");203  })204  it("min='2' && max='5' && value='1' should show error state",function(){205    const wrapper = mount(206      <Input 207        name="test"208        type="text"209        value="1"210        min="2"211        max="5"212      />213    );214    const antdInputMount = getAntdFormComponentMount(wrapper);215    const antdFormItemMount = getAntdFormItemMount(wrapper);216    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-error");217  })218  it("onlyLetter=true should show success state",function(){219    const wrapper = mount(220      <Input 221        name="test"222        type="text"223        value="sdd"224        onlyLetter={ true }225      />226    );227    const antdInputMount = getAntdFormComponentMount(wrapper);228    const antdFormItemMount = getAntdFormItemMount(wrapper);229    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-success");230  })231  it("onlyLetter=true should show error state",function(){232    const wrapper = mount(233      <Input 234        name="test"235        type="text"236        value="取值"237        onlyLetter={ true }238      />239    );240    const antdInputMount = getAntdFormComponentMount(wrapper);241    const antdFormItemMount = getAntdFormItemMount(wrapper);242    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-control has-error");243  })244  it("array=true should work",function(){245    const wrapper = mount(246      <Input 247        name="test"248        type="text"249        array={ true }250        value={251          [2,3]252        }253      />254    );255    expect(wrapper.childAt(0).childAt(0).props().children.length).toEqual(2);256  })...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

1// Copyright (c) 2012 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4// These have to be sync'd with file_browser_private_apitest.cc5var expectedVolume1 = {6  devicePath: 'device_path1',7  mountPath: 'removable/mount_path1',8  systemPath: 'system_path1',9  filePath: 'file_path1',10  deviceLabel: 'device_label1',11  driveLabel: 'drive_label1',12  deviceType: 'usb',13  totalSize: 1073741824,14  isParent: false,15  isReadOnly: false,16  hasMedia: false,17  isOnBootDevice: false18};19var expectedVolume2 = {20  devicePath: 'device_path2',21  mountPath: 'removable/mount_path2',22  systemPath: 'system_path2',23  filePath: 'file_path2',24  deviceLabel: 'device_label2',25  driveLabel: 'drive_label2',26  deviceType: 'mobile',27  totalSize: 47723,28  isParent: true,29  isReadOnly: true,30  hasMedia: true,31  isOnBootDevice: true32};33var expectedVolume3 = {34  devicePath: 'device_path3',35  mountPath: 'removable/mount_path3',36  systemPath: 'system_path3',37  filePath: 'file_path3',38  deviceLabel: 'device_label3',39  driveLabel: 'drive_label3',40  deviceType: 'optical',41  totalSize: 0,42  isParent: true,43  isReadOnly: false,44  hasMedia: false,45  isOnBootDevice: true46};47// List of expected mount points.48// NOTE: this has to be synced with values in file_browser_private_apitest.cc49//       and values sorted by mountPath.50var expectedMountPoints = [51  {52    sourcePath: '/media/removable/archive_path',53    mountPath: 'archive/archive_mount_path',54    mountType: 'file',55    mountCondition: ''56  },57  {58    sourcePath: 'device_path1',59    mountPath: 'removable/mount_path1',60    mountType: 'device',61    mountCondition: ''62  },63  {64    sourcePath: 'device_path2',65    mountPath: 'removable/mount_path2',66    mountType: 'device',67    mountCondition: ''68  },69  {70    sourcePath: 'device_path3',71    mountPath: 'removable/mount_path3',72    mountType: 'device',73    mountCondition: ''74  }75];76function validateObject(received, expected, name) {77  for (var key in expected) {78    if (received[key] != expected[key]) {79      console.warn('Expected "' + key + '" ' + name + ' property to be: "' +80                  expected[key] + '"' + ', but got: "' + received[key] +81                  '" instead.');82      return false;83    }84  }85  if (Object.keys(expected).length != Object.keys(received).length) {86    console.warn('Unexpected property found in returned volume');87    return false;88  }89  return true;90}91function createFileUrl(fileName) {92  var testExtensionId = 'ddammdhioacbehjngdmkjcjbnfginlla';93  var fileUrl = 'filesystem:chrome-extension://' + testExtensionId +94                '/external/' + fileName;95  return fileUrl;96}97chrome.test.runTests([98  function removeMount() {99    // The ID of this extension.100    var fileUrl = createFileUrl('archive/archive_mount_path');101    chrome.fileBrowserPrivate.removeMount(fileUrl);102    // We actually check this one on C++ side. If MountLibrary.RemoveMount103    // doesn't get called, test will fail.104    chrome.test.succeed();105  },106  function getVolumeMetadataValid1() {107    chrome.fileBrowserPrivate.getVolumeMetadata(108        createFileUrl(expectedVolume1.mountPath),109        chrome.test.callbackPass(function(result) {110          chrome.test.assertTrue(111              validateObject(result, expectedVolume1, 'volume'),112              'getVolumeMetadata result for first volume not as expected');113    }));114  },115  function getVolumeMetadataValid2() {116    chrome.fileBrowserPrivate.getVolumeMetadata(117        createFileUrl(expectedVolume2.mountPath),118        chrome.test.callbackPass(function(result) {119          chrome.test.assertTrue(120              validateObject(result, expectedVolume2, 'volume'),121              'getVolumeMetadata result for second volume not as expected');122    }));123  },124  function getVolumeMetadataValid3() {125    chrome.fileBrowserPrivate.getVolumeMetadata(126        createFileUrl(expectedVolume3.mountPath),127        chrome.test.callbackPass(function(result) {128          chrome.test.assertTrue(129              validateObject(result, expectedVolume3, 'volume'),130              'getVolumeMetadata result for third volume not as expected');131    }));132  },133  function getVolumeMetadataNonExistentPath() {134    chrome.fileBrowserPrivate.getVolumeMetadata(135        createFileUrl('removable/non_existent_device_path'),136        chrome.test.callbackPass(function(result) {137          chrome.test.assertEq(undefined, result);138    }));139  },140  function getVolumeMetadataArchive() {141    chrome.fileBrowserPrivate.getVolumeMetadata(142        createFileUrl('archive/archive_mount_path'),143        chrome.test.callbackPass(function(result) {144          chrome.test.assertEq(undefined, result);145   }));146  },147  function getVolumeMetadataInvalidPath() {148    chrome.fileBrowserPrivate.getVolumeMetadata(149        'some path',150        chrome.test.callbackFail('Invalid mount path.'));151  },152  function getMountPointsTest() {153    chrome.fileBrowserPrivate.getMountPoints(154        chrome.test.callbackPass(function(result) {155          chrome.test.assertEq(result.length, expectedMountPoints.length,156              'getMountPoints returned wrong number of mount points.');157          for (var i = 0; i < expectedMountPoints.length; i++) {158            chrome.test.assertTrue(159                validateObject(result[i], expectedMountPoints[i], 'mountPoint'),160                'getMountPoints result[' + i + '] not as expected');161          }162    }));163  }...

Full Screen

Full Screen

common.js

Source:common.js Github

copy

Full Screen

...18  return mountComponent.childAt(0);19}20export function testCommonProps(Component,type){21  it("should not have props",function(){22    const wrapper = mount(23      <Component />24    );25    //console.log(wrapper.props())26    const antdInputMount = getAntdFormComponentMount(wrapper,0,type);27    const antdFormItemMount = getAntdFormItemMount(wrapper,type);28    expect(wrapper.props()).toEqual({ });29    expect(antdInputMount.props().name).toEqual(undefined);30    //无label时,className="ant-form-item-control-wrapper"31    expect(antdFormItemMount.childAt(0).props().className).toEqual("ant-form-item-control-wrapper");32    expect(antdInputMount.props().required).toEqual(undefined);33  })34  it("props.name should work",function(){35    const wrapper = mount(36      <Component 37        name="test"38      />39    );40    const antdInputMount = getAntdFormComponentMount(wrapper,0,type);41    const antdFormItemMount = getAntdFormItemMount(wrapper,type);42    expect(wrapper.props()).toEqual({ name: "test" });43    if(type !== "timepicker"){44      expect(antdInputMount.props().name).toEqual("test");45    }else {46      expect(antdInputMount.props().name).toEqual(undefined);47    }48  })49  it("props.label should work",function(){50    const wrapper = mount(51      <Component 52        name="test"53        label="label"54      />55    );56    const antdInputMount = getAntdFormComponentMount(wrapper,1,type);57    const antdFormItemMount = getAntdFormItemMount(wrapper,type);58    expect(wrapper.props()).toEqual(59      { 60        name: "test", 61        label: "label", 62      }63    );64    //有label时,className="ant-form-item-label"65    expect(antdFormItemMount.childAt(0).props().className).toEqual("ant-form-item-label");66  })67  it("props.required should work",function(){68    const wrapper = mount(69      <Component 70        required71        name="test"72        label="label"73      />74    );75    const antdInputMount = getAntdFormComponentMount(wrapper,1,type);76    const antdFormItemMount = getAntdFormItemMount(wrapper,type);77    expect(wrapper.props()).toEqual(78      { 79        name: "test", 80        label: "label", 81        required: true,82      }83    );84    //有label时,className="ant-form-item-label"85    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-required");86  })87  it("props.rules should work",function(){88    const wrapper = mount(89      <Component 90        rules={91          [92            { required: true, message:"input is required" }93          ]94        }95        name="test"96        label="label"97      />98    );99    const antdInputMount = getAntdFormComponentMount(wrapper,1,type);100    const antdFormItemMount = getAntdFormItemMount(wrapper,type);101    if(type !== "password"){102      expect(wrapper.props()).toEqual(103        { 104          name: "test", 105          label: "label", 106          rules: [107            { required: true,message:"input is required" }108          ]109        }110      );111    }else {112      expect(wrapper.props().rules[0]).toEqual(113        { required: true,message:"input is required" }114      );115    }116    //有label时,className="ant-form-item-label"117    expect(antdFormItemMount.childAt(0).childAt(0).props().className).toEqual("ant-form-item-required");118  })119  it("props.className should work",function(){120    const wrapper = mount(121      <Component 122        required123        name="test"124        label="label"125        className="test"126      />127    );128    const antdInputMount = getAntdFormComponentMount(wrapper,1,type);129    const antdFormItemMount = getAntdFormItemMount(wrapper,type);130    expect(wrapper.props()).toEqual(131      { 132        name: "test", 133        label: "label", 134        required: true,...

Full Screen

Full Screen

util.js

Source:util.js Github

copy

Full Screen

1const widgetResolveFns = {};2const widgetPromises = {};3function provideWidget(mountId, widgetView) {4    if (widgetResolveFns[mountId]) {5        widgetResolveFns[mountId](widgetView);6    } else {7        widgetPromises[mountId] = Promise.resolve(widgetView);8    }9}10function requestWidget(mountId) {11    if (!widgetPromises[mountId]) {12        widgetPromises[mountId] = new Promise(resolve => widgetResolveFns[mountId] = resolve);13    }14    return widgetPromises[mountId];15}16window.init = async (voila) => {17    const kernel = await voila.connectKernel();18    window.addEventListener('beforeunload', () => kernel.shutdown());19    const widgetManager = new voila.WidgetManager(kernel);20    await widgetManager.build_widgets();21    // Create views for widgets that needs to be mount on the page22    Object.values(widgetManager._models)23        .forEach(async (modelPromise) => {24            const model = await modelPromise;25            const mountId = model.get('mount_id');26            if (mountId && model.get('_view_name')) {27                const view = await widgetManager.create_view(model);28                provideWidget(mountId, view);29            }30        });31    // Then mount them on the page32    const containers = document.querySelectorAll('[data-mount-id]');33    containers.forEach((container) => {34        requestWidget(container.getAttribute('data-mount-id')).then((view) => {35            container.appendChild(view.el);36        });37    });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2  it('Visits the Kitchen Sink', function() {3    cy.contains('type').click()4    cy.url().should('include', '/commands/actions')5    cy.get('.action-email')6      .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2  it('Does not do much!', function() {3    cy.contains('type').click()4    cy.url().should('include', '/commands/actions')5    cy.get('.action-email')6      .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2  it('Does not do much!', function() {3    cy.get('input:first').type('Hello World!')4    cy.get('input:last').type('Hello World!')5    cy.get('button').click()6    cy.contains('Hello World!')7    cy.contains('Hello World!')8  })9})

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2  it('Visits the Kitchen Sink', function() {3    cy.contains('h1', 'Hello World')4  })5})6describe('My First Test', function() {7  it('Visits the Kitchen Sink', function() {8    cy.mount(<App />, {9    })10    cy.contains('h1', 'Hello World')11  })12})13describe('My First Test', function() {14  it('Visits the Kitchen Sink', function() {15    cy.contains('h1', 'Hello World')16  })17})18describe('My First Test', function() {19  it('Visits the Kitchen Sink', function() {20    cy.mount(<App />, {21    })22    cy.contains('h1', 'Hello World')23  })24})25describe('My First Test', function() {26  it('Visits the Kitchen Sink', function() {27    cy.mount(<App />, {28    })29    cy.contains('h1', 'Hello World')30  })31})32describe('My First Test', function() {33  it('Visits the Kitchen Sink', function() {34    cy.mount(<App />, {35    })36    cy.contains('h1', 'Hello World')37  })38})39describe('My First Test', function() {40  it('Visits the Kitchen Sink', function() {41    cy.mount(<App />, {42    })43    cy.contains('h1', 'Hello World')44  })45})46describe('My First Test', function() {47  it('Visits the Kitchen

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { mount } from 'cypress-react-unit-test';3import { MyComponent } from './my-component';4it('renders', () => {5  mount(<MyComponent />);6  cy.contains('Hello World').should('be.visible');7});8export const MyComponent = () => {9  return <div>Hello World</div>;10};

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.mount(<MyComponent/>);2import { mount } from 'cypress-react-unit-test';3Cypress.Commands.overwrite('mount', mount);4const webpackPreprocessor = require('@cypress/webpack-preprocessor');5const webpackOptions = {6  module: {7      {8        use: {9          options: {10          },11        },12      },13  },14  resolve: {15  },16};17module.exports = (on, config) => {18  on('file:preprocessor', webpackPreprocessor(options));19};20"devDependencies": {21  }22describe('MyComponent', () => {23  it('should render', () => {24    cy.mount(<MyComponent />);25    cy.contains('Hello World');26  });27});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { mount } from 'cypress-react-unit-test'2import React from 'react'3import { Button } from 'reactstrap'4describe('Button test', () => {5  it('Button test', () => {6    mount(<Button>Click Me</Button>)7    cy.get('button').click()8  })9})

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful