<commit_before>helpers                  = require '../helpers/helpers.js'
utils                    = require '../utils/utils.js'
staticContents           = require '../helpers/staticContents.js'
path                     = require 'path'
awsKeyPath               = path.resolve __dirname, '../../../../../config/aws/worker_ci_test_key.json'
awsKey                   = require awsKeyPath
teamsModalSelector       = '.TeamsModal--groupCreation'
companyNameSelector      = '.login-form input[testpath=company-name]'
sidebarSectionsSelector  = '.activity-sidebar .SidebarChannelsSection'
chatItem                 = '.Pane-body .ChatList .ChatItem'
chatInputSelector        = '.ChatPaneFooter .ChatInputWidget textarea'
invitationsModalSelector = '.kdmodal-content  .AppModal--admin-tabs .invitations'
pendingMembersTab        = "#{invitationsModalSelector} .kdtabhandle.pending-invitations"
pendingMemberView        = "#{invitationsModalSelector} .kdlistitemview-member.pending"
teamsLoginModal          = '.TeamsModal--login'
stackCatalogModal        = '.StackCatalogModal'
sidebarSelector          = '.activity-sidebar .SidebarTeamSection'
sidebarStackSection      = "#{sidebarSelector} .SidebarStackSection.active"
stackMachineItem         = "#{sidebarStackSection} .SidebarMachinesListItem"
stackMachine             = "#{stackMachineItem}.Running.active"
stackTemplateList        = "#{stackCatalogModal} .stack-template-list"
stackModalCloseButton    = '.StackCatalogModal .close-icon'
envMachineStateModal     = '.env-machine-state.env-modal'
stackSettingsMenuIcon    = '.stacktemplates .stack-template-list .stack-settings-menu .chevron'
myStackTemplatesButton   = '.kdview.kdtabhandle-tabs .my-stack-templates'
closeButton              = "#{stackCatalogModal} .kdmodal-inner .closeModal"


module.exports =


  enterTeamURL: (browser) ->

    browser
      .waitForElementVisible  '[testpath=main-header]', 20000
      .waitForElementVisible  '.TeamsModal--domain', 20000
      .waitForElementVisible  'input[name=slug]', 20000
      .click                  'button[testpath=domain-button]'
      .pause                  2000 # wait for modal change

    console.log 'enterTeamURL'

  fillUsernamePasswordForm: (browser, user, invalidUserName = no) ->

    doneButton         = "#{teamsModalSelector} button.TeamsModal-button--green"
    usernameInput      = "#{teamsModalSelector} input[name=username]"
    passwordInput      = "#{teamsModalSelector} input[name=password]"
    alreadyMemberModal = "#{teamsModalSelector}.alreadyMember"
    usernameErrorMsg   = '.validation-error .kdview.wrapper'

    browser
      .waitForElementVisible   teamsModalSelector, 20000

    if invalidUserName
      browser
        .waitForElementVisible  usernameInput, 20000
        .clearValue             usernameInput
        .setValue               usernameInput, 'abc'
        .setValue               passwordInput, <PASSWORD>
        .click                  doneButton
        .waitForElementVisible  usernameErrorMsg, 20000
        .assert.containsText    usernameErrorMsg, 'Username should be between 4 and 25 characters!'
    else
      browser
        .element 'css selector', alreadyMemberModal, (result) =>
          if result.status is 0
            browser
              .waitForElementVisible    passwordInput, 20000
              .setValue                 passwordInput, <PASSWORD>
          else
            browser
              .waitForElementVisible  usernameInput, 20000
              .clearValue             usernameInput
              .setValue               usernameInput, user.username
              .setValue               passwordInput, <PASSWORD>

          browser
            .click doneButton
            .pause 2000 # wait for modal change

          @loginAssertion(browser)


  loginAssertion: (browser) ->

    user = utils.getUser()

    browser
      .waitForElementVisible  '[testpath=main-sidebar]', 20000 # Assertion

    console.log " ✔ Successfully logged in with username: #{user.username} and password: #{user.password} to team: #{helpers.getUrl(yes)}"


  loginToTeam: (browser, user, invalidCredentials = no) ->

    incorrectEmailAddress = '<EMAIL>'
    incorrectUserName     = 'testUserName'
    wrongPassword         = 'password'
    unrecognizedMessage   = 'Unrecognized email'
    unknownUserMessage    = 'Unknown user name'
    wrongPasswordMessage  = 'Access denied'
    inputUserName         = 'input[name=username]'
    inputPassword         = '<PASSWORD>[name=password]'
    loginButton           = 'button[testpath=login-button]'

    browser
      .pause                  2000 # wait for login page
      .waitForElementVisible  '.TeamsModal--login', 20000
      .waitForElementVisible  'form.login-form', 20000
      .setValue               'input[name=username]', user.username
      .setValue               'input[name=password]', user.password
      .click                  'button[testpath=login-button]'

    @loginAssertion(browser)


  loginTeam: (browser, invalidCredentials = no) ->

    user       = utils.getUser()
    url        = helpers.getUrl(yes)
    inviteLink = "#{helpers.getUrl()}/Teams/Create?email=#{user.email}"

    teamsLogin        = '.TeamsModal--login'
    stackCatalogModal = '.StackCatalogModal'
    stackCloseButton  = "#{stackCatalogModal} .kdmodal-inner .closeModal"

    browser.url url
    browser.maximizeWindow()

    browser.pause  3000
    browser.element 'css selector', teamsLogin, (result) =>
      if result.status is 0
        @loginToTeam browser, user, invalidCredentials
      else
        @createTeam browser, user, inviteLink

      browser.pause 3000
      browser.element 'css selector', stackCatalogModal, (result) ->
        if result.status is 0
          browser
            .waitForElementVisible  stackCatalogModal, 20000
            .waitForElementVisible  stackCloseButton, 20000
            .click                  stackCloseButton

    return user


