Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
While this PR may seem a bit overwhelming judging from the number of files / lines added and removed... please take a moment to understand why.
It is a complete refactoring of all tests to make them a little DRY'er... well a lot I guess since it's only a bit over one third of the original code in size despite adding more comments.
It is a direct reaction to the last comment @koenpunt made in #2899
The tests are exactly the same as in current master.
How
The main idea is that tests that can be shared between prototype and jquery versions should be shared... Just like the Chosen "abstract" itself. As it turns out all (current) tests except the very first one actually can.
So I've written three functions for each "version":
fw_basictest
The very basic test to check for the Chosen global / jQuery functionfw
A wrapper around the needed jQuery / prototype functions that allow access to them through a common interfacefw_testcase
A function to initialize the many Chosen drops used in the tests and return an object with references to the most commonly used elementsThese three functions take up about 50 lines for each jQuery and prototype. The rest of the code is shared. If more "specialty" functions are needed in the future they can (probably) quite easily be added to the
fw
wrapperI've also added two shared helper functions that make it possible to both initialize and do common tasks with a lot less code - so it's clearer what is actually being tested:
testcase_html
constructs the actual html for most tests from an array or object.testcase
initiates each test by callingtestcase_html
, thenfw_testcase
and finally adds common functions likeopen_drop
,click_result
,set_search
and so on to this object before returning.This means that every test can now go something like:
...which I hope everyone will agree is more readable than before. Of course the biggest advantage is that this test works for both jquery and prototype.
For some tests the simple array is not enough, so it can accept an object instead:
For cases that need optgroups or other "advanced" markup, we can still pass the HTML directly:
I'm expecting someone to argue that it is harder to know what actually happens, since everything passes through "layers" instead of being right there in the code for anyone to see... For example I'm not 100% sure the helper that constructs the HTML is actually a good idea... It might be easier for someone else to add a new test if every test simply starts with the "plain" HTML needed for that specific case.
On the other hand I don't have any doubt that having only one set of actual tests to maintain is a huge advantage - both for maintainers and "new" contributors like myself.
package.json
.References
Just the one mentioned above: #2899