<commit_before>import {WaitingButtonController} from '../src/js/waiting-button.directive';
const angular = require('angular'),
      angularMock = require('angular-mocks');


describe('mbmWaitingButton', () => {
  beforeEach(() => {
    angular.mock.module('mbm.waitingButton');
  });

  it('should toggle waiting class based on operation promise', () => {
    angular.mock.inject(($rootScope, $compile, $timeout, $q) => {
      // Build a Promise to represent an async operation
      const operationDeferred = $q.defer();

      // Fake receiver for the click action
      $rootScope.onClickReceiver = function() {
        return operationDeferred.promise;
      }

      // Define simple template for the directive, and then compile it
      const template = `
        <button mbm-waiting-button="onClickReceiver()">Waiting Button</button>
      `;
      const element = $compile(template)($rootScope);

      // Verify that the element doesn't have the waiting-button loading class
      //  by default.
      expect(element.hasClass(WaitingButtonController.WAITING_CLASS)).toEqual(false);

      // Simulate click to enter "waiting" state
      element[0].click();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Verify that the element now has the waiting-button loading class.
      expect(element.hasClass(WaitingButtonController.WAITING_CLASS)).toEqual(true);

      // Resolve the operation. Should return waiting button to normal state.
      operationDeferred.resolve();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Verify that the element doesn't have the waiting-button loading class
      //  after the operation promise has resolved.
      expect(element.hasClass(WaitingButtonController.WAITING_CLASS)).toEqual(false);
    });
  });

  it('should support customizable waiting classes', () => {
    angular.mock.inject(($rootScope, $compile, $timeout, $q) => {
      // Build a Promise to represent an async operation
      const operationDeferred = $q.defer();

      // Fake receiver for the click action
      $rootScope.onClickReceiver = function() {
        return operationDeferred.promise;
      }

      // Define the custom CSS class we'll be testing for
      const waitingClass = 'waiting';

      // Define simple template for the directive, and then compile it
      const template = `
        <button
          mbm-waiting-button="onClickReceiver()"
          waiting-button-waiting-class="${waitingClass}"
          >Waiting Button</button>
      `;
      const element = $compile(template)($rootScope);

      // Verify that the element doesn't have the waiting-button loading class
      //  by default.
      expect(element.hasClass(waitingClass)).toEqual(false);

      // Simulate click to enter "waiting" state
      element[0].click();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Verify that the element now has the waiting-button loading class.
      expect(element.hasClass(waitingClass)).toEqual(true);

      // Resolve the operation. Should return waiting button to normal state.
      operationDeferred.resolve();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Verify that the element doesn't have the waiting-button loading class
      //  after the operation promise has resolved.
      expect(element.hasClass(waitingClass)).toEqual(false);
    });
  });

  it('should support prevent additional action triggers while in wait state', () => {
    angular.mock.inject(($rootScope, $compile, $timeout, $q) => {
      // Build a Promise to represent an async operation
      const operationDeferred = $q.defer();

      // Fake receiver for the click action
      let receiverInvocationCounter = 0;
      $rootScope.onClickReceiver = function() {
        // TODO: This should updated to use a spy at some point.
        receiverInvocationCounter++;

        return operationDeferred.promise;
      }

      // Define simple template for the directive, and then compile it
      const template = `
        <button mbm-waiting-button="onClickReceiver()">Waiting Button</button>
      `;
      const element = $compile(template)($rootScope);

      // Simulate click to enter "waiting" state
      element[0].click();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Simulate another click
      element[0].click();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Verify that the operation receiver has only been invoked once.
      expect(receiverInvocationCounter).toEqual(1);
    });
  });
});<commit_msg>Adds test of error state recovery.<commit_after>import {WaitingButtonController} from '../src/js/waiting-button.directive';
const angular = require('angular'),
      angularMock = require('angular-mocks');