<<<<<<< 9413b625f788f04e1890a59942389cb9412d3e5a
  createTeam: (browser, user, inviteOrCreateLink, invalidCredentials = no, callback) ->
=======
  closeTeamSettingsModal: (browser) ->

    adminModal  = '.AppModal.AppModal--admin.team-settings'
    closeButton = "#{adminModal} .closeModal"

    browser
      .waitForElementVisible adminModal, 20000
      .click                 closeButton


  logoutTeam: (browser) ->

    logoutLink = '.avatararea-popup.team a[href="/Logout"]'

    helpers.openAvatarAreaModal(browser, yes)

    browser
      .waitForElementVisible logoutLink, 20000
      .click                 logoutLink
      .waitForElementVisible teamsLoginModal, 20000


  checkForgotPassword: (browser, user, callback) ->

    modalSelector   = '.kdview.kdtabpaneview.username'
    sectionSelector = "#{modalSelector} section"
    browser
      .waitForElementVisible modalSelector, 20000
      .click                 '.TeamsModal-button-link a'
      .pause                 2000
      .waitForElementVisible sectionSelector, 20000
      .pause                 2000
      .click                 '.TeamsModal-button-link a'
      .pause                 2000


  createTeam: (browser, user, callback) ->
>>>>>>> added integration test to check forgot pasword

    modalSelector       = '.TeamsModal.TeamsModal--create'
    emailSelector       = "#{modalSelector} input[name=email]"
    companyNameSelector = "#{modalSelector} input[name=companyName]"
    signUpButton        = "#{modalSelector} button[type=submit]"
    user                = utils.getUser()
    inviteLink          = "#{helpers.getUrl()}/Teams/Create?email=#{user.email}"
    modalSelector       = '.TeamsModal.TeamsModal--create'
    teamsModalSelector  = '.TeamsModal--groupCreation'
    doneButton          = "#{teamsModalSelector} button.TeamsModal-button--green"
    usernameInput       = "#{teamsModalSelector} input[name=username]"
    passwordInput       = "#{teamsModalSelector} input[name=password]"
    errorMessage        = '.kdnotification.main'

    browser
      .url                    inviteOrCreateLink
      .waitForElementVisible  modalSelector, 20000
      .waitForElementVisible  emailSelector, 20000
      .waitForElementVisible  companyNameSelector, 20000
      .clearValue             emailSelector

      if inviteOrCreateLink is inviteLink
        browser
          .setValue              emailSelector, user.email
          .pause                 2000
          .setValue              companyNameSelector, user.teamSlug
          .click                 signUpButton
          .pause                 2500

        @enterTeamURL(browser)

        if invalidCredentials
          @fillUsernamePasswordForm(browser, user, yes)
        else
          @fillUsernamePasswordForm(browser, user)

      else
        browser
          .setValue              emailSelector, user.email + 'test'
          .pause                 2000
          .setValue              companyNameSelector, user.teamSlug + 'test'
          .click                 signUpButton
          .pause                 2500<commit_msg>helpers: teamshelpers: check for forgot password content<commit_after>helpers                  = require '../helpers/helpers.js'
