Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage #16785

Merged
merged 40 commits into from
Dec 27, 2015
Merged

Conversation

vlazar
Copy link
Collaborator

@vlazar vlazar commented Nov 24, 2015

I have some more tests, and I wanted to clean them up before sending this PR, but it looks like I've already waited far too long, and just increased the chance of conflict with tests from other contributors. So I'm sending this PR now.

Tests:

  • better test coverage
  • better tests structure with folders for groups of features and smaller feature-oriented files
  • simpler test setup with karma-fixtures which loads HTML fixtures from file
  • simpler test setup with def() and subject() lazy helpers from karma-jasmine-def
  • updated devDependencies

Bug fixes:

Also contains temporarily disabled test for found bug. See Fix for open() will not open list before any input event. I can look at it as soon as I have time and more tests ready. Maybe there is more than 1 bug there.

@vlazar
Copy link
Collaborator Author

vlazar commented Nov 24, 2015

@LeaVerou I know you are usually super busy, but can you please merge this huge PR soon, so I can safely continue to work on more similar looking tests?

Also, would you agree to add code coverage reporting (Code Climate or Coveralls), similar to Travis CI builds info we already have now?

It's good to see, which code is covered by tests, and which is not. I'll do a separate PR if you agree.

@vlazar vlazar changed the title Features/improve test coverage Improve test coverage Nov 25, 2015
@vlazar
Copy link
Collaborator Author

vlazar commented Nov 25, 2015

Almost 100% test coverage now. Woot!

I'm planning to add missing initialization and export tests, once I figure out a better way to do it.

Chrome 46.0.2490 (Mac OS X 10.11.1): Executed 197 of 198 (skipped 1) SUCCESS (0.27 secs / 0.18 secs)

