import commonModule from '../';

describe('wsValidationMessages component', () => {
  let outerScope;
  let element;

  beforeEach(() => {
    angular.mock.module(commonModule);
    angular.mock.module('ws.common');
  });

  function injectElement(elementHtml) {
    beforeEach(angular.mock.inject(($rootScope, $compile) => {
      outerScope = $rootScope.$new();
      element = angular.element(elementHtml);
      $compile(element)(outerScope);
      outerScope.$digest();
    }));
  }

  describe('initial state', () => {
    const html = `<div ng-form="validationForm">
                    <input class="form-input-text" name="field" type="text" ng-model="validationModel.field" required>
                    <ws-validation-messages model="validationModel" attribute="field" form-name="validationForm.field">
                    </ws-validation-messages>
                  </div>`;
    injectElement(html);
    it('there should be two help-blocks', () => {
      const helpBlocks = element[0].querySelectorAll('div.help-block');
      expect(helpBlocks.length).toBe(2);
    });
    it('there should be an ngMessage', () => {
      const errorMessages = element[0].querySelectorAll('p.error-message');
      expect(errorMessages.length).toBe(1);
    });
  });
});