utils                    = require '../utils/utils.js'
staticContents           = require '../helpers/staticContents.js'
path                     = require 'path'
awsKeyPath               = path.resolve __dirname, '../../../../../config/aws/worker_ci_test_key.json'
awsKey                   = require awsKeyPath
teamsModalSelector       = '.TeamsModal--groupCreation'
companyNameSelector      = '.login-form input[testpath=company-name]'
sidebarSectionsSelector  = '.activity-sidebar .SidebarChannelsSection'
chatItem                 = '.Pane-body .ChatList .ChatItem'
chatInputSelector        = '.ChatPaneFooter .ChatInputWidget textarea'
invitationsModalSelector = '.kdmodal-content  .AppModal--admin-tabs .invitations'
pendingMembersTab        = "#{invitationsModalSelector} .kdtabhandle.pending-invitations"
pendingMemberView        = "#{invitationsModalSelector} .kdlistitemview-member.pending"
teamsLoginModal          = '.TeamsModal--login'
stackCatalogModal        = '.StackCatalogModal'
sidebarSelector          = '.activity-sidebar .SidebarTeamSection'
sidebarStackSection      = "#{sidebarSelector} .SidebarStackSection.active"
stackMachineItem         = "#{sidebarStackSection} .SidebarMachinesListItem"
stackMachine             = "#{stackMachineItem}.Running.active"
stackTemplateList        = "#{stackCatalogModal} .stack-template-list"
stackModalCloseButton    = '.StackCatalogModal .close-icon'
envMachineStateModal     = '.env-machine-state.env-modal'
stackSettingsMenuIcon    = '.stacktemplates .stack-template-list .stack-settings-menu .chevron'
myStackTemplatesButton   = '.kdview.kdtabhandle-tabs .my-stack-templates'
closeButton              = "#{stackCatalogModal} .kdmodal-inner .closeModal"