Suites and tests results:

 - awesomplete.close :
   * closes completer : ok
   * makes no item selected : ok
   * fires awesomplete-close event : ok
 - awesomplete.evaluate :
   - with too short input value :
     * closes completer : ok
   - with no items found :
     * closes completer : ok
   - with some items found :
     * opens completer : ok
     * fills completer with found items : ok
     * makes no item selected : ok
 - awesomplete.goto :
   * clears previous aria-selected : ok
   * goes to first item : ok
   * goes to last item : ok
   * fires awesomplete-highlight event : ok
   - with item index > -1 :
     * sets aria-selected : ok
     * updates status : ok
   - with item index = -1 :
     * does not update status : ok
 - awesomplete.next :
   - without any items found :
     * does not select any item : ok
   - with some items found :
     - and no item was already selected :
       * selects the first item  : ok
     - and some item was already selected :
       * selects the second item : ok
       * selects the last item : ok
       * selects no item after reaching the end : ok
 - awesomplete.open :
   * opens completer : ok
   * fills in the list on creation : skipped
   * fires awesomplete-open event : ok
   - with autoFirst: true :
     * automatically selects first item : ok
   - with autoFirst: false :
     * does not select any item : ok
 - awesomplete.opened :
   - with newly created completer :
     * is false : ok
   - with opened completer :
     * is true : ok
   - with closed completer :
     * is false : ok
 - awesomplete.previous :
   - without any items found :
     * does not select any item : ok
   - with some items found :
     - and no item was already selected :
       * selects the last item  : ok
     - and some item was already selected :
       * selects the second item from the end : ok
       * selects the first item : ok
       * selects no item after reaching the start : ok
 - awesomplete.select :
   - with closed completer :
     * does not change the input value : ok
     * does not fire awesomplete-select event : ok
     * does not fire awesomplete-selectcomplete event : ok
   - with opened completer :
     - and no current item :
       * does not change the input value : ok
       * does not fire awesomplete-select event : ok
       * does not fire awesomplete-selectcomplete event : ok
     - and current item :
       * fires awesomplete-select event : ok
       - and awesomplete-select event was not prevented :
         * changes the input value : ok
         * closes completer : ok
         * fires awesomplete-selectcomplete event : ok
       - and awesomplete-select event was prevented :
         * does not change the input value : ok
         * does not close completer : ok
         * does not fire awesomplete-selectcomplete event : ok
     - and item specified as argument :
       * fires awesomplete-select event : ok
       - and awesomplete-select event was not prevented :
         * changes the input value : ok
         * closes completer : ok
         * fires awesomplete-selectcomplete event : ok
       - and awesomplete-select event was prevented :
         * does not change the input value : ok
         * does not close completer : ok
         * does not fire awesomplete-selectcomplete event : ok
 - awesomplete.selected :
   - with newly created completer :
     * is false : ok
   - with opened completer :
     - and no item selected :
       * is false : ok
     - and some item selected :
       * is true : ok
   - with closed completer :
     * is false : ok
 - blur event :
   * closes completer : ok
 - input event :
   * rebuilds the list : ok
 - keydown event :
   * supports enter : ok
   * supports escape : ok
   * supports down arrow : ok
   * supports up arrow : ok
   * ignores other keys : ok
   * does nothing if not opened : ok
 - mousedown event :
   - with ul target :
     * does not select item : ok
   - with li target :
     * selects item : ok
   - with child of li target :
     * selects item : ok
 - form submit event :
   * closes completer : ok
 - Awesomplete.$.bind :
   - whith invalid element :
     * does nothing if element is undefined : ok
     * does nothing if element is null : ok
     * does nothing if element is false : ok
     * does nothing if element is 0 : ok
     * does nothing if element is empty string : ok
   - with valid element :
     * adds event listeners for all events : ok
     * adds single event listener for multiple events : ok
 - Awesomplete.$.create :
   * creates DOM element : ok
   - with various tag names :
     * creates <ul> element : ok
     * creates <li> element : ok
   - without options :
     * creates element without any attributes : ok
   - with simple options :
     * assigns properties : ok
     * assigns attributes : ok
   - with option for boolean attribute/property :
     * assigns from true value : ok
     * assigns from truthy value : ok
     * assigns from false value : ok
     * assigns from falsy value : ok
   - with inside: option :
     * appends to container by element : ok
     * appends to container by selector : ok
   - with around: option :
     * wraps specified element : ok
     * wraps element specified by selector : ok
 - Awesomplete.$ :
   - with default context :
     * returns DOM element : ok
     * finds by id : ok
     * finds by class name : ok
     * finds by tag name : ok
   - with custom context :
     * returns DOM element : ok
     * finds by id : ok
     * finds by class name : ok
     * finds by tag name : ok
   - with truthy non string expression :
     * returns the expression back : ok
   - with falsy non string expression :
     * returns null if expression is undefined : ok
     * returns null if expression is null : ok
     * returns null if expression is false : ok
 - Awesomplete.$$ :
   - with default context :
     * returns an array of DOM elements : ok
     * finds all elements : ok
     * finds DOM element : ok
     * finds by id : ok
     * finds by class name : ok
     * finds by tag name : ok
   - with custom context :
     * returns an array of DOM elements : ok
     * finds all elements : ok
     * finds DOM element : ok
     * finds by id : ok
     * finds by class name : ok
     * finds by tag name : ok
 - Awesomplete.$.fire :
   * fires event once : ok
   - fires different event types :
     * fires click event : ok
     * fires input event : ok
   - sets event properties :
     * makes cancelable event : ok
     * can't make non cancelable event : ok
     * makes event that bubbles : ok
     * can't make event that does not bubble : ok
     * sets properties on the event : ok
 - Awesomplete.$.regExpEscape :
   - with regular expression special characters :
     * escapes backslashes : ok
     * escapes brackets, braces and parentheses : ok
     * escapes other special characters : ok
     * escapes the whole string : ok
   - with plain characters :
     * does not escape letters : ok
     * does not escape numbers : ok
 - Html modifications :
   * binds to correct input : ok
   * turns native autocompleter off : ok
   - HTML tweaks :
     * creates container : ok
     * places input inside container : ok
     * creates list : ok
     * places list inside container : ok
     * hides list : ok
   - ARIA support :
     * makes input accessible : ok
     * creates status : ok
     * puts status inside container : ok
     * hides status : ok
 - Awesomplete list :
   * is empty if not provided : ok
   - setter :
     * assigns from array : ok
     * assigns from comma separated list : ok
     * assigns from element specified by selector : ok
     * assigns from element : ok
     * does not assigns from not found list : ok
     * does not assigns from empty list : ok
     - with active input :
       * evaluates completer : ok
   - constructor option :
     * assigns from array : ok
     * assigns from comma separated list : ok
     * assigns from element specified by selector : ok
     * assigns from list specified by element : ok
   - data-list html attribute :
     * assigns from comma separated list : ok
     * assigns from element referenced by selector : ok
   - list html attribute :
     * assigns from element referenced by id : ok
 - Constructor options :
   - with default options :
     * requires minimum 2 chars to open completer : ok
     * shows 10 items in completer : ok
     * does not select the first ocurrence automatically : ok
     * filters with FILTER_CONTAINS : ok
     * orders with SORT_BYLENGTH : ok
     * generates each completer item with built-in function : ok
     * mirrors found item into input with built-in function : ok
   - with custom options in constructor :
     * overrides simple default options : ok
     * overrides default functions : ok
   - with custom options in data-* attributes :
     * overrides simple default options : ok
 - Awesomplete.all :
   * is empty initially : ok
   * keeps a list of created instances : ok
 - Awesomplete.FILTER_CONTAINS :
   * is a function : ok
   - search in a plain string :
     * matches at the start : ok
     * matches in the middle : ok
     * matches at the end : ok
     * performs case insensitive match : ok
     * ignores whitespaces around the search value : ok
     * does not match if substring is not found : ok
   - search in string with special RegExp chars :
     * matches at the start : ok
     * matches in the middle : ok
     * matches at the end : ok
     * performs case insensitive match : ok
     * ignores whitespaces around the search value : ok
     * does not match if substring is not found : ok
 - Awesomplete.FILTER_STARTSWITH :
   * is a function : ok
   - search in plain string :
     * matches at the start : ok
     * does not match in the middle : ok
     * does not match at the end : ok
     * performs case insensitive match : ok
     * ignores whitespaces around the search value : ok
     * does not match if substring is not found : ok
   - search in string with special RegExp chars :
     * matches at the start : ok
     * does not match in the middle : ok
     * does not match at the end : ok
     * performs case insensitive match : ok
     * ignores whitespaces around the search value : ok
     * does not match if substring is not found : ok
 - Awesomplete.SORT_BYLENGTH :
   * is a function : ok
   - with strings of different length :
     * returns negative number if the first string is shorter : ok
     * returns positive number if the first string is longer : ok
   - with strings of the same length :
     * returns -1 if the first string < second string : ok
     * returns 1 if the first string > second string : ok
     * returns 1 if the first string == second string : ok

