How to use Nb method in Protractor

Best JavaScript code snippet using protractor

codalia-dynamic-item.js

Source:codalia-dynamic-item.js Github

copy

Full Screen

1Codalia.DynamicItem = class {2 constructor(props) {3 // Sets the item properties.4 this.vendor = props.vendor;5 this.pluginName = props.plugin;6 this.itemType = props.item;7 this.itemTypeUpperCase = this.itemType.slice(0,1).toUpperCase() + this.itemType.slice(1);8 this.rowsCells = props.rowsCells;9 this.rootLocation = props.rootLocation;10 this.ordering = props.ordering;11 this.Select2 = props.Select2;12 // Pagination parameters.13 this.nbItemsPerPage = null;14 if(props.nbItemsPerPage !== undefined) {15 this.nbItemsPerPage = props.nbItemsPerPage;16 }17 this.totalPages = 1;18 this.currentPageNb = 1;19 this.toLastPage = false;20 // Initializes some utility variables21 this.idNbList = [];22 // Used to keep each id unique during the session (ie: not reuse the id of a deleted item).23 this.removedIdNbs = [];24 // Creates the item container as well as the add button container.25 let attribs = {'id':this.itemType+'-container', 'class':this.itemType+'-container'};26 this.container = this.createElement('div', attribs);27 attribs = {'id':this.itemType+'-add-button-container', 'class':'add-button-container'};28 this.addButtonContainer = this.createElement('div', attribs);29 // Adds both the div and add button containers to the DOM. 30 document.getElementById(this.itemType).appendChild(this.container); 31 document.getElementById(this.itemType+'-container').appendChild(this.addButtonContainer); 32 // Inserts the add button.33 let button = this.createButton('add');34 this.addButtonContainer.appendChild(button);35 // Builds the pagination area.36 if(this.nbItemsPerPage !== null) {37 attribs = {'id':this.itemType+'-pagination', 'class':this.itemType+'-pagination'};38 this.pagination = this.createElement('div', attribs);39 document.getElementById(this.itemType).appendChild(this.pagination); 40 attribs = {'id':this.itemType+'-pagination-browser', 'class':this.itemType+'-pagination-browser'};41 document.getElementById(this.itemType+'-pagination').appendChild(this.createElement('table', attribs)); 42 }43 return this;44 }45 /**46 * Creates a button then binds it to a function according to the action.47 *48 * @param string action The action that the button triggers.49 * @param integer idNb The item id number (for remove action).50 * @param string modal The url to the modal window (for select action).51 *52 * @return object The created button.53 */54 createButton(action, idNb, modal) {55 // Creates a basic button.56 let label = CodaliaLang.action[action];57 let attribs = {'class':'btn', 'title':label};58 let button = this.createElement('button', attribs);59 let classes = {'add':'btn-primary', 'remove':'btn-danger', 'clear':'btn'};60 let icons = {'add':'plus-circle', 'remove':'times-circle', 'clear':'remove'};61 if(action == 'add') {62 button.addEventListener('click', (e) => { e.preventDefault(); this.createItem(); } );63 }64 if(action == 'remove') {65 button.addEventListener('click', (e) => { e.preventDefault(); this.removeItem(idNb, true); } );66 }67 if(action == 'clear') {68 button.addEventListener('click', (e) => { e.preventDefault(); } );69 button.classList.add('clear-btn');70 // No label on the clear button.71 label = '';72 }73 button.classList.add(classes[action]);74 button.innerHTML = '<span class="icon-'+icons[action]+' icon-white"></span> '+label;75 return button;76 }77 /**78 * Creates a basic item of the given type. A callback function (named after the item type) is called afterward. 79 *80 * @param object data The data to set the item to.81 *82 * @return void83 */84 createItem(data) {85 // Sets the id number for the item.86 let idNb = null;87 if(data !== undefined && data.id_nb !== undefined) {88 // Uses the given id number.89 idNb = data.id_nb;90 }91 else {92 // Gets a brand new id number for the item.93 idNb = this.getNewIdNumber();94 }95 // Means that a new item has been created from the "Add" button.96 if(data === undefined) {97 // Displays the last page to show the newly created item. (used for pagination). 98 this.toLastPage = true;99 }100 // Creates the item div then its inner structure.101 let attribs = {'id':this.itemType+'-item-'+idNb, 'class':this.itemType+'-item'};102 let item = this.createElement('div', attribs);103 this.container.appendChild(item);104 this.createItemStructure(item, idNb);105 if(this.ordering) {106 // N.B: No need to add the new item id number to the list as it is updated 107 // in the itemReordering function. The item pagination is reset as well.108 this.setItemOrdering(idNb);109 }110 else {111 // Adds the new item id number to the list.112 this.idNbList.push(idNb);113 // Reset the item pagination if required.114 if(this.nbItemsPerPage !== null) {115 this.updatePagination(this.currentPageNb);116 }117 }118 this.setOddEven();119 // Concatenates the callback function name.120 let callback = 'populate'+this.itemTypeUpperCase+'Item';121 // Calls the callback function to add the specific elements to the item.122 window[callback](idNb, data);123 }124 /**125 * Creates the inner structure of the item (ie: a set of divs structured in rows and126 * cells). A Remove button is added in the last cell of the first row.127 *128 * @param object item The item.129 * @param integer idNb The item id number.130 *131 * @return void132 */133 createItemStructure(item, idNb) {134 // N.B: row number = the rowsCells array indexes. 135 // cell number = the rowsCells array values.136 for(let i = 0; i < this.rowsCells.length; i++) {137 let rowNb = i + 1;138 let cellNb = 0;139 for(let j = 0; j < this.rowsCells[i]; j++) {140 cellNb = j + 1;141 let attribs = {'id':this.itemType+'-row-'+rowNb+'-cell-'+cellNb+'-'+idNb, 'class':this.itemType+'-cells-row-'+rowNb+' '+this.itemType+'-cell-'+cellNb+'-row-'+rowNb};142 item.appendChild(this.createElement('div', attribs));143 }144 // Adds a button which removes the item.145 if(rowNb == 1) {146 // Creates first an empty label.147 let attribs = {'class':'item-space', 'id':this.itemType+'-delete-label-'+idNb};148 document.getElementById(this.itemType+'-row-'+rowNb+'-cell-'+cellNb+'-'+idNb).appendChild(this.createElement('span', attribs));149 document.getElementById(this.itemType+'-delete-label-'+idNb).innerHTML = '&nbsp;';150 // Then adds the button.151 document.getElementById(this.itemType+'-row-'+rowNb+'-cell-'+cellNb+'-'+idNb).appendChild(this.createButton('remove', idNb)); 152 }153 // Adds a separator for multiple row structures.154 if(rowNb < this.rowsCells.length) {155 item.appendChild(this.createElement('span', {'class':this.itemType+'-row-separator'}));156 }157 }158 }159 /**160 * Removes the item corresponding to the given id number.161 *162 * @param string idNb The id number of the item to remove.163 * @param string warning If true a confirmation window is shown before deletion.164 *165 * @return void166 */167 removeItem(idNb, warning) {168 if(warning) {169 // Asks the user to confirm deletion.170 if(confirm(CodaliaLang.message.warning_remove_dynamic_item) === false) {171 return;172 }173 }174 // Calls a callback function to execute possible tasks before the item deletion.175 window['beforeRemoveItem'](idNb, this.itemType);176 // Removes the item from its div id.177 this.container.removeChild(document.getElementById(this.itemType+'-item-'+idNb));178 // Stores the removed id number.179 this.removedIdNbs.push(idNb);180 if(this.ordering) {181 // N.B: No need to remove the item id number from the list as it is updated 182 // in the itemReordering function. The item pagination is reset as well.183 this.itemReordering();184 }185 else {186 // Removes the item id number from the list.187 for(let i = 0; i < this.idNbList.length; i++) { 188 if(this.idNbList[i] == idNb) {189 this.idNbList.splice(i, 1); 190 }191 }192 // Reset the item pagination if required.193 if(this.nbItemsPerPage !== null) {194 this.updatePagination(this.currentPageNb);195 }196 }197 this.setOddEven();198 // Calls a callback function to execute possible tasks after the item deletion.199 window['afterRemoveItem'](idNb, this.itemType);200 }201 /**202 * Creates an HTML element of the given type.203 *204 * @param string type The type of the element.205 * @param object attributes The element attributes.206 *207 * @return object The HTML element.208 */209 createElement(type, attributes) {210 let element = document.createElement(type);211 // Sets the element attributes (if any).212 if(attributes !== undefined) {213 for(let key in attributes) {214 // Ensures that key is not a method/function.215 if(typeof attributes[key] !== 'function') {216 element.setAttribute(key, attributes[key]);217 }218 }219 }220 return element;221 }222 /**223 * Removes all of the items from the container.224 *225 * @return void226 */227 removeItems() {228 let idNbList = this.idNbList.slice();229 for(let i = 0; i < idNbList.length; i++) {230 this.removeItem(idNbList[i]);231 }232 }233 /**234 * Computes a new item id number according to the item divs which are already in the235 * container as well as those recently removed.236 *237 * @return integer The new id number.238 */239 getNewIdNumber() {240 let newIdNb = 0;241 // Loops through the id number list.242 for(let i = 0; i < this.idNbList.length; i++) {243 // If the item id number is greater than the new one, we use it.244 if(this.idNbList[i] > newIdNb) {245 newIdNb = this.idNbList[i];246 }247 }248 // Checks against the recently removed items.249 for(let i = 0; i < this.removedIdNbs.length; i++) {250 if(this.removedIdNbs[i] > newIdNb) {251 newIdNb = this.removedIdNbs[i];252 }253 }254 // Returns a valid id number (ie: the highest id number in the container plus 1).255 return newIdNb + 1;256 }257 /**258 * Generic function called by a modal child window when an item is 259 * selected (clicked) into a modal list.260 *261 * @param integer id The id of the selected item.262 * @param string name The name of the selected item.263 * @param integer idNb The id number of the dynamic item.264 * @param string type The type of the selected item.265 * @param boolean close If true the child window is closed.266 *267 * @return void268 */269 selectItem(id, name, idNb, type, close) {270 let item = document.getElementById(this.itemType+'-'+type+'-id-'+idNb);271 if(item.value != id) {272 item.value = id;273 document.getElementById(this.itemType+'-'+type+'-name-'+idNb).value = name;274 }275 if(close) {276 // Specific to October CMS.277 $('.modal').trigger('close.oc.popup');278 }279 }280 /**281 * Updates the order value of the items according to their position into the item282 * container.283 *284 * @return void285 */286 itemReordering() {287 // Collects all the item divs (ie: divs with a itemtype-item class) in the container.288 let divs = this.container.querySelectorAll('div.'+this.itemType+'-item');289 // Empties the id number list.290 this.idNbList = [];291 // Loops through the item divs.292 for(let i = 0; i < divs.length; i++) {293 let ordering = i + 1; 294 // Extracts the id number of the item from the end of its id value and convert it into an integer.295 let idNb = parseInt(divs[i].id.replace(/.+-(\d+)$/, '$1'));296 // Updates the ordering of the id number. 297 this.idNbList.push(idNb);298 // Updates the item ordering.299 document.getElementById(this.itemType+'-ordering-'+idNb).value = ordering;300 document.getElementById(this.itemType+'-order-number-'+idNb).value = ordering;301 // Displays the up/down links of the item. 302 document.getElementById(this.itemType+'-up-ordering-'+idNb).style.display = 'inline';303 document.getElementById(this.itemType+'-down-ordering-'+idNb).style.display = 'inline';304 // Resets first and last item classes.305 document.getElementById(this.itemType+'-order-number-'+idNb).classList.remove('first-item', 'last-item');306 if(ordering == 1) {307 // The first item cannot go any higher.308 document.getElementById(this.itemType+'-up-ordering-'+idNb).style.display = 'none';309 document.getElementById(this.itemType+'-order-number-'+idNb).classList.add('first-item');310 }311 if(ordering == divs.length) {312 // The last item cannot go any lower.313 document.getElementById(this.itemType+'-down-ordering-'+idNb).style.display = 'none';314 document.getElementById(this.itemType+'-order-number-'+idNb).classList.add('last-item');315 }316 }317 // Reset the item pagination if required.318 if(this.nbItemsPerPage !== null) {319 this.updatePagination(this.currentPageNb);320 }321 }322 /**323 * Inserts an ordering functionality in the given item. This functionality allows the324 * item to go up or down into the item ordering.325 *326 * @param integer idNb The id number of the item.327 *328 * @return void329 */330 setItemOrdering(idNb) {331 // The ordering tags are always inserted in the penultimate cell of the first row.332 let row = 1;333 let cell = this.rowsCells[0] - 1; 334 // Creates first an empty label.335 let attribs = {'class':'item-space', 'id':this.itemType+'-ordering-label-'+idNb};336 document.getElementById(this.itemType+'-row-'+row+'-cell-'+cell+'-'+idNb).appendChild(this.createElement('span', attribs));337 document.getElementById(this.itemType+'-ordering-label-'+idNb).innerHTML = '&nbsp;';338 // Creates a ordering container.339 attribs = {'class':'ordering-div', 'id':this.itemType+'-ordering-div-'+idNb};340 document.getElementById(this.itemType+'-row-'+row+'-cell-'+cell+'-'+idNb).appendChild(this.createElement('div', attribs));341 // Creates the element in which the item ordering number is stored.342 attribs = {'type':'hidden', 'name':this.itemType+'_ordering_'+idNb, 'id':this.itemType+'-ordering-'+idNb};343 document.getElementById(this.itemType+'-ordering-div-'+idNb).appendChild(this.createElement('input', attribs));344 // Concatenates the function name allowing the item to go up or down in the item ordering. 345 let functionName = 'reverse'+this.itemTypeUpperCase+'Order';346 // Creates the link allowing the item to go down the item ordering.347 attribs = {'href':'javascript:void(0);', 'id':this.itemType+'-down-ordering-'+idNb, 'onclick':'reverseOrder(\'down\','+idNb+',\''+this.itemType+'\')', 'class':'down-ordering'};348 let link = this.createElement('a', attribs);349 attribs = {'src':this.rootLocation+'/plugins/'+this.vendor+'/'+this.pluginName+'/assets/images/arrow_down.png', 'title':'arrow down', 'height':16, 'width':16};350 link.appendChild(this.createElement('img', attribs));351 document.getElementById(this.itemType+'-ordering-div-'+idNb).appendChild(link);352 // Creates fake element to display the order number. 353 attribs = {'type':'text', 'disabled':'disabled', 'id':this.itemType+'-order-number-'+idNb, 'class':this.itemType+'-order-number'};354 document.getElementById(this.itemType+'-ordering-div-'+idNb).appendChild(this.createElement('input', attribs));355 356 // Creates the link allowing the item to go up the item ordering.357 attribs = {'href':'javascript:void(0);', 'id':this.itemType+'-up-ordering-'+idNb, 'onclick':'reverseOrder(\'up\','+idNb+',\''+this.itemType+'\')', 'class':'up-ordering'};358 link = this.createElement('a', attribs);359 attribs = {'src':this.rootLocation+'/plugins/'+this.vendor+'/'+this.pluginName+'/assets/images/arrow_up.png', 'title':'arrow up', 'height':16, 'width':16};360 link.appendChild(this.createElement('img', attribs));361 document.getElementById(this.itemType+'-ordering-div-'+idNb).appendChild(link);362 this.itemReordering();363 }364 /**365 * Switches the order of 2 items in the DOM. 366 *367 * @param string direction The direction to go when switching (up/down).368 * @param integer idNb The id number of the item to switch from.369 *370 * @return void371 */372 reverseOrder(direction, idNb) {373 // Loops through the item id number order.374 for(let i = 0; i < this.idNbList.length; i++) {375 // Checks for the item which order has to be reversed.376 if(this.idNbList[i] == idNb) {377 // Sets the item indexes according to the direction.378 let index1 = i;379 let index2 = i + 1;380 if(direction == 'up') {381 index1 = i - 1;382 index2 = i;383 }384 // Gets the reference item before which the other item will be inserted.385 let refItem = document.getElementById(this.itemType+'-item-'+this.idNbList[index1]);386 // Momentarily withdraws the other item from the DOM.387 let oldChild = this.container.removeChild(document.getElementById(this.itemType+'-item-'+this.idNbList[index2]));388 // Switches the 2 items.389 this.container.insertBefore(oldChild, refItem);390 break;391 }392 }393 this.itemReordering();394 // The "odd" and "even" classes need to be reset.395 this.setOddEven();396 }397 /**398 * Checks the item field values.399 *400 * @param object fields The name of the fields to check (ie: the mandatory fields). The field names are stored in the 401 * object keys (eg 'firstname':'', 'lastname':'', ...).402 * Optional: A value type to check can be set in the value (eg: 'age':'int')403 * @param object extraType A specific type to check. Object structure: {'type name':'regex to use'}404 *405 * @return boolean True if all fields are ok, else otherwise.406 */407 validateFields(fields, extraType) {408 // Loops through the item id numbers.409 for(let i = 0; i < this.idNbList.length; i++) {410 // Computes the current page.411 let pageNb = Math.ceil((i + 1) / this.nbItemsPerPage);412 // Checks the given fields for each item.413 for(let key in fields) {414 let field = document.getElementById(this.itemType+'-'+key+'-'+this.idNbList[i]);415 if(field.hasAttribute('disabled')) {416 // Skips the disabled fields as their values are not taken in account when417 // sending the form.418 continue;419 }420 // Checks the select tags when the Select2 plugin is used.421 let Select2 = null;422 if(this.Select2 && (field.type == 'select-one' || field.type == 'select-multiple')) {423 // Gets the Select2 span.424 Select2 = field.nextElementSibling;425 }426 // In case the field was previously not valid.427 field.classList.remove('mandatory');428 if(Select2 !== null) {429 Select2.classList.remove('mandatory');430 }431 // Removes possible whitespace from both sides of the string.432 let value = field.value.trim();433 // Checks for empty fields.434 if(field.value == '') {435 field.classList.add('mandatory');436 if(Select2 !== null) {437 Select2.classList.add('mandatory');438 }439 if(this.nbItemsPerPage !== null) {440 // Shows the corresponding page.441 this.updatePagination(pageNb);442 }443 alert(CodaliaLang.message.alert_mandatory_field);444 return false;445 }446 // Checks the value type.447 if(fields[key] !== '' && !this.checkValueType(field.value, fields[key], extraType)) {448 field.classList.add('mandatory');449 if(Select2 !== null) {450 Select2.classList.add('mandatory');451 }452 if(this.nbItemsPerPage !== null) {453 // Shows the corresponding page.454 this.updatePagination(pageNb);455 }456 alert(CodaliaLang.message.alert_value_type_not_valid);457 return false;458 }459 }460 }461 return true;462 }463 /**464 * Checks if the given value is present into the given array.465 *466 * @param string needle The value to search.467 * @param array haystack The array in which the given value is searched.468 *469 * @return boolean True if the value matches the type, false otherwise.470 */471 inArray(needle, haystack) {472 let length = haystack.length;473 for(let i = 0; i < length; i++) {474 if(haystack[i] == needle) {475 return true;476 }477 }478 return false;479 }480 /**481 * Checks the type of the given value.482 *483 * @param string value The value to check.484 * @param string valueType The type to check the value against.485 * @param object extraType A specific type to check. Object structure: {'type name':'regex to use'}486 *487 * @return boolean True if the value matches the type, false otherwise.488 */489 checkValueType(value, valueType, extraType) {490 let regex = '';491 // Checks first for extra type.492 if(extraType !== undefined && valueType == extraType.valueType) {493 regex = extraType.regex;494 return regex.test(value);495 }496 switch(valueType) {497 case 'string':498 regex = /^.+$/;499 break;500 case 'int':501 regex = /^-?[0-9]+$/;502 break;503 case 'unsigned_int':504 regex = /^[0-9]+$/;505 break;506 case 'float':507 regex = /^-?[0-9]+(\.[0-9]+)?$/;508 break;509 case 'unsigned_float':510 regex = /^[0-9]+(\.[0-9]+)?$/;511 break;512 case 'snake_case':513 regex = /^[a-z0-9\_]+$/;514 break;515 case 'slug':516 regex = /^[a-z0-9\-]+$/;517 break;518 default: // Unknown type.519 return false;520 }521 return regex.test(value);522 }523 /**524 * Defines the items to display according to the given page number and the pagination parameters.525 *526 * @param integer activePageNb The page to display in the item list.527 *528 * @return void529 */530 updatePagination(activePageNb) {531 // Updates the current page number.532 this.currentPageNb = activePageNb;533 // Computes the total number of pages from the id list.534 this.totalPages = Math.ceil(this.idNbList.length / this.nbItemsPerPage);535 this.pagination.style.display = 'block';536 // A new item has been added to the end of the list OR the only item of the current 537 // page has been deleted. In both cases the current last item page is displayed.538 if(this.toLastPage || activePageNb > this.totalPages) {539 this.currentPageNb = this.totalPages;540 // Reset the flag.541 this.toLastPage = false;542 }543 // Loops through the item id number ordering.544 for(let i = 0; i < this.idNbList.length; i++) {545 let pageNb = 1;546 // Computes the page number according to the number of items per page.547 if((i + 1) > this.nbItemsPerPage) {548 let result = (i + 1) / this.nbItemsPerPage;549 pageNb = Math.ceil(result);550 }551 // Gets the class names of the item.552 let item = document.getElementById(this.itemType+'-item-'+this.idNbList[i]);553 let classes = item.className.split(' ');554 // Loops through the class names.555 for(let j = 0; j < classes.length; j++) {556 // Checks and removes the possible pagination class.557 if(classes[j].substring(0, this.itemType.length + 20) === this.itemType+'-pagination-inactive') {558 item.classList.remove(classes[j]);559 }560 // Hides the items which are not part of the current page. 561 if(pageNb != this.currentPageNb) {562 item.classList.add(this.itemType+'-pagination-inactive');563 }564 }565 }566 // The only item of the current page has been deleted.567 if(this.totalPages < this.currentPageNb) {568 // Updates the current page number.569 this.currentPageNb = this.totalPages;570 }571 if(this.totalPages < 2) {572 // No pagination is needed if there's just one or no page.573 this.pagination.style.display = 'none';574 return;575 }576 this.updatePaginationBrowser();577 }578 /**579 * Builds the pagination browser according to the pagination parameters.580 *581 * @return void582 */583 updatePaginationBrowser() {584 let beginning = CodaliaLang.pagination.beginning;585 let previous = CodaliaLang.pagination.previous;586 // Sets the 'beginning' and 'previous' links 587 if(this.currentPageNb > 1) {588 beginning = '<a href="javascript:void(0);" onclick="browsingPages(1, \''+this.itemType+'\');">'+beginning+'</a>';589 let previousPage = this.currentPageNb - 1;590 previous = '<a href="javascript:void(0);" onclick="browsingPages('+previousPage+', \''+this.itemType+'\');">'+previous+'</a>';591 }592 let browser = '<td>'+beginning+'</td><td>'+previous+'</td>';593 let next = CodaliaLang.pagination.next;594 let end = CodaliaLang.pagination.end;595 // Sets the 'next' and 'end' links 596 if(this.currentPageNb < this.totalPages) {597 let nextPage = this.currentPageNb + 1;598 next = '<a href="javascript:void(0);" onclick="browsingPages('+nextPage+', \''+this.itemType+'\');">'+next+'</a>';599 end = '<a href="javascript:void(0);" onclick="browsingPages('+this.totalPages+', \''+this.itemType+'\');">'+end+'</a>';600 }601 // Sets the page links 602 for(let i = 0; i < this.totalPages; i++) {603 let pageNb = i + 1;604 if(pageNb == this.currentPageNb) {605 browser += '<td class="current-page-number">'+pageNb+'</td>';606 }607 else {608 browser += '<td class="page-number"><a href="javascript:void(0);" onclick="browsingPages('+pageNb+', \''+this.itemType+'\');">'+pageNb+'</a></td>';609 }610 }611 browser += '<td>'+next+'</td><td>'+end+'</td>';612 // Deletes the previous table row (if any).613 if(document.getElementById(this.itemType+'-pagination-browser').rows.length > 0) {614 document.getElementById(this.itemType+'-pagination-browser').deleteRow(0);615 }616 // Inserts the new browsing links.617 let row = document.getElementById(this.itemType+'-pagination-browser').insertRow(0)618 row.innerHTML = browser;619 }620 /**621 * Adds the odd or even class to the items according to their position into the list.622 *623 * @return void624 */625 setOddEven() {626 // Loops through the id number list.627 for(let i = 0; i < this.idNbList.length; i++) { 628 // Gets the div item.629 let item = document.getElementById(this.itemType+'-item-'+this.idNbList[i]);630 // First removes the current class.631 item.classList.remove(this.itemType+'-odd');632 item.classList.remove(this.itemType+'-even');633 // Uses the modulo operator to add the proper class.634 if((i + 1) % 2) {635 item.classList.add(this.itemType+'-odd');636 }637 else {638 item.classList.add(this.itemType+'-even');639 }640 }641 }642 /**643 * Creates a date and time fields into a given location.644 *645 * @param string name The name of the date time field.646 * @param integer idNb The item id number.647 * @param string rowCellId The location where the date time field is created.648 * @param string value The datetime value.649 * @param boolean time If true, displays the time field.650 *651 * @return void652 */653 createDateTimeFields(name, idNb, rowCellId, value, time) {654 let attribs = {'class':'field-datepicker row', 'data-control':'datepicker', 'data-mode':'datetime', 'id':'datepicker-'+name+'-'+idNb};655 document.getElementById(rowCellId).appendChild(this.createElement('div', attribs)); 656 attribs = {'class':'input-with-icon right-align datetime-field', 'id':'div-date-'+name+'-'+idNb};657 document.getElementById('datepicker-'+name+'-'+idNb).appendChild(this.createElement('div', attribs)); 658 attribs = {'class':'icon icon-calendar-o'};659 document.getElementById('div-date-'+name+'-'+idNb).appendChild(this.createElement('i', attribs)); 660 attribs = {'type':'text', 'id':this.itemType+'-date-'+name+'-'+idNb, 'class':'form-control', 'autocomplete':'off', 'data-datepicker':''};661 document.getElementById('div-date-'+name+'-'+idNb).appendChild(this.createElement('input', attribs)); 662 if(time) {663 attribs = {'class':'input-with-icon right-align datetime-field', 'id':'div-time-'+name+'-'+idNb};664 document.getElementById('datepicker-'+name+'-'+idNb).appendChild(this.createElement('div', attribs)); 665 attribs = {'class':'icon icon-clock-o'};666 document.getElementById('div-time-'+name+'-'+idNb).appendChild(this.createElement('i', attribs)); 667 attribs = {'type':'text', 'id':this.itemType+'-time-'+name+'-'+idNb, 'class':'form-control', 'autocomplete':'off', 'data-timepicker':''};668 document.getElementById('div-time-'+name+'-'+idNb).appendChild(this.createElement('input', attribs)); 669 }670 if(value == null) {671 value = '';672 }673 attribs = {'type':'hidden', 'name':this.itemType+'_'+name+'_'+idNb, 'id':'publication-'+name+'-'+idNb, 'value':value, 'data-datetime-value':''};674 document.getElementById('datepicker-'+name+'-'+idNb).appendChild(this.createElement('input', attribs)); 675 $('[data-control="datepicker"]').datePicker();676 }...

Full Screen

Full Screen

exprparser.js

Source:exprparser.js Github

copy

Full Screen

1function ParseExpArr(arr, globals, locals) {2 arr = arr.slice();3 let exp = [], op = [], dov;4 // parenthesis5 for (let i = 0; i < arr.length; i++) {6 if (Object.prototype.toString.call(arr[i]) == '[object Array]') arr[i] = ParseExpArr(arr[i], globals, locals)[0][0];7 }8 // variable, property access, function call9 for (let i = 0; i < arr.length; i++) {10 if (arr[i].type == 'variable' && VARRESCLS(arr, i)) {11 if (arr[i].val in locals.val) arr[i] = locals.val[arr[i].val];12 else if (arr[i].val in globals.val) arr[i] = globals.val[arr[i].val];13 else throw new Error('variable ' + arr[i].val + ' nonexistent');14 } else if (arr[i].type == 'tarray') {15 for (let j in arr[i].val) arr[i].val[j] = ParseExpArr(arr[i].val[j], globals, locals)[0][0];16 arr[i] = new ExpArray(arr[i].val);17 } else if (arr[i].type == 'tobject') {18 for (let j in arr[i].val) arr[i].val[j] = ParseExpArr(arr[i].val[j], globals, locals)[0][0];19 arr[i] = new ExpObject(arr[i].val);20 }21 let clss = true;22 while (clss) {23 clss = false;24 while (PROPACCCLS(arr, i)) {25 arr.splice(i, 3, ExpPropAcc(arr[i], arr[i + 2]));26 clss = true;27 }28 if (arr[i + 1] && arr[i + 1].type == 'funccall') {29 let ar = arr[i + 1].val.slice();30 for (let j in ar) ar[j] = ParseExpArr(ar[j], globals, locals)[0][0];31 let fcres = FuncCallProp(arr[i], ar, globals, locals);32 if (fcres === undefined) throw new Error('function returned undefined');33 arr.splice(i, 2, fcres);34 clss = true;35 }36 }37 }38 // logical not, bitwise not, unary plus, unary minus, typeof, void, delete : right > left39 dov = true;40 while (dov) {41 let nb = false;42 for (let i = arr.length - 1; i >= 0; i--) {43 if (arr[i].type == 'op') {44 if (arr[i].val == '!') {45 arr.splice(i, 2, ExpLogicalNot(arr[i + 1]));46 nb = true;47 break;48 } else if (arr[i].val == '~') {49 arr.splice(i, 2, ExpBitwiseNot(arr[i + 1]));50 nb = true;51 break;52 } else if (arr[i].val == '+') {53 if (arr[i - 1] && arr[i - 1].type != 'op') continue;54 arr.splice(i, 2, ExpUnaryPlus(arr[i + 1]));55 nb = true;56 break;57 } else if (arr[i].val == '-') {58 if (arr[i - 1] && arr[i - 1].type != 'op') continue;59 arr.splice(i, 2, ExpUnaryMinus(arr[i + 1]));60 nb = true;61 break;62 } else if (arr[i].val == 'typeof') {63 arr.splice(i, 2, ExpTypeof(arr[i + 1]));64 } else if (arr[i].val == 'void') {65 arr.splice(i, 2, GetUndefined());66 } else if (arr[i].val == 'del' || arr[i].val == 'delete') {67 if (arr[i + 2] && arr[i + 2].type == 'op' && arr[i + 2].val == '.') {68 let nam = arr[i + 3].val;69 delete arr[i + 1].val[nam];70 arr.splice(i, 4, GetBool(true));71 } else {72 let varn = arr[i + 1];73 if (varn.type != 'variable') throw new Error('delete: unexpected token');74 varn = varn.val;75 if (varn in locals.val) {76 arr.splice(i, 2, GetBool(true));77 delete locals.val[varn];78 } else {79 arr.splice(i, 2, GetBool(false));80 }81 }82 }83 }84 }85 dov = nb;86 }87 // split up into exp and op88 for (let i = 0; i < arr.length; i++) {89 if (i % 2 == 0) exp.push(arr[i]);90 else op.push(arr[i].val);91 }92 // exponents : right > left93 dov = true;94 while (dov) {95 let nb = false;96 for (let i = op.length - 1; i >= 0; i--) {97 if (op[i] == '**' || op[i] == '^') {98 exp.splice(parseInt(i), 2, ExpExponentiate(exp[i], exp[parseInt(i) + 1]));99 op.splice(parseInt(i), 1);100 nb = true;101 break;102 }103 }104 dov = nb;105 }106 // multiply, divide, remainder : left > right107 dov = true;108 while (dov) {109 let nb = false;110 for (let i = 0; i < op.length; i++) {111 if (op[i] == '*') {112 exp.splice(parseInt(i), 2, ExpMultiply(exp[i], exp[parseInt(i) + 1]));113 op.splice(parseInt(i), 1);114 nb = true;115 break;116 } else if (op[i] == '/') {117 exp.splice(parseInt(i), 2, ExpDivide(exp[i], exp[parseInt(i) + 1]));118 op.splice(parseInt(i), 1);119 nb = true;120 break;121 } else if (op[i] == '%') {122 exp.splice(parseInt(i), 2, ExpRemainder(exp[i], exp[parseInt(i) + 1]));123 op.splice(parseInt(i), 1);124 nb = true;125 break;126 }127 }128 dov = nb;129 }130 // addition, subtraction : left > right131 dov = true;132 while (dov) {133 let nb = false;134 for (let i = 0; i < op.length; i++) {135 if (op[i] == '+') {136 exp.splice(parseInt(i), 2, ExpAdd(exp[i], exp[parseInt(i) + 1]));137 op.splice(parseInt(i), 1);138 nb = true;139 break;140 } else if (op[i] == '-') {141 exp.splice(parseInt(i), 2, ExpSubtract(exp[i], exp[parseInt(i) + 1]));142 op.splice(parseInt(i), 1);143 nb = true;144 break;145 }146 }147 dov = nb;148 }149 // bitwise left shift, bitwise right shift : left > right150 dov = true;151 while (dov) {152 let nb = false;153 for (let i = 0; i < op.length; i++) {154 if (op[i] == '<<') {155 exp.splice(parseInt(i), 2, ExpBitwiseLeftShift(exp[i], exp[parseInt(i) + 1]));156 op.splice(parseInt(i), 1);157 nb = true;158 break;159 } else if (op[i] == '>>') {160 exp.splice(parseInt(i), 2, ExpBitwiseRightShift(exp[i], exp[parseInt(i) + 1]));161 op.splice(parseInt(i), 1);162 nb = true;163 break;164 }165 }166 dov = nb;167 }168 // greater than, less than, greater than or equal, less than or equal : left > right169 dov = true;170 while (dov) {171 let nb = false;172 for (let i = 0; i < op.length; i++) {173 if (op[i] == '>') {174 exp.splice(i, 2, ExpGreaterThan(exp[i], exp[i + 1]));175 op.splice(i, 1);176 nb = true;177 break;178 } else if (op[i] == '<') {179 exp.splice(i, 2, ExpLessThan(exp[i], exp[i + 1]));180 op.splice(i, 1);181 nb = true;182 break;183 } else if (op[i] == '>=') {184 exp.splice(i, 2, ExpGreaterThanEqual(exp[i], exp[i + 1]));185 op.splice(i, 1);186 nb = true;187 break;188 } else if (op[i] == '<=') {189 exp.splice(i, 2, ExpLessThanEqual(exp[i], exp[i + 1]));190 op.splice(i, 1);191 nb = true;192 break;193 }194 }195 dov = nb;196 }197 // equality, inequality, true equality : left > right198 dov = true;199 while (dov) {200 let nb = false;201 for (let i = 0; i < op.length; i++) {202 if (op[i] == '==') {203 exp.splice(i, 2, ExpEqual(exp[i], exp[i + 1]));204 op.splice(i, 1);205 nb = true;206 break;207 } else if (op[i] == '!=') {208 exp.splice(i, 2, ExpNotEqual(exp[i], exp[i + 1]));209 op.splice(i, 1);210 nb = true;211 break;212 } else if (op[i] == 'is') {213 exp.splice(i, 2, ExpIs(exp[i], exp[i + 1]));214 op.splice(i, 1);215 nb = true;216 break;217 }218 }219 dov = nb;220 }221 // bitwise and : left > right222 dov = true;223 while (dov) {224 let nb = false;225 for (let i = 0; i < op.length; i++) {226 if (op[i] == '&') {227 exp.splice(i, 2, ExpBitwiseAnd(exp[i], exp[i + 1]));228 op.splice(i, 1);229 nb = true;230 break;231 }232 }233 dov = nb;234 }235 // bitwise xor : left > right236 dov = true;237 while (dov) {238 let nb = false;239 for (let i = 0; i < op.length; i++) {240 if (op[i] == '#') {241 exp.splice(i, 2, ExpBitwiseXor(exp[i], exp[i + 1]));242 op.splice(i, 1);243 nb = true;244 break;245 }246 }247 dov = nb;248 }249 // bitwise or : left > right250 dov = true;251 while (dov) {252 let nb = false;253 for (let i = 0; i < op.length; i++) {254 if (op[i] == '|') {255 exp.splice(i, 2, ExpBitwiseOr(exp[i], exp[parseInt(i) + 1]));256 op.splice(i, 1);257 nb = true;258 break;259 }260 }261 dov = nb;262 }263 // logical and : left > right264 dov = true;265 while (dov) {266 let nb = false;267 for (let i = 0; i < op.length; i++) {268 if (op[i] == '&&') {269 exp.splice(i, 2, ExpLogicalAnd(exp[i], exp[i + 1]));270 op.splice(i, 1);271 nb = true;272 break;273 }274 }275 dov = nb;276 }277 // logical or : left > right278 dov = true;279 while (dov) {280 let nb = false;281 for (let i = 0; i < op.length; i++) {282 if (op[i] == '||') {283 exp.splice(i, 2, ExpLogicalOr(exp[i], exp[i + 1]));284 op.splice(i, 1);285 nb = true;286 break;287 }288 }289 dov = nb;290 }291 // assignment : right > left292 dov = true;293 while (dov) {294 let nb = false;295 for (let i = op.length - 1; i >= 0; i--) {296 if (op[i] == '=') {297 if (op[i - 1] && op[i - 1] == '.') {298 let nam = exp[i].val, val = exp[i + 1];299 exp[i - 1].val[nam] = val;300 exp.splice(i - 1, 3, val);301 op.splice(i - 1, 2);302 nb = true;303 break;304 } else {305 if (exp[i].type != 'variable') throw new Error('invalid left-hand side in assignment');306 let nam = exp[i].val, val = exp[i + 1];307 locals.val[nam] = val;308 exp.splice(i, 2, val);309 op.splice(i, 1);310 nb = true;311 break;312 }313 }314 }315 dov = nb;316 }317 if (exp.length == 0) exp.push(GetUndefined());318 return [exp, op];...

Full Screen

Full Screen

browser_rules_pseudo-element_01.js

Source:browser_rules_pseudo-element_01.js Github

copy

Full Screen

1/* vim: set ft=javascript ts=2 et sw=2 tw=80: */2/* Any copyright is dedicated to the Public Domain.3 http://creativecommons.org/publicdomain/zero/1.0/ */4"use strict";5// Test that pseudoelements are displayed correctly in the rule view6const TEST_URI = URL_ROOT + "doc_pseudoelement.html";7const PSEUDO_PREF = "devtools.inspector.show_pseudo_elements";8add_task(function* () {9 yield pushPref(PSEUDO_PREF, true);10 yield addTab(TEST_URI);11 let {inspector, view} = yield openRuleView();12 yield testTopLeft(inspector, view);13 yield testTopRight(inspector, view);14 yield testBottomRight(inspector, view);15 yield testBottomLeft(inspector, view);16 yield testParagraph(inspector, view);17 yield testBody(inspector, view);18});19function* testTopLeft(inspector, view) {20 let id = "#topleft";21 let rules = yield assertPseudoElementRulesNumbers(id,22 inspector, view, {23 elementRulesNb: 4,24 firstLineRulesNb: 2,25 firstLetterRulesNb: 1,26 selectionRulesNb: 0,27 afterRulesNb: 1,28 beforeRulesNb: 229 }30 );31 let gutters = assertGutters(view);32 info("Make sure that clicking on the twisty hides pseudo elements");33 let expander = gutters[0].querySelector(".ruleview-expander");34 ok(!view.element.children[1].hidden, "Pseudo Elements are expanded");35 expander.click();36 ok(view.element.children[1].hidden,37 "Pseudo Elements are collapsed by twisty");38 expander.click();39 ok(!view.element.children[1].hidden, "Pseudo Elements are expanded again");40 info("Make sure that dblclicking on the header container also toggles " +41 "the pseudo elements");42 EventUtils.synthesizeMouseAtCenter(gutters[0], {clickCount: 2},43 view.styleWindow);44 ok(view.element.children[1].hidden,45 "Pseudo Elements are collapsed by dblclicking");46 let elementRuleView = getRuleViewRuleEditor(view, 3);47 let elementFirstLineRule = rules.firstLineRules[0];48 let elementFirstLineRuleView =49 [...view.element.children[1].children].filter(e => {50 return e._ruleEditor && e._ruleEditor.rule === elementFirstLineRule;51 })[0]._ruleEditor;52 is(convertTextPropsToString(elementFirstLineRule.textProps),53 "color: orange",54 "TopLeft firstLine properties are correct");55 let onAdded = view.once("ruleview-changed");56 let firstProp = elementFirstLineRuleView.addProperty("background-color",57 "rgb(0, 255, 0)", "", true);58 yield onAdded;59 onAdded = view.once("ruleview-changed");60 let secondProp = elementFirstLineRuleView.addProperty("font-style",61 "italic", "", true);62 yield onAdded;63 is(firstProp,64 elementFirstLineRule.textProps[elementFirstLineRule.textProps.length - 2],65 "First added property is on back of array");66 is(secondProp,67 elementFirstLineRule.textProps[elementFirstLineRule.textProps.length - 1],68 "Second added property is on back of array");69 is((yield getComputedStyleProperty(id, ":first-line", "background-color")),70 "rgb(0, 255, 0)", "Added property should have been used.");71 is((yield getComputedStyleProperty(id, ":first-line", "font-style")),72 "italic", "Added property should have been used.");73 is((yield getComputedStyleProperty(id, null, "text-decoration")),74 "none", "Added property should not apply to element");75 yield togglePropStatus(view, firstProp);76 is((yield getComputedStyleProperty(id, ":first-line", "background-color")),77 "rgb(255, 0, 0)", "Disabled property should now have been used.");78 is((yield getComputedStyleProperty(id, null, "background-color")),79 "rgb(221, 221, 221)", "Added property should not apply to element");80 yield togglePropStatus(view, firstProp);81 is((yield getComputedStyleProperty(id, ":first-line", "background-color")),82 "rgb(0, 255, 0)", "Added property should have been used.");83 is((yield getComputedStyleProperty(id, null, "text-decoration")),84 "none", "Added property should not apply to element");85 onAdded = view.once("ruleview-changed");86 firstProp = elementRuleView.addProperty("background-color",87 "rgb(0, 0, 255)", "", true);88 yield onAdded;89 is((yield getComputedStyleProperty(id, null, "background-color")),90 "rgb(0, 0, 255)", "Added property should have been used.");91 is((yield getComputedStyleProperty(id, ":first-line", "background-color")),92 "rgb(0, 255, 0)", "Added prop does not apply to pseudo");93}94function* testTopRight(inspector, view) {95 yield assertPseudoElementRulesNumbers("#topright", inspector, view, {96 elementRulesNb: 4,97 firstLineRulesNb: 1,98 firstLetterRulesNb: 1,99 selectionRulesNb: 0,100 beforeRulesNb: 2,101 afterRulesNb: 1102 });103 let gutters = assertGutters(view);104 let expander = gutters[0].querySelector(".ruleview-expander");105 ok(!view.element.firstChild.classList.contains("show-expandable-container"),106 "Pseudo Elements remain collapsed after switching element");107 expander.scrollIntoView();108 expander.click();109 ok(!view.element.children[1].hidden,110 "Pseudo Elements are shown again after clicking twisty");111}112function* testBottomRight(inspector, view) {113 yield assertPseudoElementRulesNumbers("#bottomright", inspector, view, {114 elementRulesNb: 4,115 firstLineRulesNb: 1,116 firstLetterRulesNb: 1,117 selectionRulesNb: 0,118 beforeRulesNb: 3,119 afterRulesNb: 1120 });121}122function* testBottomLeft(inspector, view) {123 yield assertPseudoElementRulesNumbers("#bottomleft", inspector, view, {124 elementRulesNb: 4,125 firstLineRulesNb: 1,126 firstLetterRulesNb: 1,127 selectionRulesNb: 0,128 beforeRulesNb: 2,129 afterRulesNb: 1130 });131}132function* testParagraph(inspector, view) {133 let rules =134 yield assertPseudoElementRulesNumbers("#bottomleft p", inspector, view, {135 elementRulesNb: 3,136 firstLineRulesNb: 1,137 firstLetterRulesNb: 1,138 selectionRulesNb: 1,139 beforeRulesNb: 0,140 afterRulesNb: 0141 });142 assertGutters(view);143 let elementFirstLineRule = rules.firstLineRules[0];144 is(convertTextPropsToString(elementFirstLineRule.textProps),145 "background: blue",146 "Paragraph first-line properties are correct");147 let elementFirstLetterRule = rules.firstLetterRules[0];148 is(convertTextPropsToString(elementFirstLetterRule.textProps),149 "color: red; font-size: 130%",150 "Paragraph first-letter properties are correct");151 let elementSelectionRule = rules.selectionRules[0];152 is(convertTextPropsToString(elementSelectionRule.textProps),153 "color: white; background: black",154 "Paragraph first-letter properties are correct");155}156function* testBody(inspector, view) {157 yield testNode("body", inspector, view);158 let gutters = getGutters(view);159 is(gutters.length, 0, "There are no gutter headings");160}161function convertTextPropsToString(textProps) {162 return textProps.map(t => t.name + ": " + t.value).join("; ");163}164function* testNode(selector, inspector, view) {165 yield selectNode(selector, inspector);166 let elementStyle = view._elementStyle;167 return elementStyle;168}169function* assertPseudoElementRulesNumbers(selector, inspector, view, ruleNbs) {170 let elementStyle = yield testNode(selector, inspector, view);171 let rules = {172 elementRules: elementStyle.rules.filter(rule => !rule.pseudoElement),173 firstLineRules: elementStyle.rules.filter(rule =>174 rule.pseudoElement === ":first-line"),175 firstLetterRules: elementStyle.rules.filter(rule =>176 rule.pseudoElement === ":first-letter"),177 selectionRules: elementStyle.rules.filter(rule =>178 rule.pseudoElement === ":-moz-selection"),179 beforeRules: elementStyle.rules.filter(rule =>180 rule.pseudoElement === ":before"),181 afterRules: elementStyle.rules.filter(rule =>182 rule.pseudoElement === ":after"),183 };184 is(rules.elementRules.length, ruleNbs.elementRulesNb,185 selector + " has the correct number of non pseudo element rules");186 is(rules.firstLineRules.length, ruleNbs.firstLineRulesNb,187 selector + " has the correct number of :first-line rules");188 is(rules.firstLetterRules.length, ruleNbs.firstLetterRulesNb,189 selector + " has the correct number of :first-letter rules");190 is(rules.selectionRules.length, ruleNbs.selectionRulesNb,191 selector + " has the correct number of :selection rules");192 is(rules.beforeRules.length, ruleNbs.beforeRulesNb,193 selector + " has the correct number of :before rules");194 is(rules.afterRules.length, ruleNbs.afterRulesNb,195 selector + " has the correct number of :after rules");196 return rules;197}198function getGutters(view) {199 return view.element.querySelectorAll(".theme-gutter");200}201function assertGutters(view) {202 let gutters = getGutters(view);203 is(gutters.length, 3,204 "There are 3 gutter headings");205 is(gutters[0].textContent, "Pseudo-elements",206 "Gutter heading is correct");207 is(gutters[1].textContent, "This Element",208 "Gutter heading is correct");209 is(gutters[2].textContent, "Inherited from body",210 "Gutter heading is correct");211 return gutters;...

Full Screen

Full Screen

quote.js

Source:quote.js Github

copy

Full Screen

1/** QUOTE FORM2*************************************************** **/3function mySelection() { 4 5 var buildingType = document.getElementById("building_type").value6 function AddElementResidQ() {7 document.getElementById("residentialQ").style.display = "block";}8 function AddElementCommQ() {9 document.getElementById("commercialQ").style.display = "block";}10 function AddElementCorpQ() {11 document.getElementById("corporateQ").style.display = "block";}12 function AddElementHybridQ() {13 document.getElementById("hybridQ").style.display = "block";}14 15 function RemoveElementResidQ() {16 document.getElementById("residentialQ").style.display = "none";} 17 function RemoveElementCommQ() {18 document.getElementById("commercialQ").style.display = "none";} 19 function RemoveElementCorpQ() {20 document.getElementById("corporateQ").style.display = "none";} 21 function RemoveElementHybridQ() {22 document.getElementById("hybridQ").style.display = "none";} 23 24 if (buildingType === "residential") { //RESIDENTIAL SELECTED BLOCK25 console.log("selected")26 AddElementResidQ();27 RemoveElementCommQ();28 RemoveElementCorpQ();29 RemoveElementHybridQ();30 } else if (buildingType === "commercial") { //COMMERCIAL SELECTED BLOCK31 console.log("selected")32 RemoveElementResidQ();33 AddElementCommQ();34 RemoveElementCorpQ();35 RemoveElementHybridQ();36 } else if (buildingType === "corporate") { //CORPORATE SELECTED BLOCK37 console.log("selected")38 RemoveElementResidQ();39 RemoveElementCommQ();40 AddElementCorpQ();41 RemoveElementHybridQ();42 } else if (buildingType === "hybrid") { //HYBRID SELECTED BLOCK43 console.log("selected")44 RemoveElementResidQ();45 RemoveElementCommQ();46 RemoveElementCorpQ();47 AddElementHybridQ();48 } else { //DEFAULT SELECTED NONE49 console.log("selected")50 RemoveElementResidQ();51 RemoveElementCommQ();52 RemoveElementCorpQ();53 RemoveElementHybridQ();54 }55 56}57 function Quantity_residential() {58 //Number of appart59 var nbAppart = document.getElementById("residA").value || 0 ;60 //Number of level61 var nbLevel = document.getElementById("residB").value || 0 ;62 //Number of Basement 63 var nbBasement = document.getElementById("residC").value || 0;64 65//RESIDENTIAL CALCUL 66 67 //Occurence of 6 Appart by Level 68 var OccurAppartLevel = Math.ceil(residA /(residB * 6) );69 70 var columns = Math.ceil($residB / 20);71 72 var elevatorsEstimate = (OccurAppartLevel) * (columns);73 74 if(elevatorsEstimate > 0){75 document.getElementById("elevatorsNb").value= elevatorsEstimate;76 }else {77 document.getElementById("elevatorsNb").value = 0;78 }79 return elevatorsEstimate;80}81function Quantity_commercial() {82 //Number of level83 var nbLevel = document.getElementById("commA").value || 0 ;84 //Number of Basement 85 var nbBasement = document.getElementById("commB").value || 0;86 //Number of Business 87 var nbBusiness = document.getElementById("commC").value || 0;88 //Number of Parking 89 var nbParking = document.getElementById("commD").value || 0;90 //Number of elevator cage 91 var nbElevatorCage = document.getElementById("commeE").value || 0;92 93//COMMERCIAL CALCUL 94 95 //Compute and return qty of elevators needed96 var elevatorsEstimate = nbElevatorCage;97 //MINIMU VALUE BY INPUT98 if (nbLevel != "" && nbBasement != "" && nbBusiness != "" && nbParking !="" && nbElevatorCage !=0 ){99 //Value selector for elevators qty 100 document.getElementById("elevatorsNb").value = elevatorsEstimate;101 }else {102 document.getElementById("elevatorsNb").value = 0;103 }104 return elevatorsEstimate;105} 106function Resultqty_Elevators_quote() {107 buildingType = mySelection();108 //var Hy = document.getElementById("qty_Level").value || 0 ;109 var nbLevel = Number(document.getElementById("corporateA").value || 0 );110 //var Hz = document.getElementById("qty_Base").value;111 var nbBasement = Number(document.getElementById("corporateB").value || 0 );112 var nbParking = document.getElementById("corporateC").value || 0 ;113 var nbBusiness = document.getElementById("corporateD").value || 0 ;114 var nbOccupants = document.getElementById("corporateE").value || 0 ;115 var nbHours = document.getElementById("hybridE").value || 0 ;116 var Min = nbLevel + nbBasement; 117 118 var totalNbOccupants = Math.ceil(corporateE*(nbLevel + nbBasement)); 119 var elevatorsEstimate = Math.ceil(totalNbOccupants/1000 ); 120 121 var columns = Math.ceil((nbLevel + nbBasement)/20);122 123 var qty_Eleva = (elevatorsEstimate / columns);124 125 var elevatorsEstimate = (qty_Eleva * columns); 126 //console.log(service); 127 if (nbLevel != "" && nbBasement != "" && nbParking !="" && nbBusiness !="" && nbOccupants != "" && Min != 0 ) {128 //Value selector for elevators qty 129 130 document.getElementById("elevatorsNb").value = elevatorsEstimate;131 } else {132 document.getElementById("elevatorsNb").value = 0;133 }134 return elevatorsEstimate;135 } 136 137function Price() {138 var buildingType = mySelection(); 139 140 if (buildingType === "residential") {141 var elevatorQuote = returnQuantity_residential();142 }143 if (buildingType === "commercial") {144 var elevatorQuote = returnQuantity_commercial();145 } 146 if (buildingType === "corporate" || buildingType === "hybrid") {147 var elevatorQuote = Resultqty_Elevators_quote();148 }149 var install_Rate; 150 var Total;151 152 if (document.getElementById("standard").checked) { 153 document.getElementById("elevatorCost").value="7565.00";154 install_Rate = (7565.00 * (10/100) * elevatorQuote).toFixed(2);155 Total = (7565.00 * 1.10 * elevatorQuote).toFixed(2);//ok156 document.getElementById("installationCost").value = install_Rate ;157 document.getElementById("totalCost").value = Total;158 } 159 if (document.getElementById("premium").checked) { 160 document.getElementById("elevatorCost").value="12345.00";161 install_Rate = (12345.00 * (13/100) * elevatorQuote).toFixed(2); 162 Total = (12345.00 * 1.13 * elevatorQuote).toFixed(2);//ok163 document.getElementById("installationCost").value = install_Rate ;164 document.getElementById("totalCost").value = Total;165 } 166 if (document.getElementById("excelium").checked) { 167 document.getElementById("elevatorCost").value="15400.00";168 install_Rate = (15400.00 * (16/100) * elevatorQuote).toFixed(2);169 Total = (15400.00 * 1.16 * elevatorQuote).toFixed(2);//ok170 document.getElementById("installationCost").value = install_Rate ;171 document.getElementById("totalCost").value = Total;172 } 173 } 174 175 176 177 ...

Full Screen

Full Screen

postReactionProvider.jsx

Source:postReactionProvider.jsx Github

copy

Full Screen

1 import React, {useReducer, createContext, useContext} from 'react';2 const react_action = {3 'ADD_LIKE': 1,4 'ADD_LOVE': 2,5 'ADD_CARE': 3,6 'ADD_HAHA': 4,7 'ADD_WOW': 5,8 'ADD_SAD': 6,9 'ADD_ANGRY': 7,10 'REMOVE_LIKE': 8,11 'REMOVE_LOVE': 9,12 'REMOVE_CARE': 10,13 'REMOVE_HAHA': 11,14 'REMOVE_WOW': 12,15 'REMOVE_SAD': 13,16 'REMOVE_ANGRY': 14,17 'ADD_COMMENT': 15,18 'REMOVE_SIBLING_REACT': 1619 }20 const react_reducer = (state, action) => {21 switch (action.type) {22 case react_action.ADD_LIKE: // LIKE REACTION23 return {24 ...state,25 react_nb: {...state.react_nb, like_nb : state.react_nb.like_nb + 1},26 reacted: true,27 current_react: 'like',28 } 29 case react_action.REMOVE_LIKE:30 return {31 ...state,32 react_nb: {...state.react_nb, like_nb : state.react_nb.like_nb - 1},33 reacted: false,34 current_react: ''35 }36 case react_action.ADD_LOVE: // LOVE REACTION37 return {38 ...state,39 react_nb: {...state.react_nb, love_nb: state.react_nb.love_nb + 1},40 reacted: true,41 current_react: 'love'42 }43 case react_action.REMOVE_LOVE:44 return {45 ...state,46 react_nb: {...state.react_nb, love_nb: state.react_nb.love_nb - 1},47 reacted: false,48 current_react: ''49 }50 51 case react_action.ADD_CARE: // CARE REACT52 return {53 ...state,54 react_nb: {...state.react_nb, care_nb: state.react_nb.care_nb + 1},55 reacted: true,56 current_react: 'care'57 }58 case react_action.REMOVE_CARE:59 return {60 ...state,61 react_nb: {...state.react_nb, care_nb: state.react_nb.care_nb - 1},62 reacted: false,63 current_react: ''64 }65 case react_action.ADD_HAHA: // HAHA REACT66 return {67 ...state,68 react_nb: {...state.react_nb, haha_nb: state.react_nb.haha_nb + 1},69 reacted: true,70 current_react: 'haha'71 }72 case react_action.REMOVE_HAHA:73 return {74 ...state,75 react_nb: {...state.react_nb, haha_nb: state.react_nb.haha_nb - 1},76 reacted: false,77 current_react: ''78 }79 // SAD REACT80 case react_action.ADD_SAD: // SAD REACT81 return {82 ...state,83 react_nb: {...state.react_nb, sad_nb: state.react_nb.sad_nb + 1},84 reacted: true,85 current_react: 'sad'86 }87 case react_action.REMOVE_SAD:88 return {89 ...state,90 react_nb: {...state.react_nb, sad_nb: state.react_nb.sad_nb - 1},91 reacted: false,92 current_react: ''93 }94 case react_action.ADD_WOW: // WOW REACT95 return {96 ...state,97 react_nb: {...state.react_nb, wow_nb: state.react_nb.wow_nb + 1},98 reacted: true,99 current_react: 'wow'100 }101 case react_action.REMOVE_WOW:102 return {103 ...state,104 react_nb: {...state.react_nb, wow_nb: state.react_nb.wow_nb - 1},105 reacted: false,106 current_react: ''107 }108 case react_action.ADD_ANGRY: // ANGRY REACT109 return {110 ...state,111 react_nb: {112 ...state.react_nb,113 angry_nb: state.react_nb.angry_nb + 1114 },115 reacted: true,116 current_react: 'angry'117 }118 case react_action.REMOVE_ANGRY:119 return {120 ...state,121 react_nb: {122 ...state.react_nb,123 angry_nb: state.react_nb.angry_nb - 1,124 },125 reacted: false,126 current_react: ''127 }128 case react_action.REMOVE_SIBLING_REACT: // REMOVE SIBLING REACT WHICH ALREADY ACTIVATED (CLICKED BEFORE THE CURRENT ONE)129 return {130 ...state,131 react_nb: {132 ...state.react_nb,133 [`${state.current_react}_nb`]: eval(`state.react_nb.${state.current_react}_nb`) - 1 134 }135 }136 default:137 return state;138 }139 }140 141 const Context = createContext(null); // THE CONTEXT142 const initalvalue = { // INITIAL VALUES143 react_nb : { // REACT NUMBER144 like_nb: 4, 145 love_nb: 4,146 care_nb: 5,147 haha_nb: 1,148 sad_nb: 3,149 wow_nb: 1,150 angry_nb: 0151 },152 reacted: false, // react status153 current_react: '', // like | love | care | haha | sad | wow | angry154 155 commenting: { // COMMENT SECTION156 comment_nb: 0,157 },158 sharing: { // SHARE SECTION159 share_nb: 0, 160 }161 }162 function PostReactionProvider({children}) {163 return (164 <Context.Provider value={useReducer(react_reducer, initalvalue)}>165 {children}166 </Context.Provider>167 );168 }169 170 const PostReactContext = () => useContext(Context)171 export {react_action, PostReactContext};...

Full Screen

Full Screen

script.js

Source:script.js Github

copy

Full Screen

1// VARIABLES GLOBALES2let nb;3let guessNB;4let nbToGuess;5let cpt=0;6let minRange=0;7let maxRange="infini";8// CONVERSION EN ENTIER9function myNumber(givenNumber){10 let intNumber=parseInt(givenNumber);11 return intNumber;12}13// VERSION ETAPE 6 : VERSION AVEC MINRANGE ET MAXRANGE AU CHOIX DE JOUEUR 1 ALLANT DE 1 A INFINI !!!14function nbInRange (n) {15 if (n<minRange || n>maxRange) { // CAS EN DEHORS DU RANGE16 console.log("nbInRange retourne False : " + n);17 return false;18 }19 else { // SINON RETOURNE TRUE IL EST DANS LE RANGE20 console.log("nbInRange retourne True : " + n); 21 return true;22 };23}24// VERSION ETAPE 6 : compteur itération25function compteur () {26 cpt++; // ON INCREMENTE LE COMPTEUR27 return cpt;28}29// VERSION ETAPE 6 : entre un chiffre quelque soit le joueur 1 ou 2 en paramètre30function askANumber5(idJoueur) {31 var nbJX = document.getElementById(idJoueur).value;32 guessNB=myNumber(nbJX);33 console.log("Vous avez tapé : " + guessNB);34 return guessNB;35}36// VERSION ETAPE 6 : lance le jeu pour le joueur 1 d'abord, pas de range fixé, allant de 1 à infini !!!37function gamePlay3() {38 nbToGuess= askANumber5("joueur1");39 console.log("NB TO GUESS : " + nbToGuess);40 document.getElementById("joueur1").value=""; // efface son formulaire à joueur 141 document.getElementById("message").innerHTML="PLACE AU JOUEUR 2!"; // demande au joueur 2 d'entrer un chiffre42}43/* // VERSION ETAPE 6 : POUR LE JOUEUR 2 */44function didIWin(idJoueur) {45 var nbJX = document.getElementById(idJoueur).value;46 nb=myNumber(nbJX);47 48 // CAS IL A GAGNE :49 if (nb==nbToGuess) { 50 alert("YOU DID IT !!!","");51 document.getElementById("score").innerHTML = "<br><br>Nombre de tentative(s) : " + compteur ();52 document.getElementById("message").innerHTML="BRAVO JOUEUR 2! Tu as droit à un bonus !"53 document.getElementById("bonus").innerHTML="Click 'GO' to play: <button id='ok' onclick='myName()'>GO!</button>" ; // 1ere solution : mettre du html dans JS; 2e sol: separer html du JS mais appelle le DOM ci-dessous :54 // document.getElementById("ok").setAttribute("style", "visibility:visible;"); // 2e solution : Pour rendre visible le bouton OK55 display_image('img/rat.jfif', 56 276, 57 250, 58 'JavaScriptImage');59 60 return true;61 }62 // SINON ON VERIFIE S'IL EST DANS LE RANGE63 else { 64 if (!nbInRange(nb)) {65 console.log("Pas dans range : " + nb);66 document.getElementById("score").innerHTML = "<br><br>Nombre de tentative(s) : " + compteur ();67 } 68 else {69 if (nb<nbToGuess) { 70 //myNumber(alert(`TROP PETIT ! Play again! Entre un chiffre entre ${minRange}<?<${maxRange} `,""));71 // SI 72 minRange=nb; // ON CHANGE LE RANGE MINIMUM PAR LE NOMBRE NB DU JOUEUR 273 myNumber(document.getElementById("message").innerHTML=`TROP PETIT ! Play again! Entre un chiffre entre ${minRange} ET ${maxRange}.`);74 console.log(`minRange = ${minRange}`);75 document.getElementById("score").innerHTML = "<br><br>Nombre de tentative(s) : " + compteur ();76 return false77 }78 else if (nb>nbToGuess) { 79 //myNumber(alert(`TROP GRAND ! Play again! Entre un chiffre entre ${minRange}<?<${maxRange} `,""));80 maxRange=nb; // ON CHANGE LE RANGE MMAXIMUM PAR LE NOMBRE NB DU JOUEUR 281 myNumber(document.getElementById("message").innerHTML=`TROP GRAND ! Play again! Entre un chiffre entre ${minRange} ET ${maxRange}.`);82 console.log(`maxRange = ${maxRange}`);83 document.getElementById("score").innerHTML = "<br><br>Nombre de tentative(s) : " + compteur ();84 return false85 }86 }87 return false88 }89 ...

Full Screen

Full Screen

calculator.js

Source:calculator.js Github

copy

Full Screen

1import mexp from 'math-expression-evaluator'2const POPULATION_TOTALE = 700000003const DUREE_MALADIE = 10 // en jours4const TAUX_MORTALITE = 0.035const NB_INITIAL_MALADES = 20006const NB_INITIAL_REMIS = 2007const NB_INITIAL_MORTS = 508const NB_JOURS_SIMULATION = 1809const calcul = (nbContactsQuotidien, probaTransmission) => calculComplet(NB_INITIAL_MALADES, NB_INITIAL_REMIS, NB_INITIAL_MORTS, NB_JOURS_SIMULATION, POPULATION_TOTALE, DUREE_MALADIE, TAUX_MORTALITE, nbContactsQuotidien, probaTransmission)10const calculComplet = (nbInitialMalades, nbInitialMorts, nbInitialRemis, nbJours, populationTotale, dureeMaladie, tauxMortalite, nbContactsQuotidien, probaTransmission) => {11 const donneesMalades = []12 const donneesMorts = []13 const donneesRemis = []14 const donneesSains = []15 const summary = {}16 let nbMalades = nbInitialMalades17 let nbMorts = nbInitialMorts18 let nbRemis = nbInitialRemis19 let nbSains = populationTotale - (nbMalades + nbMorts + nbRemis)20 for (let jour = 0; jour <= nbJours; jour++) {21 donneesMalades.push(Math.round(nbMalades))22 donneesMorts.push(Math.round(nbMorts))23 donneesRemis.push(Math.round(nbRemis))24 donneesSains.push(Math.round(nbSains))25 summary[jour] = toLocaleString({26 sains: Math.round(nbSains),27 malades: Math.round(nbMalades),28 remis: Math.round(nbRemis),29 morts: Math.round(nbMorts),30 })31 nbMorts = mexp.eval(`${nbMorts} + (${tauxMortalite}/${dureeMaladie}) * ${nbMalades}`)32 nbRemis = mexp.eval(`${nbRemis} + (1/${dureeMaladie}) * ${nbMalades}`)33 nbMalades = mexp.eval(`${nbMalades} + (${nbMalades} * ${nbContactsQuotidien} * ${probaTransmission} * (${nbSains}/${populationTotale})) - ((1/${dureeMaladie}) * ${nbMalades}) - ((${tauxMortalite}/${dureeMaladie}) * ${nbMalades})`)34 nbSains = mexp.eval(`${populationTotale} - (${nbMalades} + ${nbMorts} + ${nbRemis}`)35 }36 console.table(summary)37 const R0 = (nbContactsQuotidien * probaTransmission * dureeMaladie).toLocaleString()38 const nbMortsTotal = (donneesMorts[donneesMorts.length - 1]).toLocaleString()39 console.table(toLocaleString({ populationTotale, nbContactsQuotidien, probaTransmission, dureeMaladie, tauxMortalite, R0, nbMortsTotal }))40 return {41 R0,42 nbMortsTotal,43 donneesMalades,44 donneesMorts,45 donneesRemis,46 donneesSains,47 }48}49const toLocaleString = (object) => {50 const result = {}51 for (let key in object) {52 result[key] = object[key].toLocaleString()53 }54 return result55}...

Full Screen

Full Screen

convert.js

Source:convert.js Github

copy

Full Screen

1let nb = 102console.log(`${nb} est égal à ${nb.toString(2)} en binaire`)3console.log(`${nb} est égal à ${nb.toString(8)} en octal`)4console.log(`${nb} est égal à ${nb.toString(16)} en hexadecimal`)5console.log('\n')6nb = 157console.log(`${nb} est égal à ${nb.toString(2)} en binaire`)8console.log(`${nb} est égal à ${nb.toString(8)} en octal`)9console.log(`${nb} est égal à ${nb.toString(16)} en hexadecimal`)10console.log('\n')11nb = 1612console.log(`${nb} est égal à ${nb.toString(2)} en binaire`)13console.log(`${nb} est égal à ${nb.toString(8)} en octal`)14console.log(`${nb} est égal à ${nb.toString(16)} en hexadecimal`)15console.log('\n')16nb = 500517console.log(`${nb} est égal à ${nb.toString(2)} en binaire`)18console.log(`${nb} est égal à ${nb.toString(8)} en octal`)19console.log(`${nb} est égal à ${nb.toString(16)} en hexadecimal`)20console.log('\n')21nb = 5239090322console.log(`${nb} est égal à ${nb.toString(2)} en binaire`)23console.log(`${nb} est égal à ${nb.toString(8)} en octal`)24console.log(`${nb} est égal à ${nb.toString(16)} en hexadecimal`)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Protractor Demo App', function() {2 it('should add one and two', function() {3 element(by.model('first')).sendKeys(1);4 element(by.model('second')).sendKeys(2);5 element(by.id('gobutton')).click();6 });7});8describe('Protractor Demo App', function() {9 it('should add one and two', function() {10 element(by.model('first')).sendKeys(1);11 element(by.model('second')).sendKeys(2);12 element(by.id('gobutton')).click();13 });14});15describe('Protractor Demo App', function() {16 it('should add one and two', function() {17 element(by.model('first')).sendKeys(1);18 element(by.model('second')).sendKeys(2);19 element(by.id('gobutton')).click();20 });21});22describe('Protractor Demo App', function() {23 it('should add one and two', function() {24 element(by.model('first')).sendKeys(1);25 element(by.model('second')).sendKeys(2);26 element(by.id('gobutton')).click();27 });28});29describe('Protractor Demo App', function() {30 it('should add one and two', function() {31 element(by.model('first')).sendKeys(1);

Full Screen

Using AI Code Generation

copy

Full Screen

1var nb = require('protractor-nodebird');2describe('Protractor Demo App', function() {3 it('should have a title', function() {4 expect(browser.getTitle()).toEqual('Super Calculator');5 });6});7 browser.getTitle().then(function(title) {8 console.log(title);9 });10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var nb = require('protractor-nodebird');2describe('Protractor Demo App', function() {3 it('should add one and two', function() {4 nb.enterText('id','greetings','Hello');5 nb.click('id','greet');6 nb.verifyText('id','greet','Hello');7 });8});9### openBrowser(url)10### enterText(locatorType, locatorValue, text)11### click(locatorType, locatorValue)12### verifyText(locatorType, locatorValue, expectedText)13[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1var nb = require('protractor-nb').nb;2nb.findElement(by.name('q')).sendKeys('Protractor');3nb.findElement(by.name('btnG')).click();4nb.wait(function() {5 return nb.getTitle().then(function(title) {6 return title === 'Protractor - Google Search';7 });8});9nb.quit();10{11 "dependencies": {12 }13}14exports.config = {15}16var nb = require('protractor-nb').nb;17nb.findElement(by.name('q')).sendKeys('Protractor');18nb.findElement(by.name('btnG')).click();19nb.wait(function() {20 return nb.getTitle().then(function(title) {21 return title === 'Protractor - Google Search';22 });23});24nb.quit();25{26 "dependencies": {27 }28}29exports.config = {30}31var nb = require('protractor-nb').nb;32nb.findElement(by.name('q')).sendKeys('Protractor');33nb.findElement(by.name('btnG')).click();34nb.wait(function() {35 return nb.getTitle().then(function(title) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var ptor = protractor.getInstance();2var nb = ptor.nb;3nb.waitForAngular();4nb.element(by.model('q')).sendKeys('protractor');5nb.element(by.id('gbqfbb')).click();6nb.waitForAngular();7var ptor = protractor.getInstance();8var nb = ptor.nb;9nb.waitForAngular();10nb.element(by.model('q')).sendKeys('protractor');11nb.element(by.id('gbqfbb')).click();12nb.waitForAngular();13var ptor = protractor.getInstance();14var nb = ptor.nb;15nb.waitForAngular();16nb.element(by.model('q')).sendKeys('protractor');17nb.element(by.id('gbqfbb')).click();18nb.waitForAngular();19var ptor = protractor.getInstance();20var nb = ptor.nb;

Full Screen

Using AI Code Generation

copy

Full Screen

1var nb = require('protractor-nodebird');2var ptor = nb.init(protractor, browser);3describe('test', function() {4 it('should add 1 + 2', function() {5 ptor.findElement(ptor.By.model('todoList.todoText')).sendKeys('write first protractor test');6 ptor.findElement(ptor.By.css('[value="add"]')).click();7 var todoList = ptor.findElement(ptor.By.repeater('todo in todoList.todos'));8 expect(todoList.getText()).toEqual('write first protractor test');9 });10});11#### Nb.init(protractor, browser)12#### Nb.findElement(locator)13#### Nb.findElements(locator)14#### Nb.findElementFromElement(element, locator)15#### Nb.findElementsFromElement(element, locator)16#### Nb.wait(condition, timeout, message)17#### Nb.sleep(ms)18#### Nb.waitForAngular()19#### Nb.getCurrentUrl()20#### Nb.getTitle()21#### Nb.takeScreenshot()22#### Nb.refresh()23#### Nb.back()24#### Nb.forward()25#### Nb.executeScript(script, ...var_args)26#### Nb.executeAsyncScript(script, ...var_args)27#### Nb.switchTo().alert()28#### Nb.switchTo().activeElement()29#### Nb.switchTo().window(nameOrHandle)30#### Nb.switchTo().frame(indexOrName)31#### Nb.switchTo().defaultContent()32#### Nb.switchTo().parentFrame()33#### Nb.getProcessedConfig()34#### Nb.actions()35#### Nb.touchActions()36#### Nb.call(callback, opt_description)

Full Screen

Using AI Code Generation

copy

Full Screen

1var nb = require('protractor-nodebird');2var pageObject = require('./pageObject.js');3var page = new pageObject();4var pageObject1 = require('./pageObject1.js');5var page1 = new pageObject1();6var pageObject2 = require('./pageObject2.js');7var page2 = new pageObject2();8var pageObject3 = require('./pageObject3.js');9var page3 = new pageObject3();10var pageObject4 = require('./pageObject4.js');11var page4 = new pageObject4();12var pageObject5 = require('./pageObject5.js');13var page5 = new pageObject5();14var pageObject6 = require('./pageObject6.js');15var page6 = new pageObject6();16var pageObject7 = require('./pageObject7.js');17var page7 = new pageObject7();18var pageObject8 = require('./pageObject8.js');19var page8 = new pageObject8();20var pageObject9 = require('./pageObject9.js');21var page9 = new pageObject9();22var pageObject10 = require('./pageObject10.js');23var page10 = new pageObject10();24var pageObject11 = require('./pageObject11.js');25var page11 = new pageObject11();26var pageObject12 = require('./pageObject12.js');27var page12 = new pageObject12();28var pageObject13 = require('./pageObject13.js');29var page13 = new pageObject13();30var pageObject14 = require('./pageObject14.js');31var page14 = new pageObject14();32var pageObject15 = require('./pageObject15.js');33var page15 = new pageObject15();34var pageObject16 = require('./pageObject16.js');35var page16 = new pageObject16();36var pageObject17 = require('./pageObject17

Full Screen

Using AI Code Generation

copy

Full Screen

1var nb = require('protractor-node-bdd');2nb.init();3Given('I am on the home page', function() {4});5When('I search for {string}', function(searchTerm) {6 element(by.model('q')).sendKeys(searchTerm);7});8Then('I should see {string} in the results', function(searchTerm) {9 expect(element(by.css('h3.r')).getText()).toEqual(searchTerm);10});11nb.run();

Full Screen

Selenium Protractor Tutorial

Protractor is developed by Google Developers to test Angular and AngularJS code. Today, it is used to test non-Angular applications as well. It performs a real-world user-like test against your application in a real browser. It comes under an end-to-end testing framework. As of now, Selenium Protractor has proved to be a popular framework for end-to-end automation for AngularJS.

Let’s talk about what it does:

  • Protractor, built on WebDriver JS (Selenium), offers Angular-specific locator strategies.
  • It helps to construct automated tests for applications other than Angular JS and is not just intended to test AngularJS applications.
  • Page object design pattern is supported by Protractor Selenium, which improves in producing clear and legible code. Automation testers need to write clean code.
  • Frameworks like Jasmine, Cucumber, and others are fully integrated with Protractor.

Chapters:

Protractor is a JavaScript framework, end-to-end test automation framework for Angular and AngularJS applications.

Protractor Selenium provides new locator methods that actually make it easier to find elements in the DOM.

Two files are required to execute Protractor Selenium tests for end-to-end automation: Specs & Config. Go through the link above to understand in a better way.

To carry out extensive, automated cross browser testing, you can't imagine installing thousands of the available browsers on your own workstation. The only way to increase browser usage is through remote execution on the cloud. To execute your automation test scripts across a variety of platforms and browser versions, LambdaTest offers more than 3000 browsers.

We recommend Selenium for end-to-end automation for AngularJS because both are maintained and owned by Google, and they build JavaScript test automation framework to handle AngularJS components in a way that better matches how developers use it.

For scripting, selenium locators are essential since if they're off, your automation scripts won't run. Therefore, in any testing framework, these Selenium locators are the foundation of your Selenium test automation efforts.

To make sure that your Selenium automation tests function as intended, debugging can be an effective option. Check the blog to know more.

Get familiar with global variables that are majorly used in locating the DOM elements with examples for better understanding of these Selenium locators in protractor.

If you are not familiar with writing Selenium test automation on Protractor, here is a blog for you to get you understand in depth.

Selenium tests are asynchronous and there are various reasons for a timeout to occur in a Protractor test. Find out how to handle timeouts in this Protractor tutorial.

In this Protractor tutorial, learn how to handle frames or iframes in Selenium with Protractor for automated browser testing.

Handle alerts and popups in Protractor more efficiently. It can be confusing. Here's a simple guide to understand how to handle alerts and popups in Selenium.

Run Protractor 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