<commit_before>describe "FacebookFriend ", ->

  beforeEach ->
    window.HandlebarsTemplates = {}
    window.HandlebarsTemplates['facebook_share_widget/templates/friend'] = (f) ->
    setFixtures('<div id="sandbox"><div class="loader tick"><img src=""/></div></div>')
    window.FB = {};
    window.FB.ui = ->
    window.FB.init = ->
    
  it "should share message to friend", ->

    facebookFriend = new app.models.FacebookFriend
    facebookFriendView = new app.views.FacebookFriendView(model: facebookFriend, el: $('#sandbox'))
    facebookFriendView.render()

    $('.share-button').click()

    expect(facebookFriend.isShared()).toBe(true)

  it "should share message with default callback from window.facebookShareWidget", ->
    @success_callback = (friend) ->
    spyOn(this, 'success_callback')

    window.facebookShareWidget.callbacks.success = @success_callback

    facebookFriend = new app.models.FacebookFriend
    facebookFriendView = new app.views.FacebookFriendView(model: facebookFriend, el: $('#sandbox'))
    facebookFriendView.render()

    $('.share-button').click()

    expect(@success_callback).toHaveBeenCalledWith(facebookFriend);

  it "should share message with callback", ->
    @success_callback = (friend) ->
    spyOn(this, 'success_callback')

    facebookFriend = new app.models.FacebookFriend success_callback: @success_callback
    facebookFriendView = new app.views.FacebookFriendView(model: facebookFriend, el: $('#sandbox'))
    facebookFriendView.render()

    $('.share-button').click()

    expect(@success_callback).toHaveBeenCalledWith(facebookFriend);

  it "should call FB.ui function with redirect_uri and proper data", ->
    window.FB.ui = (data) ->
      expect(data.method).toEqual('feed')
      expect(data.to).toEqual(123)
      expect(data.redirect_uri).toEqual('http://localhost:8888/widget/facebook/share-redirect?facebook_id=123&link=test')

    facebookFriend = new app.models.FacebookFriend(id: 123)
    facebookFriendView = new app.views.FacebookFriendView(model: facebookFriend, el: $('#sandbox'))
    spyOn(facebookFriendView,'sharingTemplate').andCallFake ->
      '{"link":"test"}'
    facebookFriendView.render()<commit_msg>Rohit fixed a spec for running on CI<commit_after>describe "FacebookFriend ", ->

  beforeEach ->
    window.HandlebarsTemplates = {}
    window.HandlebarsTemplates['facebook_share_widget/templates/friend'] = (f) ->
    setFixtures('<div id="sandbox"><div class="loader tick"><img src=""/></div></div>')
    window.FB = {};
    window.FB.ui = ->
    window.FB.init = ->
    
  it "should share message to friend", ->

    facebookFriend = new app.models.FacebookFriend
    facebookFriendView = new app.views.FacebookFriendView(model: facebookFriend, el: $('#sandbox'))
    facebookFriendView.render()

    $('.share-button').click()

    expect(facebookFriend.isShared()).toBe(true)

  it "should share message with default callback from window.facebookShareWidget", ->
    @success_callback = (friend) ->
    spyOn(this, 'success_callback')

    window.facebookShareWidget.callbacks.success = @success_callback

    facebookFriend = new app.models.FacebookFriend
    facebookFriendView = new app.views.FacebookFriendView(model: facebookFriend, el: $('#sandbox'))
    facebookFriendView.render()

    $('.share-button').click()

    expect(@success_callback).toHaveBeenCalledWith(facebookFriend);

  it "should share message with callback", ->
    @success_callback = (friend) ->
    spyOn(this, 'success_callback')

    facebookFriend = new app.models.FacebookFriend success_callback: @success_callback
    facebookFriendView = new app.views.FacebookFriendView(model: facebookFriend, el: $('#sandbox'))
    facebookFriendView.render()

    $('.share-button').click()

    expect(@success_callback).toHaveBeenCalledWith(facebookFriend);

  it "should call FB.ui function with redirect_uri and proper data", ->
    window.FB.ui = (data) ->
      expect(data.method).toEqual('feed')
      expect(data.to).toEqual(123)
      expect(data.redirect_uri).toMatch("facebook_id=123")
      expect(data.redirect_uri).toMatch("link=test")
      expect(data.redirect_uri).toMatch("facebook/share-redirect")

    facebookFriend = new app.models.FacebookFriend(id: 123)
    facebookFriendView = new app.views.FacebookFriendView(model: facebookFriend, el: $('#sandbox'))
    spyOn(facebookFriendView,'sharingTemplate').andCallFake ->
      '{"link":"test"}'
    facebookFriendView.render()
{'fraction_non_alphanumeric': 0.14100268576544314, 'fraction_numerical': 0.004923903312444047, 'mean_word_length': 4.45, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4146006', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1248, 'n_words': 230}