Browser results:

 - Chrome 46.0.2490 (Mac OS X 10.11.1): 198 tests
   - 197 ok, 1 skipped

This was referenced Nov 25, 2015
@vlazar
Copy link
Collaborator Author

vlazar commented Nov 29, 2015

Added code coverage reporting via Code Climate in #16792, which you might consider merging before this PR in order to check out code coverage improvement on Code Climate.

@vlazar
Copy link
Collaborator Author

vlazar commented Dec 15, 2015

Ping :)
With this PR and #16792 merged in it would be safer and easier to merge other PRs.

@@ -46,7 +46,7 @@ var _ = function (input, o) {
});

this.ul = $.create("ul", {
hidden: "",
hidden: "hidden",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$.create when working with attributes would do:

element['hidden'] = '';

Which is for boolean attribute would be the same as:

element['hidden'] = false;

So completer would not be hidden by default.

I don't remember why I didn't used hidden: false here. Maybe there was some bug with it. I'll check this later.

@LeaVerou
Copy link
Owner

Awesome, thank you so much!!! Merging now, sorry it took so long.

LeaVerou added a commit that referenced this pull request Dec 27, 2015
@LeaVerou LeaVerou merged commit 9af4a6e into LeaVerou:gh-pages Dec 27, 2015
@vlazar
Copy link
Collaborator Author

vlazar commented Dec 28, 2015

Thanks @LeaVerou

I've updated test for newly merged features. See #16804
And resolved conflicts in #16792.

@vlazar vlazar deleted the features/improve-test-coverage branch January 29, 2016 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants