 module.exports =
 
 
-  openTeamsPage: (browser) ->
-
-    teamsSelector = '[testpath=main-header] .full-menu a.teams'
-
-    browser
-      .waitForElementVisible  '[testpath=main-header]', 20000
-      .waitForElementVisible  teamsSelector, 20000
-      .click                  teamsSelector
-      .waitForElementVisible  '.content-page.teams', 20000
-
-
-  fillSignUpFormOnTeamsHomePage: (browser, user) ->
-
-    emailSelector  = '.login-form input[testpath=register-form-email]'
-    buttonSelector = 'button[testpath=signup-company-button]'
-
-    browser
-      .waitForElementVisible  emailSelector, 20000
-      .setValue               emailSelector, user.email
-      .waitForElementVisible  companyNameSelector, 20000
-      .setValue               companyNameSelector, user.name
-      .waitForElementVisible  buttonSelector, 20000
-      .click                  buttonSelector
-      .pause                  2000 # wait for modal change
-
-
   enterTeamURL: (browser) ->
 
     browser

        .click                  sidebarSectionsHeaderSelector


  createChannel: (browser, user, channelName, isInvalid, purpose) ->

    channelModalSelector             = '.CreateChannel-Modal .CreateChannel-content'
    createChannelModalNameSelector   = "#{channelModalSelector} .channelName input"
    purposeSelector                  = "#{channelModalSelector} .channelPurpose input"
    createChannelModalButtonSelector = '.CreateChannel-Modal .Modal-buttons .Button--danger'
    channelName                    or= helpers.getFakeText().split(' ')[0] + Date.now()
    channelName                      = channelName.substring(0, 19)
    channelLinkOnSidebarSelector     = "#{sidebarSectionsSelector} a[href='/Channels/#{channelName}']"

    @moveToSidebarHeader(browser, yes)

    browser
      .waitForElementVisible  '.CreateChannel-Modal', 20000
      .waitForElementVisible  createChannelModalNameSelector, 20000
      .setValue               createChannelModalNameSelector, channelName

    if purpose
      browser
        .waitForElementVisible  purposeSelector, 20000
        .setValue               purposeSelector, purpose

    browser
      .waitForElementVisible  createChannelModalButtonSelector, 20000
      .moveToElement          createChannelModalButtonSelector, 32, 12
      .click                  createChannelModalButtonSelector

    if isInvalid
      browser
        .waitForElementVisible  '.channelName.invalid', 20000
        .pause                   2000
        .waitForElementVisible  '.CreateChannel-Modal', 20000
    else
      browser
        .pause                  3000 # wait for page load
        .waitForElementVisible  chatItem, 20000
        .pause                  3000
        .assert.containsText    chatItem, user.username
        .waitForElementVisible  sidebarSectionsSelector, 20000
        .pause                  2000 # wait for side bar channel list
        .waitForElementVisible  channelLinkOnSidebarSelector, 20000
        .assert.containsText    sidebarSectionsSelector, channelName

    if purpose
      browser.assert.containsText '.ChannelThreadPane-purposeWrapper .ChannelThreadPane-purpose', purpose

    return channelName


  sendComment: (browser, message, messageType) ->

    chatInputSelector     = '.ChatPaneFooter .ChatInputWidget textarea'
    imageSelector         = '.EmbedBox-container .EmbedBoxImage'
    imageTextSelector     = '.Pane-body .ChatList .ChatItem .ChatItem-contentBody:nth-of-type(1)'
    linkTextSelector      = '.EmbedBoxLinkContent .EmbedBoxLinkContent-description'
    emojiSelector         = '.ChatList .ChatItem .SimpleChatListItem .ChatListItem-itemBodyContainer .ChatItem-contentBody '
    blockSelector         = '.Pane-body .ChatList .ChatItem .ChatListItem-itemBodyContainer .ChatItem-contentBody .MessageBody blockquote'
    emojiSmileySelector   = "#{emojiSelector} .emoji-smiley"
    emojiThumbsUpSelector = "#{emojiSelector} .emoji-thumbsup"
    messageWithShortCode  = "console.log('123456789')"
    textAreaSelector      = '.Pane-body .ChatList'

    browser
      .waitForElementVisible  chatItem, 20000
      .waitForElementVisible  chatInputSelector, 20000
      .setValue               chatInputSelector, message + '\n'
      .waitForElementVisible  chatItem, 20000

    if not messageType
      browser
        .assert.containsText      textAreaSelector, message

    switch messageType
      when 'messageWithCode'
        browser
          .pause                  3000
          .assert.containsText    "#{textAreaSelector} .ChatItem .SimpleChatListItem", messageWithShortCode
      when 'messageWithImage'
        browser
          .waitForElementVisible  imageSelector, 20000
          .assert.containsText    imageTextSelector, message
      when 'messageWithLink'
        browser
          .waitForElementVisible  linkTextSelector, 20000
          .assert.containsText    linkTextSelector, 'The Free Encyclopedia'
      when 'messageWithEmoji'
        browser
          .waitForElementVisible  emojiSmileySelector, 20000
          .waitForElementVisible  emojiSmileySelector, 20000
          .pause                  2000
          .waitForElementVisible  emojiThumbsUpSelector, 20000
      when 'messageWithBlockquote'
        browser
          .pause                  3000
          .waitForElementVisible  blockSelector, 20000
          .assert.containsText    blockSelector, 'Message with blockquote'


  createChannelsAndCheckList: (browser, user) ->

    channelHeader     = "#{sidebarSectionsSelector} .SidebarSection-header"
    channelListModal  = '.ChannelList-Modal'
    activeTabSelector = "#{channelListModal} .ChannelList-tab.active-tab"
    listItemSelector  = "#{channelListModal} .ChannelListItem"
    threadsContainer  = "#{channelListModal} .SidebarModalThreads"

    channelName1 = @createChannel(browser, user)
    channelName2 = @createChannel(browser, user)
    channelName3 = @createChannel(browser, user)

    browser
      .waitForElementVisible  sidebarSectionsSelector, 20000
      .waitForElementVisible  channelHeader, 20000
      .click                  channelHeader
      .waitForElementVisible  channelListModal, 20000
      .waitForElementVisible  activeTabSelector, 20000
      .assert.containsText    activeTabSelector, 'Your Channels'
      .waitForElementVisible  listItemSelector, 20000
      .assert.containsText    threadsContainer, channelName1
      .assert.containsText    threadsContainer, channelName2
      .assert.containsText    threadsContainer, channelName3

    return [ channelName1, channelName2, channelName3 ]


  leaveChannel: (browser) ->

    channelHeaderPaneSelector = '.ChannelThreadPane-content .ChannelThreadPane-header'
    buttonSelector            = "#{channelHeaderPaneSelector} .ButtonWithMenuWrapper"
    channelActionsSelector    = '.ButtonWithMenuItemsList.ChannelThreadPane-menuItems'
    leaveChannelSelector      = "#{channelActionsSelector} li:nth-child(2)"
    followChannelBox          = '.ChannelThreadPane-body .FollowChannelBox'

    browser
      .waitForElementVisible     channelHeaderPaneSelector, 20000
      .waitForElementVisible     buttonSelector, 20000
      .click                     buttonSelector
      .waitForElementVisible     channelActionsSelector, 20000
      .moveToElement             leaveChannelSelector, 70, 12
      .waitForElementVisible     leaveChannelSelector, 20000
      .click                     leaveChannelSelector
      .waitForElementVisible     followChannelBox, 20000 # Assertion
      .waitForElementNotVisible  chatInputSelector, 20000 # Assertion


  joinChannel: (browser) ->

    followChannelBox    = '.FollowChannelBox'
    followChannelButton = "#{followChannelBox} .Button-followChannel"

    @leaveChannel(browser)

    browser
      .waitForElementVisible     followChannelButton, 20000
      .click                     followChannelButton
      .waitForElementNotVisible  followChannelButton, 20000


  inviteUser: (browser, addMoreUser = no) ->

    invitationsModalSelector = '.kdmodal-content  .AppModal--admin-tabs .invitations'

      .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) ->
