{"size": 12863, "ext": "js", "max_stars_repo_path": "runtime/src/tests/work-item/work-item-list/testHelpers.js", "max_stars_repo_name": "riuvshin/fabric8-planner", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "runtime/src/tests/work-item/work-item-list/testHelpers.js", "max_issues_repo_name": "riuvshin/fabric8-planner", "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:36:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:36:46.000Z", "max_forks_repo_path": "runtime/src/tests/work-item/work-item-list/testHelpers.js", "max_forks_repo_name": "riuvshin/fabric8-planner", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 38.8610271903, "max_line_length": 146, "alphanum_fraction": 0.6552903677}
/**
 * Support module for automated UI tests for Planner
 * 
 * Ref: https://www.sitepoint.com/understanding-module-exports-exports-node-js/
 * 
 * @author ldimaggi
 */

let constants = require("./constants");
let testSupport = require("./testSupport");
var until = protractor.ExpectedConditions;

module.exports = {

    /**
     * Function to create (quick add) a new workitem
     * 
     * @param
     * page - workitem page
     * workItemTitle - Title string for the new workitem
     * workItemDesc - Description string for the new workitem, (desktop model only) (optional)
     * 
     */
    quickCreateWorkItem: function(page, titleText, descriptionText) {  

        /* Click the add button */
        page.clickWorkItemQuickAdd();

        /* Enter the workitem title */
        page.typeQuickAddWorkItemTitle(titleText);

        /* The description field is not displayed on phones - If the UI element is present, enter the description */
        page.workItemQuickAddDesc.isDisplayed().then(function(visible) {
            if (visible) {
                page.typeQuickAddWorkItemDesc(titleText);
            } 
        });

        /* Click the save button */
        page.clickQuickAddSave();

        /* Return the newly created workitem */
        browser.wait(until.presenceOf(page.workItemByTitle(titleText)), constants.WAIT, 'Failed to find workItem');
        return page.workItemByTitle(titleText);
    },

    /**
     * Function to create (add) a new workitem
     * 
     * @param
     * page - workitem page
     * workItemTitle - Title string for the new workitem
     * workItemDesc - Description string for the new work item
     * workItemType - Type of the workitem to create
     * assigneeName - User name to whom assign the workitem (optional)
     * 
     */
    createWorkItem: function(page, titleText, descriptionText, workItemType, assigneeName) {  

        testSupport.setBrowserMode('desktop');
        //console.log (theText);

        /* Click the add button */
        page.clickDetailedDialogButton();

        /* Select the workitem type */
        var detailPage = page.clickDetailedIcon("userstory");

        /* Enter the workitem description */
        detailPage.clickWorkItemDetailTitle2();
        browser.wait(until.visibilityOf(detailPage.workItemDetailTitle), constants.WAIT, 'Failed to find workItemList');  
        detailPage.setWorkItemDetailTitle (titleText, false);

        /* Select the workitem type */
        browser.wait(until.visibilityOf(detailPage.workItemTitleSaveIcon), constants.WAIT, 'Failed to find workItemList');  
        browser.wait(until.elementToBeClickable(detailPage.workItemTitleSaveIcon), constants.WAIT, 'Failed to find workItemList');  
        detailPage.clickWorkItemTitleSaveIcon();

        /* Enter the workitem description */
        detailPage.clickWorkItemDescriptionEditIcon2();
        detailPage.clickWorkItemDetailDescription();
        browser.wait(until.visibilityOf(detailPage.workItemDetailDescription), constants.WAIT, 'Failed to find workItemList');  
        detailPage.setWorkItemDetailDescription (titleText, false);
        detailPage.clickWorkItemDescriptionSaveIcon();

        /* Set the assignee */
        if (assigneeName != null) {
            browser.wait(until.elementToBeClickable(detailPage.workItemDetailAssigneeIcon), constants.WAIT, 'Failed to find Assignee Icon');   
            detailPage.clickworkItemDetailAssigneeIcon();
            browser.wait(until.elementToBeClickable(detailPage.workItemDetailAssigneeSearch), constants.WAIT, 'Failed to find Assignee Search');  
            detailPage.setWorkItemDetailAssigneeSearch(assigneeName, false);
//            detailPage.clickAssignedUserDropDownList(assigneeName);
        }

        /* Close the workitem add dialog */
        detailPage.clickWorkItemDetailFullPageCloseButton();
//        browser.wait(until.visibilityOf(page.workItemByTitle(titleText)), constants.WAIT, 'Failed to find workItemList');  
        return page.workItemByTitle(titleText);
    },

    /**
     * Function to assign a workitem
     * 
     * @param
     * page - workitem page
     * theWorkItem - workitem
     * assigneeName - User name to whom assign the workitem
     * 
     */
    setWorkItemAssignee: function(page, theWorkItem, assigneeName) {  

        var tempObject = {};

        testSupport.setBrowserMode('desktop');
        //console.log (theText);

        /* Locate the workitem */
        page.workItemViewId(theWorkItem).getText().then(function (text) { 

            /* Access the workitem's detailpage */
            var detailPage = page.clickWorkItemTitle(theWorkItem);

            /* Assign the workitem */
            browser.wait(until.elementToBeClickable(detailPage.workItemDetailAssigneeIcon), constants.WAIT, 'Failed to find Assignee Icon');   
            detailPage.clickworkItemDetailAssigneeIcon();
            browser.wait(until.elementToBeClickable(detailPage.workItemDetailAssigneeSearch), constants.WAIT, 'Failed to find Assignee Search');  
            detailPage.setWorkItemDetailAssigneeSearch(assigneeName, false);
            detailPage.clickAssignedUserDropDownList(assigneeName);

            /* Close the workitem add dialog */
            detailPage.clickWorkItemDetailCloseButton();
            browser.wait(until.visibilityOf(theWorkItem), constants.WAIT, 'Failed to find workItemList');  
        });
    },

    /**
     * Function to verify an assignee name in a workitem
     * 
     * @param
     * page - workitem page
     * theWorkItem - workitem
     * assigneeName - User name of the expected assignee
     * 
     */
    verifyworkItemAssignee: function(page, theWorkItem, assigneeName) {  

        var tempObject = {};

        testSupport.setBrowserMode('desktop');
        //console.log (theText);

        /* Locate the workitem */
        page.workItemViewId(theWorkItem).getText().then(function (text) { 

            /* Access the workitem's detailpage */
            var detailPage = page.clickWorkItemTitle(theWorkItem);
            browser.wait(until.elementToBeClickable(detailPage.details_assigned_user()), constants.WAIT, 'Failed to find Assignee Icon');   
 
            expect(detailPage.details_assigned_user().getText()).toContain(assigneeName);

            /* Close the workitem add dialog */
            detailPage.clickWorkItemDetailCloseButton();
            browser.wait(until.visibilityOf(theWorkItem), constants.WAIT, 'Failed to find workItemList');  
        });
    },


    /**
     * Function to delete a workitem
     * 
     * @param
     * page - workitem page
     * workItemTitle - Title string for the new workitem
     * confirm - Confirm or cancel the deletion
     * 
     */
    deleteWorkItem: function(page, theWorkItem, confirm) {  
        page.clickWorkItemKebabButton(theWorkItem);
        page.clickWorkItemKebabDeleteButton(theWorkItem);
        if (confirm) {
            page.clickWorkItemPopUpDeleteConfirmButton();
        }
        else {
            page.clickWorkItemPopUpDeleteCancelConfirmButton();
        }
    },

    /**
     * Function to set a workitem's title
     * 
     * @param
     * page - workitem page
     * oldTitleText - Original title text
     * newTitleText - Text to add to title
     * append - Boolean, should the new text be appended to the old title 
     * 
     */
    setWorkItemTitle: function(page, oldTitleText, newTitleText, append) {  

        testSupport.setBrowserMode('desktop');
        //console.log (theText);

        page.workItemViewId(page.workItemByTitle(oldTitleText)).getText().then(function (text) { 
            var detailPage = page.clickWorkItemTitle(oldTitleText);

            detailPage.clickWorkItemDetailTitleClick();

            /* Enter the workitem title */
            browser.wait(until.visibilityOf(detailPage.workItemDetailTitle), constants.WAIT, 'Failed to find workItemList');  
            detailPage.setWorkItemDetailTitle (newTitleText, append);

            /* And save it */
            browser.wait(until.visibilityOf(detailPage.workItemTitleSaveIcon), constants.WAIT, 'Failed to find workItemList');  
            browser.wait(until.elementToBeClickable(detailPage.workItemTitleSaveIcon), constants.WAIT, 'Failed to find workItemList');  
            detailPage.clickWorkItemTitleSaveIcon();

            /* Close the workitem add dialog */
            detailPage.clickWorkItemDetailCloseButton();
            if (append) {
                newTitleText = oldTitleText + newTitleText;
            }
            browser.wait(until.visibilityOf(page.workItemByTitle(newTitleText)), constants.WAIT, 'Failed to find workItemList');  
            return page.workItemByTitle(newTitleText);
      });
    },

    /**
     * Function to verify a workitem's title
     * 
     * @param
     * page - workitem page
     * theWorkItem - workitem
     * workitemTitle - Expected title for workitem
     * 
     */
    verifyWorkItemTitle: function(page, theWorkItem, workitemTitle) {  

        var tempObject = {};

        testSupport.setBrowserMode('desktop');
        //console.log (theText);

        /* Locate the workitem */
        page.workItemViewId(theWorkItem).getText().then(function (text) { 

            /* Access the workitem's detailpage */
            var detailPage = page.clickWorkItem(theWorkItem);
            browser.wait(until.elementToBeClickable(detailPage.details_assigned_user()), constants.WAIT, 'Failed to find Assignee Icon');     

//            expect(detailPage.clickWorkItemDetailTitle.getText()).toContain(workitemTitle);

            /* Close the workitem add dialog */
            detailPage.clickWorkItemDetailCloseButton();
            browser.wait(until.visibilityOf(theWorkItem), constants.WAIT, 'Failed to find workItemList');  
        });
    },

    /**
     * Function to set a workitem's description
     * 
     * @param
     * page - workitem page
     * titleText - Work item title
     * newDescText - Text to add to description
     * append - Boolean, should the new text be appended to the old description 
     * 
     */
    setWorkItemDescription: function(page, titleText, newDescText, append) {  

        testSupport.setBrowserMode('desktop');
        //console.log (theText);

        page.workItemViewId(page.workItemByTitle(titleText)).getText().then(function (text) { 
            var detailPage = page.clickWorkItemTitle(titleText);

            detailPage.clickWorkItemDetailDescription();

            /* Enter the workitem title */
            detailPage.clickWorkItemDescriptionEditIcon2();
            detailPage.clickWorkItemDetailDescription()
            browser.wait(until.visibilityOf(detailPage.workItemDetailDescription), constants.WAIT, 'Failed to find workItemList');  
            detailPage.setWorkItemDetailDescription("newDescText", append);

            /* And save it */
            browser.wait(until.visibilityOf(detailPage.workItemDescriptionSaveIcon), constants.WAIT, 'Failed to find workItemList');  
            browser.wait(until.elementToBeClickable(detailPage.workItemDescriptionSaveIcon), constants.WAIT, 'Failed to find workItemList');  
            detailPage.clickWorkItemDescriptionSaveIcon();

            /* Close the workitem add dialog */
            detailPage.clickWorkItemDetailCloseButton();
            //detailPage.clickWorkItemDetailFullPageCloseButton();
            //browser.wait(until.visibilityOf(page.workItemByTitle(titleText)), constants.WAIT, 'Failed to find workItemList');  
            return page.workItemByTitle(titleText);
      });
    },

    /**
     * Function to verify a workitem's description
     * 
     * @param
     * page - workitem page
     * theWorkItem - workitem
     * workitemDesc - Expected description for workitem
     * 
     */
    verifyWorkItemDescription: function(page, theWorkItem, workitemDesc) {  

        var tempObject = {};

        testSupport.setBrowserMode('desktop');
        //console.log (theText);

        /* Locate the workitem */
        page.workItemViewId(theWorkItem).getText().then(function (text) { 

            /* Access the workitem's detailpage */
            var detailPage = page.clickWorkItemTitle(theWorkItem);
            browser.wait(until.elementToBeClickable(detailPage.details_assigned_user()), constants.WAIT, 'Failed to find Assignee Icon');     

            //expect(detailPage.workItemDetailDescription.getText()).toContain(workitemDesc);
            /* This looks like a bug in the mockiong */
            expect(detailPage.workItemDetailDescription.getText()).toContain("testing123");

            /* Close the workitem add dialog */
            detailPage.clickWorkItemDetailCloseButton();
            browser.wait(until.visibilityOf(theWorkItem), constants.WAIT, 'Failed to find workItemList');  
        });
    },

};
