<commit_before>describe('Offer Form', function() {
  'use strict';
  beforeEach(function() {
    module('offerFormDirective', 'partials');
  });

  var triggerKeyDown = function (element, code) {
    var e = new window.KeyboardEvent('keydown', {
      bubbles: true,
      cancelable: true,
    });
    delete e.keyCode;

    Object.defineProperty(e, 'keyCode', {'value': code});
    element.dispatchEvent(e);
  };

  describe('offer-form directive', function() {
    var element, $scope, $parentScope, mockTags;

    beforeEach(inject(function($httpBackend) {
      mockTags = offerUtils.getMockTags();
      $httpBackend.expectGET('api/v1/tags').respond(mockTags);
      var compiled = utils.compile('<offer-form on-submit="submitClicked($offer)" on-cancel="cancelClicked()" on-delete="deleteClicked()"></offer-form>');
      element = compiled.element;
      $scope = compiled.scope;
      $parentScope = compiled.parentScope;
    }));

    it('should have tags data after we mock-respond to the HTTP request', inject(function($httpBackend) {
      expect($scope.allTags.length).toBe(0);
      $httpBackend.flush();
      expect($scope.allTags.length).toBe(5);
    }));

    describe('with the http requests mock-responded', function() {
      beforeEach(inject(function($httpBackend) {
        $httpBackend.flush();
      }));

      it('should cache the tags request', inject(function($httpBackend) {
        // we'll create another directive and without flushing expect the tags to be resolved
        var compiled = utils.compile('<offer-form></offer-form>');
        expect(compiled.scope.allTags.length).toBe(5);
      }));

      it('should have a date string representing yesterday', function() {
        var now = new Date();
        var yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);

        var yesterdayInUTC = Date.parse($scope.yesterday);
        expect(yesterdayInUTC).toEqual(yesterday.getTime() - yesterday.getTimezoneOffset() * 60 * 1000);
      });

      it('should have a new offer ID prefix', function() {
        expect($scope.idPrefix).toEqual('new-offer-');
      });

      describe('getFilteredTags', function() {
        it('should return (mocked) tags that match the query', function() {
          var result = $scope.getFilteredTags('a');
          expect(result.length).toBe(3);
          expect(result[0].name).toBe('kala');
          expect(result[1].name).toBe('siga');
          expect(result[2].name).toBe('praad');
        });

        it('should return (mocked) tags that match the query', function() {
          var result = $scope.getFilteredTags('l');
          expect(result.length).toBe(2);
          expect(result[0].name).toBe('kala');
          expect(result[1].name).toBe('lind');
        });

        it('should return no tags if bad query', function() {
          var result = $scope.getFilteredTags('blablabla');
          expect(result.length).toBe(0);
        });
      });

      describe('isReadyForError', function() {
        it('should return true when dirty, touched and invalid', function() {
          var input = {
            $dirty: true,
            $touched: true,
            $invalid: true,
          };
          expect($scope.isReadyForError(input)).toBe(true);
        });

        it('should return false when not dirty, but touched and invalid', function() {
          var input = {
            $dirty: false,
            $touched: true,
            $invalid: true,
          };
          expect($scope.isReadyForError(input)).toBe(false);
        });

        it('should return true when when first input is false, second true', function() {
          var input1 = {
            $dirty: false,
            $touched: true,
            $invalid: true,
          };
          var input2 = {
            $dirty: true,
            $touched: true,
            $invalid: true,
          };
          expect($scope.isReadyForError(input1, input2)).toBe(true);
        });
      });



      describe('submitOffer', function() {
        beforeEach(function() {
          $parentScope.submitClicked = jasmine.createSpy();
        });

        describe('with the form filled', function() {
          beforeEach(function() {
            $scope.title = 'a title';
            $scope.description = 'a short description';
            $scope.tags = [{
              name: 'tag1',
              a: 'a'
            }, {
              name: 'tag2',
              a: 'b'
            }];
            $scope.price = 2.5;
            $scope.date = new Date(2015, 3, 15);
            $scope.fromTime = new Date(1970, 0, 1, 10, 0, 0);
            $scope.toTime = new Date(1970, 0, 1, 15, 0, 0);
            $scope.image = {src: 'image data'};
          });

          it('should call the specified function with $offer as the argument', function() {
            $scope.submitOffer();

            expect($parentScope.submitClicked).toHaveBeenCalledWith({
              title: 'a title',
              description: 'a short description',
              tags: ['tag1', 'tag2'],
              price: 2.5,
              from_time: new Date(2015, 3, 15, 10, 0, 0),
              to_time: new Date(2015, 3, 15, 15, 0, 0),
              image_data: 'image data',
            });
          });
        });
      });

      describe('cancelOffer', function() {
        beforeEach(function() {
          $parentScope.cancelClicked = jasmine.createSpy();
        });

        it('should call the specified function with $offer as the argument', function() {
          $scope.cancelFunction();

          expect($parentScope.cancelClicked).toHaveBeenCalled();
        });
      });

      describe('deleteOffer', function() {<commit_msg>Fix test<commit_after>describe('Offer Form', function() {
  'use strict';
  beforeEach(function() {
    module('offerFormDirective', 'partials');
  });

  var triggerKeyDown = function (element, code) {
    var e = new window.KeyboardEvent('keydown', {
      bubbles: true,
      cancelable: true,
    });
    delete e.keyCode;

    Object.defineProperty(e, 'keyCode', {'value': code});
    element.dispatchEvent(e);
  };

  describe('offer-form directive', function() {
    var element, $scope, $parentScope, mockTags;

    beforeEach(inject(function($httpBackend) {
      mockTags = offerUtils.getMockTags();
      $httpBackend.expectGET('api/v1/tags').respond(mockTags);
      var compiled = utils.compile('<offer-form on-submit="submitClicked($offer)" on-cancel="cancelClicked()" on-delete="deleteClicked()"></offer-form>');
      element = compiled.element;
      $scope = compiled.scope;
      $parentScope = compiled.parentScope;
    }));

    it('should have tags data after we mock-respond to the HTTP request', inject(function($httpBackend) {
      expect($scope.allTags.length).toBe(0);
      $httpBackend.flush();
      expect($scope.allTags.length).toBe(5);
    }));

    describe('with the http requests mock-responded', function() {
      beforeEach(inject(function($httpBackend) {
        $httpBackend.flush();
      }));

      it('should cache the tags request', inject(function($httpBackend) {
        // we'll create another directive and without flushing expect the tags to be resolved
        var compiled = utils.compile('<offer-form></offer-form>');
        expect(compiled.scope.allTags.length).toBe(5);
      }));

      it('should have a date string representing yesterday', function() {
        var now = new Date();
        var yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);

        var yesterdayInUTC = Date.parse($scope.yesterday);
        expect(yesterdayInUTC).toEqual(yesterday.getTime() - yesterday.getTimezoneOffset() * 60 * 1000);
      });

      it('should have a new offer ID prefix', function() {
        expect($scope.idPrefix).toEqual('new-offer-');
      });

      describe('getFilteredTags', function() {
        it('should return (mocked) tags that match the query', function() {
          var result = $scope.getFilteredTags('a');
          expect(result.length).toBe(3);
          expect(result[0].name).toBe('kala');
          expect(result[1].name).toBe('siga');
          expect(result[2].name).toBe('praad');
        });

        it('should return (mocked) tags that match the query', function() {
          var result = $scope.getFilteredTags('l');
          expect(result.length).toBe(2);
          expect(result[0].name).toBe('kala');
          expect(result[1].name).toBe('lind');
        });

        it('should return no tags if bad query', function() {
          var result = $scope.getFilteredTags('blablabla');
          expect(result.length).toBe(0);
        });
      });

      describe('isReadyForError', function() {
        it('should return true when dirty, touched and invalid', function() {
          var input = {
            $dirty: true,
            $touched: true,
            $invalid: true,
          };
          expect($scope.isReadyForError(input)).toBe(true);
        });

        it('should return false when not dirty, but touched and invalid', function() {
          var input = {
            $dirty: false,
            $touched: true,
            $invalid: true,
          };
          expect($scope.isReadyForError(input)).toBe(false);
        });

        it('should return true when when first input is false, second true', function() {
          var input1 = {
            $dirty: false,
            $touched: true,
            $invalid: true,
          };
          var input2 = {
            $dirty: true,
            $touched: true,
            $invalid: true,
          };
          expect($scope.isReadyForError(input1, input2)).toBe(true);
        });
      });



      describe('submitOffer', function() {
        beforeEach(function() {
          $parentScope.submitClicked = jasmine.createSpy();
        });

        describe('with the form filled', function() {
          beforeEach(function() {
            $scope.title = 'a title';
            $scope.description = 'a short description';
            $scope.tags = [{
              name: 'tag1',
              a: 'a'
            }, {
              name: 'tag2',
              a: 'b'
            }];
            $scope.price = 2.5;
            $scope.date = new Date(2015, 3, 15);
            $scope.fromTime = new Date(1970, 0, 1, 10, 0, 0);
            $scope.toTime = new Date(1970, 0, 1, 15, 0, 0);
            $scope.image = {src: 'image data'};
            $scope.$apply();
          });

          it('should call the specified function with $offer as the argument', function() {
            $scope.submitOffer();

            expect($parentScope.submitClicked).toHaveBeenCalledWith({
              title: 'a title',
              description: 'a short description',
              tags: ['tag1', 'tag2'],
              price: 2.5,
              from_time: new Date(2015, 3, 15, 10, 0, 0),
              to_time: new Date(2015, 3, 15, 15, 0, 0),
              image_data: 'image data',
            });
          });
        });
      });

      describe('cancelOffer', function() {
        beforeEach(function() {
          $parentScope.cancelClicked = jasmine.createSpy();
        });

        it('should call the specified function with $offer as the argument', function() {
          $scope.cancelFunction();

          expect($parentScope.cancelClicked).toHaveBeenCalled();
        });
      });

      describe('deleteOffer', function() {
{'fraction_non_alphanumeric': 0.14762987580899073, 'fraction_numerical': 0.013993353157250307, 'mean_word_length': 2.155353200883002, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2015564', 'n_tokens_mistral': 3327, 'n_tokens_neox': 3160, 'n_words': 734}