import { findElementWithAssert, every } from '../helpers';

/**
 * Creates a predicate to validate if an element has a given CSS class
 *
 * @example
 *
 *   var page = PageObject.create({
 *     isImageActive: hasClass('is-active', '.img')
 *   });
 *
 *   assert.ok(page.isImageActive(), 'Image is active');
 *
 * @param {string} cssClass - Name of the CSS class to look for
 * @param {string} selector - CSS selector of the element to check
 * @param {Object} options - Additional options
 * @param {string} options.scope - Overrides parent scope
 * @param {number} options.index - Reduce the set of matched elements to the one at the specified index
 * @return {Descriptor}
 */
export function hasClass(cssClass, selector, options = {}) {
  return {
    isDescriptor: true,

    get() {
      let elements = findElementWithAssert(this, selector, options);

      return every(elements, function(element) {
        return element.hasClass(cssClass);
      });
    }
  };
}

@@ -106,19 +106,41 @@
 element 
-has
+or a set of elements have
  a given
@@ -175,97 +175,690 @@
 %0A * 
-  var page = PageObject.create(%7B%0A *     isImageActive: hasClass('is-active', '.img')%0A *  
+// %3Cem class=%22lorem%22%3E%3C/em%3E%3Cspan class=%22success%22%3EMessage!%3C/span%3E%0A *%0A * let page = PageObject.create(%7B%0A *   messageIsSuccess: PageObject.hasClass('success', 'span')%0A * %7D);%0A *%0A * assert.ok(page.message);%0A *%0A * @example%0A *%0A * // %3Cspan class=%22success%22%3E%3C/span%3E%0A * // %3Cspan class=%22error%22%3E%3C/span%3E%0A *%0A * let page = PageObject.create(%7B%0A *   messagesAreSuccessful: PageObject.hasClass('success', 'span', %7B multiple: true %7D)%0A * %7D);%0A *%0A * assert.ok(!page.messagesAreSuccessful);%0A *%0A * @example%0A *%0A * // %3Cspan class=%22success%22%3E%3C/span%3E%0A * // %3Cspan class=%22success%22%3E%3C/span%3E%0A *%0A * let page = PageObject.create(%7B%0A *   messagesAreSuccessful: PageObject.hasClass('success', 'span', %7B multiple: true %7D)%0A *
  %7D);
@@ -863,18 +863,16 @@
 );%0A *%0A *
-  
  assert.
@@ -883,44 +883,658 @@
 age.
-isImageActive(), 'Image is active');
+messagesAreSuccessful);%0A *%0A * @example%0A *%0A * // %3Cdiv%3E%0A * //   %3Cspan class=%22lorem%22%3E%3C/span%3E%0A * // %3C/div%3E%0A * // %3Cdiv class=%22scope%22%3E%0A * //   %3Cspan class=%22ipsum%22%3E%3C/span%3E%0A * // %3C/div%3E%0A *%0A * let page = PageObject.create(%7B%0A *   messageIsSuccess: PageObject.hasClass('ipsum', 'span', %7B scope: '.scope' %7D)%0A * %7D);%0A *%0A * assert.ok(page.foo);%0A *%0A * @example%0A *%0A * // %3Cdiv%3E%0A * //   %3Cspan class=%22lorem%22%3E%3C/span%3E%0A * // %3C/div%3E%0A * // %3Cdiv class=%22scope%22%3E%0A * //   %3Cspan class=%22ipsum%22%3E%3C/span%3E%0A * // %3C/div%3E%0A *%0A * let page = PageObject.create(%7B%0A *   scope: '.scope',%0A *   messageIsSuccess: PageObject.hasClass('ipsum', 'span')%0A * %7D);%0A *%0A * assert.ok(page.foo);%0A *%0A * @public
 %0A *%0A
@@ -1566,20 +1566,8 @@
 ss -
- Name of the
  CSS
@@ -1580,16 +1580,20 @@
  to 
-look for
+be validated
 %0A * 
@@ -1743,24 +1743,42 @@
 e - 
-Overrides
+Nests provided scope with
  parent
+'s
  sco
@@ -1807,21 +1807,18 @@
 options.
-index
+at
  - Reduc
@@ -1889,27 +1889,365 @@
  * @
-return %7BDescriptor%7D
+param %7Bboolean%7D options.resetScope - Override parent's scope%0A * @param %7Bboolean%7D options.multiple - Check if all elements matched by selector have the CSS class%0A * @return %7BDescriptor%7D%0A *%0A * @throws Will throw an error if no element matches selector%0A * @throws Will throw an error if multiple elements are matched by selector and multiple options is not set
 %0A */

Use jsdoc documentation on has-class property