<commit_before>describe 'Page', ->

  beforeEach ->
    @visitStub = stub(Turbolinks, "visit")

  afterEach ->
    @visitStub.restore()

  it 'is defined', ->
    assert Page

  describe '#visit', ->
    it 'will call Turbolinks#visit without any options', ->
      Page.visit("http://example.com")
      assert @visitStub.calledOnce

  describe '#refresh', ->
    it 'with opts.url', ->
      Page.refresh
        url: '/foo'

      assert @visitStub.calledOnce
      assert @visitStub.calledWith "/foo", true, []

    it 'with opts.queryParams', ->
      Page.refresh
        queryParams:
          foo: "bar"
          baz: "bot"

      assert @visitStub.calledOnce
      assert @visitStub.calledWith location.pathname + "?foo=bar&baz=bot"

    it 'ignores opts.queryParams if opts.url is present', ->
      Page.refresh
        url: '/foo'
        queryParams:
          foo: "bar"

      assert @visitStub.calledOnce
      assert @visitStub.calledWith "/foo"

    it 'uses location.href if opts.url and opts.queryParams are missing', ->
      Page.refresh()

      assert @visitStub.calledOnce
      assert @visitStub.calledWith location.href

    it 'with opts.onlyKeys', ->
      Page.refresh
        onlyKeys: ['a', 'b', 'c']

      assert @visitStub.calledOnce
      assert @visitStub.calledWith location.href, true, ['a', 'b', 'c']

    it 'calls Turbolinks#loadPage if an XHR is provided in opts.response', ->
      loadPageStub = stub(Turbolinks, "loadPage")
      afterRefreshCallback = stub()

      Page.refresh
        response: "placeholder for an XHR"
        onlyKeys: ['a', 'b']
      , afterRefreshCallback

      assert loadPageStub.calledOnce
      assert loadPageStub.calledWith null, "placeholder for an XHR", true, afterRefreshCallback, ['a', 'b']
      loadPageStub.restore()
<commit_msg>Added page test for redirects<commit_after>describe 'Page', ->

  beforeEach ->
    @visitStub = stub(Turbolinks, "visit")

  afterEach ->
    @visitStub.restore()

  it 'is defined', ->
    assert Page

  describe '#visit', ->
    it 'will call Turbolinks#visit without any options', ->
      Page.visit("http://example.com")
      assert @visitStub.calledOnce

  describe '#refresh', ->
    it 'with opts.url', ->
      Page.refresh
        url: '/foo'

      assert @visitStub.calledOnce
      assert @visitStub.calledWith "/foo", true, []

    it 'with opts.queryParams', ->
      Page.refresh
        queryParams:
          foo: "bar"
          baz: "bot"

      assert @visitStub.calledOnce
      assert @visitStub.calledWith location.pathname + "?foo=bar&baz=bot"

    it 'ignores opts.queryParams if opts.url is present', ->
      Page.refresh
        url: '/foo'
        queryParams:
          foo: "bar"

      assert @visitStub.calledOnce
      assert @visitStub.calledWith "/foo"

    it 'uses location.href if opts.url and opts.queryParams are missing', ->
      Page.refresh()

      assert @visitStub.calledOnce
      assert @visitStub.calledWith location.href

    it 'with opts.onlyKeys', ->
      Page.refresh
        onlyKeys: ['a', 'b', 'c']

      assert @visitStub.calledOnce
      assert @visitStub.calledWith location.href, true, ['a', 'b', 'c']

    it 'calls Turbolinks#loadPage if an XHR is provided in opts.response', ->
      loadPageStub = stub(Turbolinks, "loadPage")
      afterRefreshCallback = stub()

      Page.refresh
        response: "placeholder for an XHR"
        onlyKeys: ['a', 'b']
      , afterRefreshCallback

      assert loadPageStub.calledOnce
      assert loadPageStub.calledWith null, "placeholder for an XHR", true, afterRefreshCallback, ['a', 'b']
      loadPageStub.restore()

    it 'updates window push state when response is a redirect', ->
      replaceStateStub = stub(Turbolinks, "replaceState")

      mockXHR = {
        getResponseHeader: (header) ->
          if header == 'Content-Type'
            return "text/html"
          else if header == 'X-XHR-Redirected-To'
            return "http://www.test.com/redirect"
          ""
        status: 302
        responseText: "<div>redirected</div>"
      }
      Page.refresh
        response: mockXHR,
        onlyKeys: ['a']

      replaceStateStub.calledWith mockXHR.getResponseHeader('X-XHR-Redirected-To')

{'fraction_non_alphanumeric': 0.12311320754716981, 'fraction_numerical': 0.0007075471698113207, 'mean_word_length': 2.4535830618892507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '6254810', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1271, 'n_words': 328}