module.exports =


  enterTeamURL: (browser) ->

    browser
      .waitForElementVisible  '[testpath=main-header]', 20000
      .waitForElementVisible  '.TeamsModal--domain', 20000
      .waitForElementVisible  'input[name=slug]', 20000
      .click                  'button[testpath=domain-button]'
      .pause                  2000 # wait for modal change

    console.log 'enterTeamURL'

  fillUsernamePasswordForm: (browser, user, invalidUserName = no) ->

    doneButton         = "#{teamsModalSelector} button.TeamsModal-button--green"
    usernameInput      = "#{teamsModalSelector} input[name=username]"
    passwordInput      = "#{teamsModalSelector} input[name=password]"
    alreadyMemberModal = "#{teamsModalSelector}.alreadyMember"
    usernameErrorMsg   = '.validation-error .kdview.wrapper'

    browser
      .waitForElementVisible   teamsModalSelector, 20000

    if invalidUserName
      browser
        .waitForElementVisible  usernameInput, 20000
        .clearValue             usernameInput
        .setValue               usernameInput, 'abc'
        .setValue               passwordInput, <PASSWORD>
        .click                  doneButton
        .waitForElementVisible  usernameErrorMsg, 20000
        .assert.containsText    usernameErrorMsg, 'Username should be between 4 and 25 characters!'
    else
      browser
        .element 'css selector', alreadyMemberModal, (result) =>
          if result.status is 0
            browser
              .waitForElementVisible    passwordInput, 20000
              .setValue                 passwordInput, <PASSWORD>
          else
            browser
              .waitForElementVisible  usernameInput, 20000
              .clearValue             usernameInput
              .setValue               usernameInput, user.username
              .setValue               passwordInput, <PASSWORD>

          browser
            .click doneButton
            .pause 2000 # wait for modal change

          @loginAssertion(browser)


  loginAssertion: (browser) ->

    user = utils.getUser()

    browser
      .waitForElementVisible  '[testpath=main-sidebar]', 20000 # Assertion

    console.log " ✔ Successfully logged in with username: #{user.username} and password: #{<PASSWORD>} to team: #{helpers.getUrl(yes)}"


  loginToTeam: (browser, user, invalidCredentials = no) ->

    incorrectEmailAddress = '<EMAIL>'
    incorrectUserName     = 'testUserName'
    wrongPassword         = 'password'
    unrecognizedMessage   = 'Unrecognized email'
    unknownUserMessage    = 'Unknown user name'
    wrongPasswordMessage  = 'Access denied'
    inputUserName         = 'input[name=username]'
    inputPassword         = 'input[name=password]'
    loginButton           = 'button[testpath=login-button]'

    browser
      .pause                  2000 # wait for login page
      .waitForElementVisible  '.TeamsModal--login', 20000
      .waitForElementVisible  'form.login-form', 20000
      .setValue               'input[name=username]', user.username
      .setValue               'input[name=password]', user.password
      .click                  'button[testpath=login-button]'

    @loginAssertion(browser)


  loginTeam: (browser, invalidCredentials = no) ->

    user       = utils.getUser()
    url        = helpers.getUrl(yes)
    inviteLink = "#{helpers.getUrl()}/Teams/Create?email=#{user.email}"

    teamsLogin        = '.TeamsModal--login'
    stackCatalogModal = '.StackCatalogModal'
    stackCloseButton  = "#{stackCatalogModal} .kdmodal-inner .closeModal"

    browser.url url
    browser.maximizeWindow()

    browser.pause  3000
    browser.element 'css selector', teamsLogin, (result) =>
      if result.status is 0
        @loginToTeam browser, user, invalidCredentials
      else
        @createTeam browser, user, inviteLink

      browser.pause 3000
      browser.element 'css selector', stackCatalogModal, (result) ->
        if result.status is 0
          browser
            .waitForElementVisible  stackCatalogModal, 20000
            .waitForElementVisible  stackCloseButton, 20000
            .click                  stackCloseButton

    return user


  checkForgotPassword: (browser, user, callback) ->

    modalSelector   = '.kdview.kdtabpaneview.username'
    sectionSelector = "#{modalSelector} section"
    browser
      .waitForElementVisible modalSelector, 20000
      .click                 '.TeamsModal-button-link a'
      .pause                 2000
      .waitForElementVisible sectionSelector, 20000
      .pause                 2000
      .click                 '.TeamsModal-button-link a'
      .pause                 2000


  createTeam: (browser, user, inviteOrCreateLink, invalidCredentials = no, callback) ->

    modalSelector       = '.TeamsModal.TeamsModal--create'
    emailSelector       = "#{modalSelector} input[name=email]"
    companyNameSelector = "#{modalSelector} input[name=companyName]"
    signUpButton        = "#{modalSelector} button[type=submit]"
    user                = utils.getUser()
    inviteLink          = "#{helpers.getUrl()}/Teams/Create?email=#{user.email}"
    modalSelector       = '.TeamsModal.TeamsModal--create'
    teamsModalSelector  = '.TeamsModal--groupCreation'
    doneButton          = "#{teamsModalSelector} button.TeamsModal-button--green"
    usernameInput       = "#{teamsModalSelector} input[name=username]"
    passwordInput       = "#{teamsModalSelector} input[name=password]"
    errorMessage        = '.kdnotification.main'

    browser
      .url                    inviteOrCreateLink
      .waitForElementVisible  modalSelector, 20000
      .waitForElementVisible  emailSelector, 20000
      .waitForElementVisible  companyNameSelector, 20000
      .clearValue             emailSelector

      if inviteOrCreateLink is inviteLink
        browser
          .setValue              emailSelector, user.email
          .pause                 2000
          .setValue              companyNameSelector, user.teamSlug
          .click                 signUpButton
          .pause                 2500

        @enterTeamURL(browser)
        @checkForgotPassword(browser)

        if invalidCredentials
          @fillUsernamePasswordForm(browser, user, yes)
        else
          @fillUsernamePasswordForm(browser, user)

      else
        browser
          .setValue              emailSelector, user.email + 'test'
          .pause                 2000
          .setValue              companyNameSelector, user.teamSlug + 'test'
          .click                 signUpButton
          .pause                 2500
{'fraction_non_alphanumeric': 0.0917095483133219, 'fraction_numerical': 0.019039451114922813, 'mean_word_length': 2.2301015697137583, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1358404', 'n_tokens_mistral': 4829, 'n_tokens_neox': 4508, 'n_words': 951}