<commit_before>'use strict';

describe('papt.wordpairs module', function() {

  beforeEach(module('papt.wordpairs'));

  describe('wordpairs controller', function() {
    var mockScope, mockLocation, mockHttp, mockInterval;
    var wordpairDataHandler;

    beforeEach(inject(function($rootScope, $location, $httpBackend, $interval, $controller) {
      mockScope = $rootScope.$new();
      mockLocation = $location;
      mockInterval = $interval;
      mockHttp = $httpBackend;

      var controller = $controller(
        'WordpairsCtrl',
        { 
          $scope: mockScope,
          $location: mockLocation,
          $interval: mockInterval
        });
      wordpairDataHandler = mockHttp.when('GET', '/data/wordpairs.json')
        .respond([["foo", "bar"], ["qux", "baz"]]);
    }));

    afterEach(function() {
      mockHttp.verifyNoOutstandingExpectation();
      mockHttp.verifyNoOutstandingRequest();
    });

    it('should redirect when no user', inject(function() {
      mockScope.start();
      expect(mockLocation.path()).toBe('/login');
    }));

    it('should load word pairs and start the countdown', inject(function() {
      mockScope.userid = "foo";
      mockScope.start();
      mockHttp.flush();
      expect(mockLocation.path()).not.toBe('/login');
      expect(mockScope.wordpairs).toBeDefined();
      expect(mockScope.wordpairs[0][0]).toBe('foo')
      expect(mockScope.numPairs).toBe(2);
      expect(mockScope.curPair).toBe(0);
      expect(mockScope.numTicksLeft).toBe(300)

      // Time moves forward, expect the tick.
      mockInterval.flush(10);
      expect(mockScope.numTicksLeft).toBe(299)

      // Skip ahead to the last tick, expect curPair to change.
      mockScope.numTicksLeft = 1
      mockInterval.flush(10);
      expect(mockScope.curPair).toBe(1);

      // Skip ahead again, past the last pair, and expect the view to change.
      mockScope.numTicksLeft = 1
      mockInterval.flush(10);
      expect(mockLocation.path()).toBe('/testinstructions');
    }));
  });
});<commit_msg>fix wordpairs test now that there's sound<commit_after>'use strict';

describe('papt.wordpairs module', function() {

  beforeEach(module('papt.wordpairs'));

  describe('wordpairs controller', function() {
    var mockScope, mockLocation, mockHttp, mockInterval, mockTimeout;
    var wordpairDataHandler;

    beforeEach(inject(function($rootScope, $location, $httpBackend, $interval, $timeout, $controller) {
      mockScope = $rootScope.$new();
      mockLocation = $location;
      mockInterval = $interval;
      mockTimeout = $timeout;
      mockHttp = $httpBackend;

      mockScope.beep = {
        playPause: function() { this.played = true; }
      }

      var controller = $controller(
        'WordpairsCtrl',
        { 
          $scope: mockScope,
          $location: mockLocation,
          $interval: mockInterval,
          $timeout: mockTimeout
        });
      wordpairDataHandler = mockHttp.when('GET', '/data/wordpairs.json')
        .respond([["foo", "bar"], ["qux", "baz"]]);
    }));

    afterEach(function() {
      mockHttp.verifyNoOutstandingExpectation();
      mockHttp.verifyNoOutstandingRequest();
    });

    it('should redirect when no user', inject(function() {
      mockScope.start();
      expect(mockLocation.path()).toBe('/login');
    }));

    it('should load word pairs and start the countdown', inject(function() {
      mockScope.userid = "foo";
      mockScope.start();
      mockHttp.flush();
      expect(mockLocation.path()).not.toBe('/login');
      expect(mockScope.wordpairs).toBeDefined();
      expect(mockScope.wordpairs[0][0]).toBe('foo')
      expect(mockScope.numPairs).toBe(2);
      expect(mockScope.curPair).toBe(0);
      expect(mockScope.numTicksLeft).toBe(300)

      // Time moves forward, expect the tick.
      mockInterval.flush(10);
      expect(mockScope.numTicksLeft).toBe(299)

      // Skip ahead to the last tick and send time forward.
      mockScope.numTicksLeft = 1
      mockInterval.flush(10);
      // Expect the beep to have been played.
      expect(mockScope.beep.played).toBeTruthy();
      // Skip ahead some more time for the sound to play.
      mockTimeout.flush(1000);
      expect(mockScope.curPair).toBe(1);

      // Reset the mock sound.
      mockScope.beep.played = false;

      // Skip ahead again, past the last pair, and expect the view to change.
      mockScope.numTicksLeft = 1
      mockInterval.flush(10);
      // Expect the beep to have been played.
      expect(mockScope.beep.played).toBeTruthy();
      // Skip ahead some more time for the sound to play.
      mockTimeout.flush(1000);
      expect(mockLocation.path()).toBe('/testinstructions');
    }));
  });
});
{'fraction_non_alphanumeric': 0.14028395846577665, 'fraction_numerical': 0.00974782792964611, 'mean_word_length': 2.9864864864864864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5923195', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1361, 'n_words': 291}