<commit_before>describe 'Invitations', ->

  threadHelper = require './helpers/thread_helper.coffee'
  emailHelper = require './helpers/email_helper.coffee'
  invitationsHelper = require './helpers/invitations_helper.coffee'
  groupsHelper = require './helpers/groups_helper.coffee'

  describe 'basics', ->
    it 'successfully opens a modal', ->
      threadHelper.load()
      invitationsHelper.openInvitationsModal()
      expect(invitationsHelper.groupDropdown().isPresent()).toBe(true)

    it 'successfully opens a model for a specific group', ->
      groupsHelper.load()
      invitationsHelper.openInvitationsModal()
      expect(invitationsHelper.groupDropdown().getText()).toContain('Dirty')
      expect(invitationsHelper.invitableInput().isPresent()).toBe(true)

  describe 'inviting a Loomio user', ->
    beforeEach ->
      invitationsHelper.load()

    describe 'by name', ->
      beforeEach ->
        invitationsHelper.openInvitationsModal()
        invitationsHelper.invite('max')
        invitationsHelper.submitInvitationsForm()

      it 'successfully invites the user', ->
        expect(groupsHelper.membersList().getText()).toContain('MVS')

      it 'displays the correct flash message', ->
        expect(groupsHelper.flashSection().getText()).toContain('1 member(s) added')

    describe 'by username', ->
      beforeEach ->
        invitationsHelper.openInvitationsModal()
        invitationsHelper.invite('ming')
        invitationsHelper.submitInvitationsForm()

      it 'successfully invites the user', ->
        expect(groupsHelper.membersList().getText()).toContain('MVS')

      it 'displays the correct flash message', ->
        expect(groupsHelper.flashSection().getText()).toContain('1 member(s) added')

    # describe 'inviting a group', ->
    #   beforeEach ->
    #     invitationsHelper.openInvitationsModal()
    #     invitationsHelper.invite('Point')
    #     invitationsHelper.submitInvitationsForm()

    #   it 'successfuly invites the group', ->
    #     expect(groupsHelper.flashSection().getText()).toContain('1 member(s) added')
    #     expect(groupsHelper.membersList().getText()).toContain('MVS')

    #   it 'displays the correct flash message', ->
    #     expect(groupsHelper.flashSection().getText()).toContain('1 member(s) added')

    describe 'by email address', ->
      beforeEach ->
        invitationsHelper.openInvitationsModal()
        invitationsHelper.invite('<EMAIL>')
        invitationsHelper.submitInvitationsForm()

      it 'successfully invites the user', ->
        expect(groupsHelper.membersList().getText()).toContain('MVS')

      it 'displays the correct flash message', ->
        expect(groupsHelper.flashSection().getText()).toContain('1 member(s) added')

  describe 'inviting a non-user', ->
    beforeEach ->
      invitationsHelper.load()

    describe 'by email address', ->
      beforeEach ->
        invitationsHelper.openInvitationsModal()
        invitationsHelper.invite('<EMAIL>')
        invitationsHelper.submitInvitationsForm()

      it 'successfully invites someone', ->
        emailHelper.openLastEmail()
        expect(emailHelper.lastEmailSubject().getText()).toContain('<NAME> has invited you to join Dirty Dancing Shoes on Loomio')

      it 'displays the correct flash message', ->
        expect(groupsHelper.flashSection().getText()).toContain('1 invitation(s) sent')

    describe 'inviting a contact', ->
      beforeEach ->
        invitationsHelper.openInvitationsModal()
        invitationsHelper.invite('keanu')
        invitationsHelper.submitInvitationsForm()

      it 'successfully invites a contact', ->
        emailHelper.openLastEmail()
        expect(emailHelper.lastEmailSubject().getText()).toContain('Dirty Dancing Shoes')

      it 'displays the correct flash message', ->
        expect(groupsHelper.flashSection().getText()).toContain('1 invitation(s) sent')

  describe 'inviting both users and non-user', ->
    beforeEach ->
      invitationsHelper.load()

    it 'successfully invites a contact', ->
      invitationsHelper.openInvitationsModal()
      invitationsHelper.invite('ming')
      invitationsHelper.invite('keanu')
      invitationsHelper.invite('<EMAIL>')
      invitationsHelper.submitInvitationsForm()
      expect(groupsHelper.flashSection().getText()).toContain('1 member(s) added and 2 invitation(s) sent')<commit_msg>Update tests to fix failing invitations spec<commit_after>describe 'Invitations', ->

  threadHelper = require './helpers/thread_helper.coffee'
  emailHelper = require './helpers/email_helper.coffee'
  invitationsHelper = require './helpers/invitations_helper.coffee'
  groupsHelper = require './helpers/groups_helper.coffee'

  describe 'basics', ->
    it 'successfully opens a modal', ->
      threadHelper.load()
      invitationsHelper.openInvitationsModal()
      expect(invitationsHelper.groupDropdown().isPresent()).toBe(true)

    it 'successfully opens a model for a specific group', ->
      groupsHelper.load()
      invitationsHelper.openInvitationsModal()
      expect(invitationsHelper.groupDropdown().getText()).toContain('Dirty')
      expect(invitationsHelper.invitableInput().isPresent()).toBe(true)

  describe 'inviting a Loomio user', ->
    beforeEach ->
      invitationsHelper.load()

    describe 'by name', ->
      beforeEach ->
        invitationsHelper.openInvitationsModal()
        invitationsHelper.invite('max')
        invitationsHelper.submitInvitationsForm()

      it 'successfully invites the user', ->
        expect(groupsHelper.membersList().getText()).toContain('MVS')

      it 'displays the correct flash message', ->
        expect(groupsHelper.flashSection().getText()).toContain('1 member(s) added')

    describe 'by username', ->
      beforeEach ->
        invitationsHelper.openInvitationsModal()
        invitationsHelper.invite('ming')
        invitationsHelper.submitInvitationsForm()

      it 'successfully invites the user', ->
        expect(groupsHelper.membersList().getText()).toContain('MVS')

      it 'displays the correct flash message', ->
        expect(groupsHelper.flashSection().getText()).toContain('1 member(s) added')

    # describe 'inviting a group', ->
    #   beforeEach ->
    #     invitationsHelper.openInvitationsModal()
    #     invitationsHelper.invite('Point')
    #     invitationsHelper.submitInvitationsForm()

    #   it 'successfuly invites the group', ->
    #     expect(groupsHelper.flashSection().getText()).toContain('1 member(s) added')
    #     expect(groupsHelper.membersList().getText()).toContain('MVS')

    #   it 'displays the correct flash message', ->
    #     expect(groupsHelper.flashSection().getText()).toContain('1 member(s) added')

    describe 'by email address', ->
      beforeEach ->
        invitationsHelper.openInvitationsModal()
        invitationsHelper.invite('<EMAIL>')
        invitationsHelper.submitInvitationsForm()

      it 'successfully invites the user', ->
        expect(groupsHelper.membersList().getText()).toContain('MVS')

      it 'displays the correct flash message', ->
        expect(groupsHelper.flashSection().getText()).toContain('1 member(s) added')

  describe 'inviting a non-user', ->
    beforeEach ->
      invitationsHelper.load()

    describe 'by email address', ->
      beforeEach ->
        invitationsHelper.openInvitationsModal()
        invitationsHelper.invite('<EMAIL>')
        invitationsHelper.submitInvitationsForm()

      it 'successfully invites someone', ->
        emailHelper.openLastEmail()
        expect(emailHelper.lastEmailSubject().getText()).toContain('<NAME> has invited you to join Dirty Dancing Shoes on Loomio')

      it 'displays the correct flash message', ->
        expect(groupsHelper.flashSection().getText()).toContain('1 invitation(s) sent')

    describe 'inviting a contact', ->
      beforeEach ->
        invitationsHelper.openInvitationsModal()
        invitationsHelper.invite('keanu')
        invitationsHelper.submitInvitationsForm()

      it 'successfully invites a contact', ->
        emailHelper.openLastEmail()
        expect(emailHelper.lastEmailSubject().getText()).toContain('Dirty Dancing Shoes')

      it 'displays the correct flash message', ->
        expect(groupsHelper.flashSection().getText()).toContain('1 invitation(s) sent')

  describe 'inviting both users and non-user', ->
    beforeEach ->
      invitationsHelper.load()

    it 'successfully adds users and invites non-users', ->
      invitationsHelper.openInvitationsModal()
      invitationsHelper.invite('ming')
      invitationsHelper.invite('keanu')
      invitationsHelper.invite('<EMAIL>')
      invitationsHelper.submitInvitationsForm()
      expect(groupsHelper.flashSection().getText()).toContain('1 member(s) added and 2 invitation(s) sent')
{'fraction_non_alphanumeric': 0.1244046268995237, 'fraction_numerical': 0.0020412792016330232, 'mean_word_length': 3.5318602261048304, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 81, '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': '399016', 'n_tokens_mistral': 2392, 'n_tokens_neox': 2307, 'n_words': 461}