describe('mbmWaitingButton', () => {
  beforeEach(() => {
    angular.mock.module('mbm.waitingButton');
  });

  it('should toggle waiting class based on operation promise', () => {
    angular.mock.inject(($rootScope, $compile, $timeout, $q) => {
      // Build a Promise to represent an async operation
      const operationDeferred = $q.defer();

      // Fake receiver for the click action
      $rootScope.onClickReceiver = function() {
        return operationDeferred.promise;
      }

      // Define simple template for the directive, and then compile it
      const template = `
        <button mbm-waiting-button="onClickReceiver()">Waiting Button</button>
      `;
      const element = $compile(template)($rootScope);

      // Verify that the element doesn't have the waiting-button loading class
      //  by default.
      expect(element.hasClass(WaitingButtonController.WAITING_CLASS)).toEqual(false);

      // Simulate click to enter "waiting" state
      element[0].click();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Verify that the element now has the waiting-button loading class.
      expect(element.hasClass(WaitingButtonController.WAITING_CLASS)).toEqual(true);

      // Resolve the operation. Should return waiting button to normal state.
      operationDeferred.resolve();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Verify that the element doesn't have the waiting-button loading class
      //  after the operation promise has resolved.
      expect(element.hasClass(WaitingButtonController.WAITING_CLASS)).toEqual(false);
    });
  });

  it('should support customizable waiting classes', () => {
    angular.mock.inject(($rootScope, $compile, $timeout, $q) => {
      // Build a Promise to represent an async operation
      const operationDeferred = $q.defer();

      // Fake receiver for the click action
      $rootScope.onClickReceiver = function() {
        return operationDeferred.promise;
      }

      // Define the custom CSS class we'll be testing for
      const waitingClass = 'waiting';

      // Define simple template for the directive, and then compile it
      const template = `
        <button
          mbm-waiting-button="onClickReceiver()"
          waiting-button-waiting-class="${waitingClass}"
          >Waiting Button</button>
      `;
      const element = $compile(template)($rootScope);

      // Verify that the element doesn't have the waiting-button loading class
      //  by default.
      expect(element.hasClass(waitingClass)).toEqual(false);

      // Simulate click to enter "waiting" state
      element[0].click();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Verify that the element now has the waiting-button loading class.
      expect(element.hasClass(waitingClass)).toEqual(true);

      // Resolve the operation. Should return waiting button to normal state.
      operationDeferred.resolve();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Verify that the element doesn't have the waiting-button loading class
      //  after the operation promise has resolved.
      expect(element.hasClass(waitingClass)).toEqual(false);
    });
  });

  it('should support prevent additional action triggers while in wait state', () => {
    angular.mock.inject(($rootScope, $compile, $timeout, $q) => {
      // Build a Promise to represent an async operation
      const operationDeferred = $q.defer();

      // Fake receiver for the click action
      let receiverInvocationCounter = 0;
      $rootScope.onClickReceiver = function() {
        // TODO: This should updated to use a spy at some point.
        receiverInvocationCounter++;

        return operationDeferred.promise;
      }

      // Define simple template for the directive, and then compile it
      const template = `
        <button mbm-waiting-button="onClickReceiver()">Waiting Button</button>
      `;
      const element = $compile(template)($rootScope);

      // Simulate click to enter "waiting" state
      element[0].click();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Simulate another click
      element[0].click();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Verify that the operation receiver has only been invoked once.
      expect(receiverInvocationCounter).toEqual(1);
    });
  });

  it('should support remove waiting presentation after error', () => {
    angular.mock.inject(($rootScope, $compile, $timeout, $q) => {
      // Build a Promise to represent an async operation
      const operationDeferred = $q.defer();

      // Fake receiver for the click action
      $rootScope.onClickReceiver = function() {
        return operationDeferred.promise;
      }

      // Define simple template for the directive, and then compile it
      const template = `
        <button mbm-waiting-button="onClickReceiver()">Waiting Button</button>
      `;
      const element = $compile(template)($rootScope);

      // Verify that the element doesn't have the waiting-button loading class
      //  by default.
      expect(element.hasClass(WaitingButtonController.WAITING_CLASS)).toEqual(false);

      // Simulate click to enter "waiting" state
      element[0].click();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Verify that the element now has the waiting-button loading class.
      expect(element.hasClass(WaitingButtonController.WAITING_CLASS)).toEqual(true);

      // Reject (fail) the operation. Should move the waiting button to
      //  error state.
      operationDeferred.reject();

      // Run the Angular digest loop once to pick up the changes.
      $rootScope.$digest();

      // Verify that the element doesn't have the waiting-button loading class
      //  after the operation promise has resolved.
      expect(element.hasClass(WaitingButtonController.WAITING_CLASS)).toEqual(false);
    });
  });
});
{'fraction_non_alphanumeric': 0.10746455007580487, 'fraction_numerical': 0.00115936859002943, 'mean_word_length': 2.798780487804878, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 35, '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': '5510330', 'n_tokens_mistral': 2938, 'n_tokens_neox': 2843, 'n_words': 950}