How to use jQuery.map method in Cypress

Best JavaScript code snippet using cypress

aige.member.js

Source:aige.member.js Github

copy

Full Screen

1/*2 * aige.member.js3 * Controller  for browser feature module member4 *5 * db.member.update({'username': 'Ecki'}, {$set: {'isAdmin':'true'} });6 */7/*jslint         browser : true, continue : true,8 devel  : true, indent  : 2,    maxerr   : 50,9 newcap : true, nomen   : true, plusplus : true,10 regexp : true, sloppy  : true, vars     : false,11 white  : true12 */13/*global $, aige */14aige.member = (function () {15//---------------- BEGIN MODULE SCOPE VARIABLES --------------16    var configMap = {17      18        member_list_html: String()19                + '<div id= "memberList" class="aige-admin-member-list" style="height:40em;  overflow:auto;">'20                + '<div id="btnCreateMember" class="buttonCreate"> Neu anlegen</div>'21                + '<table id="tblMemberList" class="tblList">'22                + '<thead><tr><th></th><th></th>'23                + '<th>Vorname</th><th>Nachname</th><th>Benutzername</th>'24                + '<th>Email</th><th>PLZ</th><th>Wohnort</th><th>Addresse</th>'25                + '<th>Tel</th><th>Mobil</th><th>Mitglied seit</th></th><th>aktiv</th>'26                + '</tr></thead><tbody></tbody>'27                + '</table>'28                + '</div>',29        member_form_html: String()30                + '<div id="memberAddEdit" class="aige-admin-member-add-edit">'31                + '<h2 id="headerMemberFormPopup" style="text-align:center;"></h2>'32                + '<form id = "memberForm">'33                + '<ul>'34                + '<input type = "hidden" id = "txtID"/>'35                + '<input type = "hidden" id = "txtIsAdmin"/>'36                + '<li>'37                + '<label for = "txtVorname"> Vorname: </label>'38                + '<input type = "text" id = "txtVorname" name="firstname"/>'39                + '</li>'40                + '<li>'41                + '<label for = "txtNachname"> Nachname: </label>'42                + '<input type = "text" id = "txtNachname" name="lastname" />'43                + '</li>'44                + '<li>'45                + '<label for = "txtUsername"> Benutzername: </label>'46                + '<input type = "text" id = "txtUsername" name ="username"/>'47                + '</li>'48                + '<li>'49                + '<label for = "txtEmail"> Email: </label>'50                + '<input type = "text" id = "txtEmail" name="email"/>'51                + '</li>'52                + '<li>'53                + '<label for = "txtZip"> PLZ: </label>'54                + '<input type = "text" id = "txtZip" name="zip" />'55                + '</li>'56                + '<li>'57                + '<label for = "txtCity"> Ort: </label>'58                + '<input type = "text" id = "txtCity"name="city" />'59                + '</li>'60                + '<li>'61                + '<label for = "txtAddress"> Addresse: </label>'62                + '<input type = "text" id = "txtAddress" name="address" />'63                + '</li>'64                + '<li>'65                + '<label for = "txtPhone"> Tel (Fest): </label>'66                + '<input type = "text" id = "txtPhone" name="phone"/>'67                + '</li>' + '<li>'68                + '<label for = "txtMobil"> Tel (Mobil): </label>'69                + '<input type = "text" id = "txtMobil"name="mobil" />'70                + '</li> <li>'71                + '<label for = "txtAdmissionDate"> Mitglied seit: </label>'72                + '<input type = "text" id = "txtAdmissionDate" name="admissionDate"/>'73                + '</li> <li>'74                + '<label for = "txtIsActive"> Aktiv: </label>'75                + '<input type = "checkbox" id = "txtIsActive"/>'76                + '</li></ul>'77                + '<div>'78                + '<input type = "submit" value = "Speichern" id = "addEditMemberSave">'79                + '<input id="btnCloseMember" class="buttonClose" type="button" value="Close Popup" />'80                + '</div>'81                + '</form>'82                + '</div>',83        imageActive: "<img src='../css/images/boxSelected.gif' alt='Aktiv'/>",84        imageInactive: "<img src='../css/images/boxUnselected.gif' alt='Aktiv'/>",85        settable_map: {86            general_model: true,87            member_model: true,88            actionTypes: true89        },90        general_model: null,91        member_model: null,92        object_type: "member",93        actionTypes: null94    },95    stateMap = {96        $shellcontainer: null,97        selectedMemberId: -1,98        currentMember: null,99        memberList: [],100        saveIsEdit: true,101        currentAction: ""102    },103    jqueryMap = {}, listMembers, onMenuMember, onEditMember, onDeleteMember, onCreateMember, onSaveMember, onLoginSuccess,104            memberCallback,105            setJqueryMap, configModule, initModule;106    //----------------- END MODULE SCOPE VARIABLES ---------------107    //------------------- BEGIN UTILITY METHODS ------------------108    function closePopup() {109        jqueryMap.$memberFormValidator.resetForm();110        jqueryMap.$memberFormPopup.fadeOut();111        jqueryMap.$overlay.fadeOut();112    }113    function validateMemberForm() {114        var validator = $("#memberForm").validate({115            focusCleanup: true,116            rules: {117                firstname: {118                    required: true,119                    minlength: 2120                },121                lastname: {122                    required: true,123                    minlength: 2124                },125                username: {126                    required: true,127                    minlength: 2128                },129                email: {130                    email: true131                },132                zip: {133                    number: true,134                    required: true,135                    minlength: 5136                },137                city: {138                    required: true139                },140                address: {141                    required: true142                }143            },144            errorClass: "errormessage",145            errorElement: "b",146            errorPlacement: function (error, element) {147                console.log("errorPlacement=" + element);148                error.insertAfter(element);149            }150        });151        return validator;152    }153//-------------------- END UTILITY METHODS -------------------154    //--------------------- BEGIN DOM METHODS --------------------155    // Begin DOM method /setJqueryMap/156    setJqueryMap = function () {157        var $container = stateMap.$shellcontainer,158                $menu = $container.find('#cssmenu'),159                $content = $container.find('.aige-shell-main-content'),160                $contentWrapper = $container.find("#contentWrapper");161      162        $contentWrapper.append($(configMap.member_list_html));163        $contentWrapper.append($(configMap.member_form_html));164        var $adminMemberList = $contentWrapper.find('#memberList');165     166     167       168        jqueryMap = {169            $contentWrapper: $contentWrapper,170            $memberMenu: $menu.find('#admin_member'),171            $overlay: $content.find("#overlay-bg"),172            $adminMemberList: $adminMemberList,173         174            $adminMemberListTableList: $adminMemberList.find('#tblMemberList tbody'),175            $memberFormPopup: $contentWrapper.find('#memberAddEdit'),176            $memberForm: $contentWrapper.find('#memberForm'),177            $memberFormValidator: validateMemberForm()};178    };179    // End DOM method /setJqueryMap/180    listMembers = function () {181        var memberlistLength, myMember;182        jqueryMap.$adminMemberListTableList.html("");183        stateMap.memberList = configMap.general_model.getItems(configMap.object_type);184        memberlistLength = stateMap.memberList.length;185        console.log("is admin=" + stateMap.currentMember.isAdmin);186        if (stateMap.currentMember.isAdmin) {187            jqueryMap.$adminMemberList.find('#btnCreateMember').fadeIn();188        } else {189            jqueryMap.$adminMemberList.find('#btnCreateMember').hide();190        }191        for (var i = 0; i < memberlistLength; i++) {192            myMember = stateMap.memberList[i];193            jqueryMap.$adminMemberListTableList.append("<tr>" + "<td><img src='../css/images/edit.png' alt='Edit" + myMember._id194                    + "' id='btnEditMember' class='btnEdit'/></td><td><img src='../css/images/dustbin.png' alt='Delete" + myMember._id195                    + "' id='btnDeleteMember'  class='btnDelete'/></td>" + "<td>" + myMember.firstname + "</td>"196                    + "<td>" + myMember.lastname + "</td>" + "<td><span class='username'>" + myMember.username + "</span></td>" + "<td>"197                    + myMember.email + "</td>" + "<td>" + myMember.zip + "</td>"198                    + "<td>" + myMember.city + "</td>" + "<td>" + myMember.address + "</td>"199                    + "<td>" + myMember.phone + "</td>" + "<td>" + myMember.mobil + "</td>"200                    + "<td>" + myMember.admissionDate + "</td>"201                    + "<td>"202                    + (myMember.isActive ? configMap.imageActive : configMap.imageInactive)203                    + "</td>"204                    + "</tr>");205        }206        if (!stateMap.currentMember.isAdmin) {207            console.log("User is not an admin");208            var rows = jqueryMap.$adminMemberListTableList.find("tr");209            rows.each(function (i, tr) {210                var username = $("span.username", tr).text();211                if (username === stateMap.currentMember.username) {212                    $(this).css({"backgroundColor": "#afc7e0", "color": "white"});213                }214            });215        }216     217      jqueryMap.$adminMemberList.fadeIn(1000, "swing");218    };219//---------------------- END DOM METHODS ---------------------220//------------------- BEGIN EVENT HANDLERS -------------------221    onMenuMember = function (event) {222        stateMap.currentAction = configMap.actionTypes.list;223        event.preventDefault();224        jqueryMap.$contentWrapper.children().hide();225        226        configMap.general_model.findAll(configMap.object_type, memberCallback);227    };228    /**229     * Inactivates the selected member. And in a second step the selected member is deleted also from230     * the corresponding membership of the current year (if it already exists);231     * 232     * @param {type} event233     * @returns {Boolean}234     */235    onDeleteMember = function (event) {236        stateMap.currentAction = configMap.actionTypes.delete;237        event.preventDefault();238        stateMap.selectedMemberId = $(this).attr("alt").replace("Delete", "");239        var theMember = null;240        if (stateMap.currentMember.isAdmin || stateMap.selectedMemberId === stateMap.currentMember._id) {241            theMember = configMap.general_model.getById(configMap.object_type, stateMap.selectedMemberId);242            if (!confirm("Willst Du wirklich [" + theMember.username + "] inaktivieren ?")) {243                return false;244            }245            configMap.general_model.deleteItem(configMap.object_type, theMember._id, memberCallback);246        }247    };248    onEditMember = function (event) {249        console.log("on edit member");250        stateMap.currentAction = configMap.actionTypes.update;251        stateMap.saveIsEdit = true;252        stateMap.selectedMemberId = $(this).attr("alt").replace("Edit", "");253        console.log("id = " + stateMap.selectedMemberId);254        var theMember = configMap.general_model.getById(configMap.object_type, stateMap.selectedMemberId);255        if (stateMap.currentMember.isAdmin || stateMap.selectedMemberId === stateMap.currentMember._id) {256            jqueryMap.$memberForm.find("#txtID").val(theMember._id);257            jqueryMap.$memberForm.find("#txtVorname").val(theMember.firstname);258            jqueryMap.$memberForm.find("#txtNachname").val(theMember.lastname);259            jqueryMap.$memberForm.find("#txtUsername").val(theMember.username);260            jqueryMap.$memberForm.find("#txtUsername").prop("readonly", true);261            jqueryMap.$memberForm.find("#txtEmail").val(theMember.email);262            jqueryMap.$memberForm.find("#txtZip").val(theMember.zip);263            jqueryMap.$memberForm.find("#txtCity").val(theMember.city);264            jqueryMap.$memberForm.find("#txtAddress").val(theMember.address);265            jqueryMap.$memberForm.find("#txtPhone").val(theMember.phone);266            jqueryMap.$memberForm.find("#txtMobil").val(theMember.mobil);267            jqueryMap.$memberForm.find("#txtAdmissionDate").val(theMember.admissionDate);268            jqueryMap.$memberForm.find("#txtIsActive").prop("checked", theMember.isActive);269            jqueryMap.$memberForm.find("#txtVorname").focus();270            aige.util.updatePopup(jqueryMap.$memberFormPopup);271            jqueryMap.$memberFormPopup.show();272            jqueryMap.$overlay.fadeIn();273            event.preventDefault();274        }275        return false;276    };277    onCreateMember = function () {278        if (stateMap.currentMember.isAdmin) {279            stateMap.currentAction = configMap.actionTypes.create;280            stateMap.saveIsEdit = false;281            jqueryMap.$memberFormValidator.resetForm();282            jqueryMap.$memberForm[0].reset();283            jqueryMap.$memberFormPopup.find("#headerMemberFormPopup").text("Neues Mitglied anlegen");284            jqueryMap.$memberFormPopup.show();285            jqueryMap.$overlay.fadeIn();286            aige.util.updatePopup(jqueryMap.$memberFormPopup);287            jqueryMap.$memberForm.find("#txtIsAdmin").prop("readonly", false);288            jqueryMap.$memberForm.find("#txtUsername").prop("readonly", false);289            jqueryMap.$memberForm.find("#txtVorname").focus();290        }291        return false;292    };293    onSaveMember = function (event) {294        if (!jqueryMap.$memberForm.valid()) {295            return false;296        }297        var name = jqueryMap.$memberForm.find('#txtUsername').val();298        var thename = jqueryMap.$memberForm.find('#txtNachname').val();299        var isAdmin = false;300        if (name === 'Ecki' || name === 'Christian'301                || name === 'Serafim' || name === 'Claus-Peter' || name === 'Frank') {302            isAdmin = true;303        }304        if (thename === 'David') {305            isAdmin = true;306        }307        var theMember = {308            _id: jqueryMap.$memberForm.find('#txtID').val(),309            firstname: jqueryMap.$memberForm.find('#txtVorname').val(),310            lastname: jqueryMap.$memberForm.find('#txtNachname').val(),311            username: jqueryMap.$memberForm.find('#txtUsername').val(),312            email: jqueryMap.$memberForm.find('#txtEmail').val(),313            zip: jqueryMap.$memberForm.find('#txtZip').val(),314            city: jqueryMap.$memberForm.find('#txtCity').val(),315            address: jqueryMap.$memberForm.find('#txtAddress').val(),316            phone: jqueryMap.$memberForm.find('#txtPhone').val(),317            mobil: jqueryMap.$memberForm.find('#txtMobil').val(),318            admissionDate: jqueryMap.$memberForm.find('#txtAdmissionDate').val(),319            isActive: jqueryMap.$memberForm.find('#txtIsActive').is(":checked"),320            isAdmin: isAdmin321        };322        console.log(" der neue= " + JSON.stringify(theMember));323        stateMap.saveIsEdit ?324                configMap.general_model.updateItem(configMap.object_type, theMember, memberCallback) :325                configMap.general_model.createItem(configMap.object_type, theMember, memberCallback);326        jqueryMap.$memberFormPopup.fadeOut();327        jqueryMap.$overlay.fadeOut();328        event.preventDefault();329    };330    onLoginSuccess = function (event, login_user) {331        stateMap.currentMember = login_user;332        console.log("current member for member model=" + stateMap.currentMember.username);333        return false;334    }335    //-------------------- END EVENT HANDLERS --------------------336    //-------------------- START CALLBACKS  -------------------- 337    memberCallback = function (error) {338        var $message;339        switch (stateMap.currentAction) {340            case configMap.actionTypes.list:341                $message = error ?342                        $("<span>Die Suche war nicht erfolgreich</span>") : $("<span>Das Ergebnis der Mitgliedersuche:</span>");343                break;344            case configMap.actionTypes.create:345                $message = error ?346                        $("<span>Die 'Neuanlage' war nicht erfolgreich</span>") : $("<span> Es wurde ein neues Mitglied gespeichert.</span>");347                break;348            case configMap.actionTypes.update:349                $message = error ?350                        $("<span>Die 'Aendernung' war nicht erfolgreich</span>") : $("<span> Die Aenderung wurde gespeichert.</span>");351                break;352            case configMap.actionTypes.delete:353                $message = error ?354                        $("<span>Die Transaktion 'Entfernen' war nicht erfolgreich</span>") : $("<span> Das Mitglied wurde deaktiviert.</span>");355                break;356        }357        error ?358                aige.util.messageError($message) :359                aige.util.messageConfirm($message);360        listMembers();361    };362    //-------------------- END CALLBACKS --------------------363    //-------------------- START PUBLIC METHIDS  -------------------- 364    // Begin public method /configModule/365    // Purpose    : Adjust configuration of allowed keys366    // Arguments  : A map of settable keys and values367    //   * color_name - color to use368    // Settings   :369    //   * configMap.settable_map declares allowed keys370    // Returns    : true371    // Throws     : none372    //373    configModule = function (input_map) {374        aige.util.setConfigMap({375            input_map: input_map,376            settable_map: configMap.settable_map,377            config_map: configMap378        });379        return true;380    };381    // End public method /configModule/382    // Begin public method /initModule/383    // Purpose    : Initializes module384    // Arguments  :385    //  * $container the jquery element used by this feature386    // Returns    : true387    // Throws     : none388    //389    initModule = function ($container) {390        stateMap.$shellcontainer = $container;391        setJqueryMap();392        jqueryMap.$memberMenu.on('click', onMenuMember);393        jqueryMap.$adminMemberList.on("click", "#btnDeleteMember", onDeleteMember);394        jqueryMap.$adminMemberList.on("click", "#btnEditMember", onEditMember);395        jqueryMap.$memberForm.on('submit', onSaveMember);396        jqueryMap.$memberForm.on("click", "#btnCloseMember", closePopup);397        jqueryMap.$contentWrapper.on("click", "#btnCreateMember", onCreateMember);398        jqueryMap.$contentWrapper.on("click", "#overlay-bg", closePopup);399        $.gevent.subscribe(jqueryMap.$contentWrapper, 'login-success', onLoginSuccess);400        $(window).resize(aige.util.updatePopup(jqueryMap.$memberFormPopup));401        return true;402    };403    // End public method /initModule/404    // return public methods405    return {406        configModule: configModule,407        initModule: initModule408    };409    //------------------- END PUBLIC METHODS ---------------------...

Full Screen

Full Screen

spa.chat.js

Source:spa.chat.js Github

copy

Full Screen

1/*2 * spa.chat.js3 * Chat feature module for SPA4*/5/*jslint         browser : true, continue : true,6  devel  : true, indent  : 2,    maxerr   : 50,7  newcap : true, nomen   : true, plusplus : true,8  regexp : true, sloppy  : true, vars     : false,9  white  : true10*/11/*global $, spa */12spa.chat = (function () {13  'use strict';14  //---------------- BEGIN MODULE SCOPE VARIABLES --------------15  var16    configMap = {17      main_html : String()18        + '<div class="spa-chat">'19          + '<div class="spa-chat-head">'20            + '<div class="spa-chat-head-toggle">+</div>'21            + '<div class="spa-chat-head-title">'22              + 'Chat'23            + '</div>'24          + '</div>'25          + '<div class="spa-chat-closer">x</div>'26          + '<div class="spa-chat-sizer">'27            + '<div class="spa-chat-list">'28              + '<div class="spa-chat-list-box"></div>'29            + '</div>'30            + '<div class="spa-chat-msg">'31              + '<div class="spa-chat-msg-log"></div>'32              + '<div class="spa-chat-msg-in">'33                + '<form class="spa-chat-msg-form">'34                  + '<input type="text"/>'35                  + '<input type="submit" style="display:none"/>'36                  + '<div class="spa-chat-msg-send">'37                    + 'send'38                  + '</div>'39                + '</form>'40              + '</div>'41            + '</div>'42          + '</div>'43        + '</div>',44      settable_map : {45        slider_open_time    : true,46        slider_close_time   : true,47        slider_opened_em    : true,48        slider_closed_em    : true,49        slider_opened_title : true,50        slider_closed_title : true,51        chat_model      : true,52        people_model    : true,53        set_chat_anchor : true54      },55      slider_open_time     : 250,56      slider_close_time    : 250,57      slider_opened_em     : 18,58      slider_closed_em     : 2,59      slider_opened_title  : 'Tap to close',60      slider_closed_title  : 'Tap to open',61      slider_opened_min_em : 10,62      window_height_min_em : 20,63      chat_model      : null,64      people_model    : null,65      set_chat_anchor : null66    },67    stateMap  = {68      $append_target   : null,69      position_type    : 'closed',70      px_per_em        : 0,71      slider_hidden_px : 0,72      slider_closed_px : 0,73      slider_opened_px : 074    },75    jqueryMap = {},76    setJqueryMap,  setPxSizes,   scrollChat,77    writeChat,     writeAlert,   clearChat,78    setSliderPosition,79    onTapToggle,   onSubmitMsg,  onTapList,80    onSetchatee,   onUpdatechat, onListchange,81    onLogin,       onLogout,82    configModule,  initModule,83    removeSlider,  handleResize;84  //----------------- END MODULE SCOPE VARIABLES ---------------85  //------------------- BEGIN UTILITY METHODS ------------------86  //-------------------- END UTILITY METHODS -------------------87  //--------------------- BEGIN DOM METHODS --------------------88  // Begin DOM method /setJqueryMap/89  setJqueryMap = function () {90    var91      $append_target = stateMap.$append_target,92      $slider        = $append_target.find( '.spa-chat' );93    jqueryMap = {94      $slider   : $slider,95      $head     : $slider.find( '.spa-chat-head' ),96      $toggle   : $slider.find( '.spa-chat-head-toggle' ),97      $title    : $slider.find( '.spa-chat-head-title' ),98      $sizer    : $slider.find( '.spa-chat-sizer' ),99      $list_box : $slider.find( '.spa-chat-list-box' ),100      $msg_log  : $slider.find( '.spa-chat-msg-log' ),101      $msg_in   : $slider.find( '.spa-chat-msg-in' ),102      $input    : $slider.find( '.spa-chat-msg-in input[type=text]'),103      $send     : $slider.find( '.spa-chat-msg-send' ),104      $form     : $slider.find( '.spa-chat-msg-form' ),105      $window   : $(window)106    };107  };108  // End DOM method /setJqueryMap/109  // Begin DOM method /setPxSizes/110  setPxSizes = function () {111    var px_per_em, window_height_em, opened_height_em;112    px_per_em = spa.util_b.getEmSize( jqueryMap.$slider.get(0) );113    window_height_em = Math.floor(114      ( jqueryMap.$window.height() / px_per_em ) + 0.5115    );116    opened_height_em117      = window_height_em > configMap.window_height_min_em118      ? configMap.slider_opened_em119      : configMap.slider_opened_min_em;120    stateMap.px_per_em        = px_per_em;121    stateMap.slider_closed_px = configMap.slider_closed_em * px_per_em;122    stateMap.slider_opened_px = opened_height_em * px_per_em;123    jqueryMap.$sizer.css({124      height : ( opened_height_em - 2 ) * px_per_em125    });126  };127  // End DOM method /setPxSizes/128  // Begin public method /setSliderPosition/129  // Example   : spa.chat.setSliderPosition( 'closed' );130  // Purpose   : Move the chat slider to the requested position131  // Arguments :132  //   * position_type - enum('closed', 'opened', or 'hidden')133  //   * callback - optional callback to be run end at the end134  //     of slider animation.  The callback receives a jQuery135  //     collection representing the slider div as its single136  //     argument137  // Action    :138  //   This method moves the slider into the requested position.139  //   If the requested position is the current position, it140  //   returns true without taking further action141  // Returns   :142  //   * true  - The requested position was achieved143  //   * false - The requested position was not achieved144  // Throws    : none145  //146  setSliderPosition = function ( position_type, callback ) {147    var148      height_px, animate_time, slider_title, toggle_text;149    // position type of 'opened' is not allowed for anon user;150    // therefore we simply return false; the shell will fix the151    // uri and try again.152    if ( position_type === 'opened'153      && configMap.people_model.get_user().get_is_anon()154    ){ return false; }155    // return true if slider already in requested position156    if ( stateMap.position_type === position_type ){157      if ( position_type === 'opened' ) {158        jqueryMap.$input.focus();159      }160      return true;161    }162    // prepare animate parameters163    switch ( position_type ){164      case 'opened' :165        height_px    = stateMap.slider_opened_px;166        animate_time = configMap.slider_open_time;167        slider_title = configMap.slider_opened_title;168        toggle_text  = '=';169        jqueryMap.$input.focus();170      break;171      case 'hidden' :172        height_px    = 0;173        animate_time = configMap.slider_open_time;174        slider_title = '';175        toggle_text  = '+';176      break;177      case 'closed' :178        height_px    = stateMap.slider_closed_px;179        animate_time = configMap.slider_close_time;180        slider_title = configMap.slider_closed_title;181        toggle_text  = '+';182      break;183      // bail for unknown position_type184      default : return false;185    }186    // animate slider position change187    stateMap.position_type = '';188    jqueryMap.$slider.animate(189      { height : height_px },190      animate_time,191      function () {192        jqueryMap.$toggle.prop( 'title', slider_title );193        jqueryMap.$toggle.text( toggle_text );194        stateMap.position_type = position_type;195        if ( callback ) { callback( jqueryMap.$slider ); }196      }197    );198    return true;199  };200  // End public DOM method /setSliderPosition/201  // Begin private DOM methods to manage chat message202  scrollChat = function() {203    var $msg_log = jqueryMap.$msg_log;204    $msg_log.animate(205      { scrollTop : $msg_log.prop( 'scrollHeight' )206        - $msg_log.height()207      },208      150209    );210  };211  writeChat = function ( person_name, text, is_user ) {212    var msg_class = is_user213      ? 'spa-chat-msg-log-me' : 'spa-chat-msg-log-msg';214    jqueryMap.$msg_log.append(215      '<div class="' + msg_class + '">'216      + spa.util_b.encodeHtml(person_name) + ': '217      + spa.util_b.encodeHtml(text) + '</div>'218    );219    scrollChat();220  };221  writeAlert = function ( alert_text ) {222    jqueryMap.$msg_log.append(223      '<div class="spa-chat-msg-log-alert">'224        + spa.util_b.encodeHtml(alert_text)225      + '</div>'226    );227    scrollChat();228  };229  clearChat = function () { jqueryMap.$msg_log.empty(); };230  // End private DOM methods to manage chat message231  //---------------------- END DOM METHODS ---------------------232  //------------------- BEGIN EVENT HANDLERS -------------------233  onTapToggle = function ( event ) {234    var set_chat_anchor = configMap.set_chat_anchor;235    if ( stateMap.position_type === 'opened' ) {236      set_chat_anchor( 'closed' );237    }238    else if ( stateMap.position_type === 'closed' ){239      set_chat_anchor( 'opened' );240    }241    return false;242  };243  onSubmitMsg = function ( event ) {244    var msg_text = jqueryMap.$input.val();245    if ( msg_text.trim() === '' ) { return false; }246    configMap.chat_model.send_msg( msg_text );247    jqueryMap.$input.focus();248    jqueryMap.$send.addClass( 'spa-x-select' );249    setTimeout(250      function () { jqueryMap.$send.removeClass( 'spa-x-select' ); },251      250252    );253    return false;254  };255  onTapList = function ( event ) {256    var $tapped  = $( event.elem_target ), chatee_id;257    if ( ! $tapped.hasClass('spa-chat-list-name') ) { return false; }258    chatee_id = $tapped.attr( 'data-id' );259    if ( ! chatee_id ) { return false; }260    configMap.chat_model.set_chatee( chatee_id );261    return false;262  };263  onSetchatee = function ( event, arg_map ) {264    var265      new_chatee = arg_map.new_chatee,266      old_chatee = arg_map.old_chatee;267    jqueryMap.$input.focus();268    if ( ! new_chatee ) {269      if ( old_chatee ) {270        writeAlert( old_chatee.name + ' has left the chat' );271      }272      else {273        writeAlert( 'Your friend has left the chat' );274      }275      jqueryMap.$title.text( 'Chat' );276      return false;277    }278    jqueryMap.$list_box279      .find( '.spa-chat-list-name' )280      .removeClass( 'spa-x-select' )281      .end()282      .find( '[data-id=' + arg_map.new_chatee.id + ']' )283      .addClass( 'spa-x-select' );284    writeAlert( 'Now chatting with ' + arg_map.new_chatee.name );285    jqueryMap.$title.text( 'Chat with ' + arg_map.new_chatee.name );286    return true;287  };288  onListchange = function ( event ) {289    var290      list_html = String(),291      people_db = configMap.people_model.get_db(),292      chatee    = configMap.chat_model.get_chatee();293    people_db().each( function ( person, idx ) {294      var select_class = '';295      if ( person.get_is_anon() || person.get_is_user()296      ) { return true;}297      if ( chatee && chatee.id === person.id ) {298        select_class=' spa-x-select';299      }300      list_html301        += '<div class="spa-chat-list-name'302        +  select_class + '" data-id="' + person.id + '">'303        +  spa.util_b.encodeHtml( person.name ) + '</div>';304    });305    if ( ! list_html ) {306      list_html = String()307        + '<div class="spa-chat-list-note">'308        + 'To chat alone is the fate of all great souls...<br><br>'309        + 'No one is online'310        + '</div>';311      clearChat();312    }313    // jqueryMap.$list_box.html( list_html );314    jqueryMap.$list_box.html( list_html );315  };316  onUpdatechat = function ( event, msg_map ) {317    var318      is_user,319      sender_id = msg_map.sender_id,320      msg_text  = msg_map.msg_text,321      chatee    = configMap.chat_model.get_chatee() || {},322      sender    = configMap.people_model.get_by_cid( sender_id );323    if ( ! sender ) {324      writeAlert( msg_text );325      return false;326    }327    is_user = sender.get_is_user();328    if ( ! ( is_user || sender_id === chatee.id ) ) {329      configMap.chat_model.set_chatee( sender_id );330    }331    writeChat( sender.name, msg_text, is_user );332    if ( is_user ) {333      jqueryMap.$input.val( '' );334      jqueryMap.$input.focus();335    }336  };337  onLogin = function ( event, login_user ) {338    configMap.set_chat_anchor( 'opened' );339  };340  onLogout = function ( event, logout_user ) {341    configMap.set_chat_anchor( 'closed' );342    jqueryMap.$title.text( 'Chat' );343    clearChat();344  };345  //-------------------- END EVENT HANDLERS --------------------346  //------------------- BEGIN PUBLIC METHODS -------------------347  // Begin public method /configModule/348  // Example   : spa.chat.configModule({ slider_open_em : 18 });349  // Purpose   : Configure the module prior to initialization350  // Arguments :351  //   * set_chat_anchor - a callback to modify the URI anchor to352  //     indicate opened or closed state. This callback must return353  //     false if the requested state cannot be met354  //   * chat_model - the chat model object provides methods355  //       to interact with our instant messaging356  //   * people_model - the people model object which provides357  //       methods to manage the list of people the model maintains358  //   * slider_* settings. All these are optional scalars.359  //       See mapConfig.settable_map for a full list360  //       Example: slider_open_em is the open height in em's361  // Action    :362  //   The internal configuration data structure (configMap) is363  //   updated with provided arguments. No other actions are taken.364  // Returns   : true365  // Throws    : JavaScript error object and stack trace on366  //             unacceptable or missing arguments367  //368  configModule = function ( input_map ) {369    spa.util.setConfigMap({370      input_map    : input_map,371      settable_map : configMap.settable_map,372      config_map   : configMap373    });374    return true;375  };376  // End public method /configModule/377  // Begin public method /initModule/378  // Example    : spa.chat.initModule( $('#div_id') );379  // Purpose    :380  //   Directs Chat to offer its capability to the user381  // Arguments  :382  //   * $append_target (example: $('#div_id')).383  //     A jQuery collection that should represent384  //     a single DOM container385  // Action     :386  //   Appends the chat slider to the provided container and fills387  //   it with HTML content.  It then initializes elements,388  //   events, and handlers to provide the user with a chat-room389  //   interface390  // Returns    : true on success, false on failure391  // Throws     : none392  //393  initModule = function ( $append_target ) {394    var $list_box;395    // load chat slider html and jquery cache396    stateMap.$append_target = $append_target;397    $append_target.append( configMap.main_html );398    setJqueryMap();399    setPxSizes();400    // initialize chat slider to default title and state401    jqueryMap.$toggle.prop( 'title', configMap.slider_closed_title );402    stateMap.position_type = 'closed';403    // Have $list_box subscribe to jQuery global events404    $list_box = jqueryMap.$list_box;405    $.gevent.subscribe( $list_box, 'spa-listchange', onListchange );406    $.gevent.subscribe( $list_box, 'spa-setchatee',  onSetchatee  );407    $.gevent.subscribe( $list_box, 'spa-updatechat', onUpdatechat );408    $.gevent.subscribe( $list_box, 'spa-login',      onLogin      );409    $.gevent.subscribe( $list_box, 'spa-logout',     onLogout     );410    // bind user input events411    jqueryMap.$head.bind(     'utap', onTapToggle );412    jqueryMap.$list_box.bind( 'utap', onTapList   );413    jqueryMap.$send.bind(     'utap', onSubmitMsg );414    jqueryMap.$form.bind(   'submit', onSubmitMsg );415  };416  // End public method /initModule/417  // Begin public method /removeSlider/418  // Purpose    :419  //   * Removes chatSlider DOM element420  //   * Reverts to initial state421  //   * Removes pointers to callbacks and other data422  // Arguments  : none423  // Returns    : true424  // Throws     : none425  //426  removeSlider = function () {427    // unwind initialization and state428    // remove DOM container; this removes event bindings too429    if ( jqueryMap.$slider ) {430      jqueryMap.$slider.remove();431      jqueryMap = {};432    }433    stateMap.$append_target = null;434    stateMap.position_type  = 'closed';435    // unwind key configurations436    configMap.chat_model      = null;437    configMap.people_model    = null;438    configMap.set_chat_anchor = null;439    return true;440  };441  // End public method /removeSlider/442  // Begin public method /handleResize/443  // Purpose    :444  //   Given a window resize event, adjust the presentation445  //   provided by this module if needed446  // Actions    :447  //   If the window height or width falls below448  //   a given threshold, resize the chat slider for the449  //   reduced window size.450  // Returns    : Boolean451  //   * false - resize not considered452  //   * true  - resize considered453  // Throws     : none454  //455  handleResize = function () {456    // don't do anything if we don't have a slider container457    if ( ! jqueryMap.$slider ) { return false; }458    setPxSizes();459    if ( stateMap.position_type === 'opened' ){460      jqueryMap.$slider.css({ height : stateMap.slider_opened_px });461    }462    return true;463  };464  // End public method /handleResize/465  // return public methods466  return {467    setSliderPosition : setSliderPosition,468    configModule      : configModule,469    initModule        : initModule,470    removeSlider      : removeSlider,471    handleResize      : handleResize472  };473  //------------------- END PUBLIC METHODS ---------------------...

Full Screen

Full Screen

tjx.app.securityinfo.chemical.js

Source:tjx.app.securityinfo.chemical.js Github

copy

Full Screen

1/**2 * Created by Administrator on 2016/1/15.3 */4/*5 * module_template.js6 * Template for browser feature modules7 */8/*jslint browser : true, continue : true,9 devel : true, indent : 2, maxerr : 50,10 newcap : true, nomen : true, plusplus : true,11 regexp : true, sloppy : true, vars : false,12 white : true13 */14/*global $, tjx */15tjx.app.securityinfo.chemical = (function () {16//---------------- BEGIN MODULE SCOPE VARIABLES --------------17    var18        configMap = {19            settable_map : { color_name: true },20            color_name : 'blue'21        },22        stateMap = {23            $container : null,24            validator : null,25            category : [],26            names : [],27            units : [],28            cas : [],29            cascatalog : [],30            namescatalog : [],31            is_new : false,32            is_modal : false33        },34        jqueryMap = {},35        setJqueryMap, configModule, initModule,36        onSumitData, onCancelData, onSuccess,37        onFail, initChemicalCategoryData, initChemicalSelect,38        onDangerChemical, onPoisonChemical, onDrugChemical,39        initChemicalNameCASData, initChemicalNameCasInput,40        onInitForm,41        onInitSuccess,42        onEditData,43        onEditSuccess44        ;45//----------------- END MODULE SCOPE VARIABLES ---------------46//------------------- BEGIN UTILITY METHODS ------------------47// example : getTrimmedString48    // help-block has-error help-block-error49    initChemicalCategoryData = function ( data ) {50        $.each( data, function ( index, item ) {51            stateMap.category.push( item.Category );52            var items = [];53            $.each( item.Item, function ( index, name ) {54                items.push( name.Name );55            } )56            stateMap.names[ item.Category ] = items;57        } );58        initChemicalSelect();59    }60    initChemicalNameCASData = function ( data ) {61        $.each( data, function ( index, item ) {62            stateMap.names[ item.Name ] = item.CAS;63            stateMap.cas[ item.CAS ] = item.Name;64            stateMap.cascatalog[ item.CAS ] = item.Unit;65            stateMap.namescatalog[ item.Name ] = item.Unit;66        } );67        initChemicalNameCasInput();68    }69    initChemicalNameCasInput = function (  ) {70        jqueryMap.$danger_chemicalnum.focusout( function () {71            var cas = jqueryMap.$danger_chemicalnum.val();72            jqueryMap.$danger_chemicalname.val( stateMap.cas[ cas ] );73            jqueryMap.$danger_chemicalcatalognum.val( stateMap.cascatalog[ cas ] );74        } );75        jqueryMap.$danger_chemicalname.focusout( function () {76            var cas = jqueryMap.$danger_chemicalname.val();77            jqueryMap.$danger_chemicalnum.val( stateMap.names[ cas ] );78            jqueryMap.$danger_chemicalcatalognum.val( stateMap.namescatalog[ cas ] );79        } );80        jqueryMap.$poison_chemicalnum.focusout( function () {81            var cas = jqueryMap.$poison_chemicalnum.val();82            jqueryMap.$poison_chemicalname.val( stateMap.cas[ cas ] );83        } );84        jqueryMap.$poison_chemicalname.focusout( function () {85            var cas = jqueryMap.$poison_chemicalname.val();86            jqueryMap.$poison_chemicalnum.val( stateMap.names[ cas ] );87        } );88        jqueryMap.$drug_chemicalnum.focusout( function () {89            var cas = jqueryMap.$drug_chemicalnum.val();90            jqueryMap.$drug_chemicalname.val( stateMap.cas[ cas ] );91        } );92        jqueryMap.$drug_chemicalname.focusout( function () {93            var cas = jqueryMap.$drug_chemicalname.val();94            jqueryMap.$drug_chemicalnum.val( stateMap.names[ cas ] );95        } );96    }97//-------------------- END UTILITY METHODS -------------------98//--------------------- BEGIN DOM METHODS --------------------99// Begin DOM method /setJqueryMap/100    setJqueryMap = function () {101        var $container = stateMap.$container;102        jqueryMap = {103            $container : $container,104            $form : $container.find( '.horizontal-form' ),105            $formbody : $container.find( '.form-body' ),106            $send : $container.find( '#ok' ),107            $cancel : $container.find( '#cancel' ),108            $caption : $container.find( '.caption' ),109            $danger_chemicalcategory :  $container.find( '#Danger-ChemicalCategory' ),110            $danger_chemicalsubcategory :  $container.find( '#Danger-ChemicalSubCategory' ),111            $danger_chemicalname :  $container.find( '#Danger-ChemicalName' ),112            $danger_chemicalnum :  $container.find( '#Danger-ChemicalNum' ),113            $danger_chemicalcatalognum :  $container.find( '#Danger-ChemicalCatalogNum' ),114            $danger_chemicalunit :  $container.find( '#Danger-ChemicalUnit' ),115            $danger_maximumstockingunit :  $container.find( '#Danger-MaximumStockingUnit' ),116            $poison_chemicalcategory :  $container.find( '#Poison-ChemicalCategory' ),117            $poison_chemicalsubcategory :  $container.find( '#Poison-ChemicalSubCategory' ),118            $poison_chemicalname :  $container.find( '#Poison-ChemicalName' ),119            $poison_chemicalnum :  $container.find( '#Poison-ChemicalNum' ),120            $poison_chemicalunit :  $container.find( '#Poison-ChemicalUnit' ),121            $poison_maximumstockingunit :  $container.find( '#Poison-MaximumStockingUnit' ),122            $drug_chemicalcategory :  $container.find( '#Drug-ChemicalCategory' ),123            $drug_chemicalsubcategory :  $container.find( '#Drug-ChemicalSubCategory' ),124            $drug_chemicalname :  $container.find( '#Drug-ChemicalName' ),125            $drug_chemicalnum :  $container.find( '#Drug-ChemicalNum' ),126            $drug_chemicalunit :  $container.find( '#Drug-ChemicalUnit' ),127            $drug_maximumstockingunit :  $container.find( '#Drug-MaximumStockingUnit' ),128        };129    };130// End DOM method /setJqueryMap/131    initChemicalSelect = function (  ) {132         tjx.util.ui.initSelectByArray( jqueryMap.$danger_chemicalcategory, stateMap.category );133         tjx.util.ui.initSelectByArray( jqueryMap.$danger_chemicalsubcategory, stateMap.names[ jqueryMap.$danger_chemicalcategory.val() ] );134         jqueryMap.$danger_chemicalcategory.change( function () {135            tjx.util.ui.initSelectByArray( jqueryMap.$danger_chemicalsubcategory, stateMap.names[ jqueryMap.$danger_chemicalcategory.val() ] , true );136           /*  onDangerChemical();*/137        } );138      /*  jqueryMap.$danger_chemicalname.change( function () {139            onDangerChemical();140        } );141        onDangerChemical();*/142        tjx.util.ui.initSelectByArray( jqueryMap.$poison_chemicalcategory, stateMap.category );143        tjx.util.ui.initSelectByArray( jqueryMap.$poison_chemicalsubcategory, stateMap.names[ jqueryMap.$poison_chemicalcategory.val() ] );144        jqueryMap.$poison_chemicalcategory.change( function () {145            tjx.util.ui.initSelectByArray( jqueryMap.$poison_chemicalsubcategory, stateMap.names[ jqueryMap.$poison_chemicalcategory.val() ] , true );146          /*  onPoisonChemical();*/147        } );148       /* jqueryMap.$poison_chemicalname.change( function () {149            onPoisonChemical();150        } );151        onPoisonChemical();*/152        tjx.util.ui.initSelectByArray( jqueryMap.$drug_chemicalcategory, stateMap.category );153        tjx.util.ui.initSelectByArray( jqueryMap.$drug_chemicalsubcategory, stateMap.names[ jqueryMap.$drug_chemicalcategory.val() ] );154        jqueryMap.$drug_chemicalcategory.change( function () {155            tjx.util.ui.initSelectByArray( jqueryMap.$drug_chemicalsubcategory, stateMap.names[ jqueryMap.$drug_chemicalcategory.val() ] , true );156           /* onDrugChemical();*/157        } );158      /*  jqueryMap.$drug_chemicalname.change( function () {159            onDrugChemical();160        } );161        onDrugChemical();*/162    }163   /* onDangerChemical = function () {164        jqueryMap.$danger_chemicalnum.val( stateMap.cas[ jqueryMap.$danger_chemicalname.val() ] );165        jqueryMap.$danger_chemicalunit.val( stateMap.units[ jqueryMap.$danger_chemicalname.val() ] );166        jqueryMap.$danger_maximumstockingunit.val( stateMap.units[ jqueryMap.$danger_chemicalname.val() ] );167    }168    onPoisonChemical = function () {169        jqueryMap.$poison_chemicalnum.val( stateMap.cas[ jqueryMap.$poison_chemicalname.val() ] );170        jqueryMap.$poison_chemicalunit.val( stateMap.units[ jqueryMap.$poison_chemicalname.val() ] );171        jqueryMap.$poison_maximumstockingunit.val( stateMap.units[ jqueryMap.$poison_chemicalname.val() ] );172    }173    onDrugChemical = function () {174        jqueryMap.$drug_chemicalnum.val( stateMap.cas[ jqueryMap.$drug_chemicalname.val() ] );175        jqueryMap.$drug_chemicalunit.val( stateMap.units[ jqueryMap.$drug_chemicalname.val() ] );176        jqueryMap.$drug_maximumstockingunit.val( stateMap.units[ jqueryMap.$drug_chemicalname.val() ] );177    }*/178//---------------------- END DOM METHODS ---------------------179//------------------- BEGIN EVENT HANDLERS -------------------180// example: onClickButton = ...181    onSumitData = function ( event ) {182        // event.preventDefault();183            var data = tjx.util.getValuesFromFormInput( jqueryMap.$formbody );184            var arg_map = {185                data : data,186                success : onSuccess,187                fail : onFail188            };189            tjx.data.chemical.addChemicalInfo( arg_map );190    }191    onCancelData = function ( event ) {192    }193    onSuccess = function ( data  ) {194        if ( data.IsSuccess ){195            tjx.util.ui.showSuccess( '系统提示' , data.Desc);196            if ( stateMap.is_modal ){197                $.gevent.publish( 'table-update', [ {} ]);198            }else {199                jqueryMap.$cancel.trigger("click");200                onDangerChemical();201                onPoisonChemical();202                onDrugChemical();203            }204        }else{205            tjx.util.ui.showAlert( '系统提示' , data.Desc);206        }207    }208    onFail = function ( data ) {209    }210    onInitForm = function (  ) {211        var arg_map = {212            data : { key : tjx.table.getSelectedKey() },213            success : onInitSuccess,214            fail : onFail215        };216        tjx.data.chemical.getChemicalInfo( arg_map );217    }218    onInitSuccess = function ( data ) {219        tjx.util.setFormValuesFromData( jqueryMap.$formbody, data );220    }221    onEditData = function ( event ) {222        // event.preventDefault();223            var data = tjx.util.getValuesFromFormInput( jqueryMap.$formbody );224            var arg_map = {225                key : tjx.table.getSelectedKey(),226                data : data,227                success : onEditSuccess,228                fail : onFail229            };230            tjx.data.chemical.updateChemicalInfo( arg_map );231    }232    onEditSuccess = function ( data ) {233        if ( data.IsSuccess ){234            tjx.util.ui.showSuccess( '系统提示' , '危险化学品更新完成。');235            $.gevent.publish( 'table-update', [ {} ]);236        }else{237            tjx.util.ui.showAlert( '系统提示' , '危险化学品更新不成功,请重试。');238        }239    }240//-------------------- END EVENT HANDLERS --------------------241//------------------- BEGIN PUBLIC METHODS -------------------242// Begin public method /configModule/243// Purpose : Adjust configuration of allowed keys244// Arguments : A map of settable keys and values245// * color_name - color to use246// Settings :247// * configMap.settable_map declares allowed keys248// Returns : true249// Throws : none250//251    configModule = function ( input_map ) {252        spa.butil.setConfigMap({253            input_map : input_map,254            settable_map : configMap.settable_map,255            config_map : configMap256        });257        return true;258    };259// End public method /configModule/260// Begin public method /initModule/261// Purpose : Initializes module262// Arguments :263// * $container the jquery element used by this feature264// Returns : true265// Throws : nonaccidental266//267    initModule = function ( $container,   isnew,  ismodal) {268        stateMap.$container = $container;269        setJqueryMap();270        stateMap.is_new = isnew;271        stateMap.is_modal = ismodal;272        tjx.util.ui.input.initOnlyNumberInput( jqueryMap.$container );273        tjx.data.chemical.getChemicalCategoryData( initChemicalCategoryData );274        tjx.data.chemical.getChemicalNameCas( initChemicalNameCASData );275      //  jqueryMap.$cancel.bind( 'click', onCancelData );276        if ( stateMap.is_new ) {277            if ( ! stateMap.is_modal ){278                jqueryMap.$caption.append( tjx.index3.getTitle() );279            }280            jqueryMap.$send.bind( 'click', onSumitData );281        }282        else283        {284            onInitForm();285            jqueryMap.$send.bind( 'click', onEditData );286        }287        return true;288    };289// End public method /initModule/290// return public methods291    return {292        configModule : configModule,293        initModule : initModule294    };295//------------------- END PUBLIC METHODS ---------------------...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Cypress', () => {2  it('jQuery map', () => {3    cy.get('.query-list li').map(($el, index, $list) => {4      console.log($el.text())5    })6  })7})8describe('Cypress', () => {9  it('jQuery each', () => {10    cy.get('.query-list li').each(($el, index, $list) => {11      console.log($el.text())12    })13  })14})15describe('Cypress', () => {16  it('jQuery each', () => {17    cy.get('.query-list li').each(($el, index, $list) => {18      console.log($el.text())19    })20  })21})22describe('Cypress', () => {23  it('jQuery each', () => {24    cy.get('.query-list li').each(($el, index, $list) => {25      console.log($el.text())26    })27  })28})29describe('Cypress', () => {30  it('jQuery each', () => {31    cy.get('.query-list li').each(($el, index, $list) => {32      console.log($el.text())33    })34  })35})36describe('Cypress', () => {37  it('jQuery each', () => {38    cy.get('.query-list li').each(($el, index, $list) => {39      console.log($el.text())40    })41  })42})43describe('Cypress', () => {44  it('jQuery each', () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test', () => {2  it('Test', () => {3    cy.get('.query-list')4      .find('li')5      .map((_, el) => el.innerText)6      .should('deep.eq', [7  })8})9describe('Test', () => {10  it('Test', () => {11    cy.get('.query-list')12      .find('li')13      .makeArray()14      .should('deep.eq', [15  })16})17describe('Test', () => {18  it('Test', () => {19    const $first = cy.get('.query-list')20    const $second = cy.get('.query-ul')21    cy.wrap($first)22      .merge($second)23      .should('have.length', 12)24  })25})26describe('Test', () => {27  it('Test', () => {28    const obj = {29      greet: function (

Full Screen

Using AI Code Generation

copy

Full Screen

1var result = jQuery.map(myArray, function (value, index) {2})3console.log(result)4### .each()5var result = jQuery.each(myArray, function (index, value) {6    console.log('Index: ' + index + ' Value: ' + value)7})8console.log(result)9### .grep()10var result = jQuery.grep(myArray, function (value, index) {11})12console.log(result)13### .inArray()

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("Test js", () => {2  it("test", () => {3    cy.get(".action-list")4      .find("li")5      .map(($el, index, $list) => {6        return $el.text() + " : " + (index + 1);7      })8      .should("deep.equal", [9      ]);10  });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var myArray = [1,2,3,4,5];2var newArray = $.map(myArray, function(value, index) {3  return value * 2;4});5console.log('newArray', newArray);6The jQuery.map() method is a shorthand for the following code:7var newArray = $.map(myArray, function(value, index) {8  return value * 2;9});10var newArray = [];11$.each(myArray, function(index, value) {12  newArray.push(value * 2);13});14console.log('newArray', newArray);15var myObject = {16}17var newObject = $.map(myObject, function(value, index) {18  return value * 2;19});20console.log('newObject', newObject);21The jQuery.map() method is a shorthand for the following code:22var newObject = $.map(myObject, function(value, index) {23  return value * 2;24});25var newObject = [];26$.each(myObject, function(index, value) {27  newObject.push(value * 2);28});29console.log('newObject', newObject);30jQuery.map() Method31The jQuery.map() method is used to iterate over an array or object

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2  it('test', () => {3    cy.get('input').then($input => {4      const name = $input.val()5      cy.wrap(name).should('be.empty')6    })7  })8})

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