<commit_before>describe "mb.spinner", ->
  beforeEach module("mb.spinner")

  pendingRequests = null
  beforeEach inject ($injector) ->
    pendingRequests = $injector.get("pendingRequests")

  describe "pendingRequests", ->
    it "has @counter", ->
      expect(pendingRequests.counter).toBeDefined()
      expect(pendingRequests.counter).toEqual(0)

    describe "#increment", ->
      it "increments the @counter", ->
        pendingRequests.increment()
        expect(pendingRequests.counter).toEqual(1)

        pendingRequests.increment()
        expect(pendingRequests.counter).toEqual(2)

    describe "#decrement", ->
      describe "when the @counter is 0", ->
        beforeEach -> pendingRequests.counter = 0

        it "does nothing", ->
          pendingRequests.decrement()
          expect(pendingRequests.counter).toEqual(0)

      describe "when the @counter is > 0", ->
        beforeEach -> pendingRequests.counter = 2

        it "decrements the @counter", ->
          pendingRequests.decrement()
          expect(pendingRequests.counter).toEqual(1)

          pendingRequests.decrement()
          expect(pendingRequests.counter).toEqual(0)

    describe "#isPending", ->
      describe "when the number of pending requests is > 0", ->
        beforeEach -> pendingRequests.counter = 2

        it "returns true", ->
          expect(pendingRequests.isPending()).toBeTruthy()

      describe "otherwise", ->
        beforeEach -> pendingRequests.counter = 0

        it "returns false", ->
          expect(pendingRequests.isPending()).toBeFalsy()

  describe "pendingRequestsInterceptor", ->
    interceptor = null
    pendingRequests = null
    promise = null

    beforeEach inject ($injector) ->
      interceptor = $injector.get("pendingRequestsInterceptor")
      pendingRequests = $injector.get("pendingRequests")
      promise = then: jasmine.createSpy("then").andReturn({})

      pendingRequests.counter = 2
      interceptor(promise)

    describe "onSuccess", ->
      it "decrements the counter", ->
        successHandler = promise.then.mostRecentCall.args[0]

        httpResponse = status: 100
        expect(successHandler(httpResponse)).toBe(httpResponse)
        expect(pendingRequests.counter).toEqual(1)

    describe "onError", ->
      it "decrements the counter", ->
        errorHandler = promise.then.mostRecentCall.args[1]

        httpResponse = status: 404
        errorHandler(httpResponse) # TODO test $q.reject(response)
        expect(pendingRequests.counter).toEqual(1)

  describe "controller", ->
    # TODO

  describe "directive", ->
    # TODO<commit_msg>Write spec for spinner controller.<commit_after>describe "mb.spinner", ->
  beforeEach module("mb.spinner")

  pendingRequests = null
  beforeEach inject ($injector) ->
    pendingRequests = $injector.get("pendingRequests")

  describe "pendingRequests", ->
    it "has @counter", ->
      expect(pendingRequests.counter).toBeDefined()
      expect(pendingRequests.counter).toEqual(0)

    describe "#increment", ->
      it "increments the @counter", ->
        pendingRequests.increment()
        expect(pendingRequests.counter).toEqual(1)

        pendingRequests.increment()
        expect(pendingRequests.counter).toEqual(2)

    describe "#decrement", ->
      describe "when the @counter is 0", ->
        beforeEach -> pendingRequests.counter = 0

        it "does nothing", ->
          pendingRequests.decrement()
          expect(pendingRequests.counter).toEqual(0)

      describe "when the @counter is > 0", ->
        beforeEach -> pendingRequests.counter = 2

        it "decrements the @counter", ->
          pendingRequests.decrement()
          expect(pendingRequests.counter).toEqual(1)

          pendingRequests.decrement()
          expect(pendingRequests.counter).toEqual(0)

    describe "#isPending", ->
      describe "when the number of pending requests is > 0", ->
        beforeEach -> pendingRequests.counter = 2

        it "returns true", ->
          expect(pendingRequests.isPending()).toBeTruthy()

      describe "otherwise", ->
        beforeEach -> pendingRequests.counter = 0

        it "returns false", ->
          expect(pendingRequests.isPending()).toBeFalsy()

  describe "pendingRequestsInterceptor", ->
    interceptor = null
    pendingRequests = null
    promise = null

    beforeEach inject ($injector) ->
      interceptor = $injector.get("pendingRequestsInterceptor")
      pendingRequests = $injector.get("pendingRequests")
      promise = then: jasmine.createSpy("then").andReturn({})

      pendingRequests.counter = 2
      interceptor(promise)

    describe "onSuccess", ->
      it "decrements the counter", ->
        successHandler = promise.then.mostRecentCall.args[0]

        httpResponse = status: 100
        expect(successHandler(httpResponse)).toBe(httpResponse)
        expect(pendingRequests.counter).toEqual(1)

    describe "onError", ->
      it "decrements the counter", ->
        errorHandler = promise.then.mostRecentCall.args[1]

        httpResponse = status: 404
        errorHandler(httpResponse) # TODO test $q.reject(response)
        expect(pendingRequests.counter).toEqual(1)

  describe "controller", ->
    controller = null
    $scope = null

    beforeEach inject ($rootScope, $controller) ->
      $scope = $rootScope.$new()
      controller = $controller "spinner",
        $scope: $scope

    describe "#showSpinner", ->
      describe "when there is a pending request", ->
        beforeEach -> pendingRequests.counter = 3

        it "returns true", ->
          expect($scope.showSpinner()).toBeTruthy()

      describe "otherwise", ->
        beforeEach -> pendingRequests.counter = 0

        it "returns false", ->
          expect($scope.showSpinner()).toBeFalsy()

  describe "directive", ->
    # TODO
{'fraction_non_alphanumeric': 0.12074888354517348, 'fraction_numerical': 0.008588114050154586, 'mean_word_length': 2.7959582790091266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 71, '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': '2007911', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1569, 'n_words': 330}