Skip to content

Commit

Permalink
Add tests for #310. Fixes #311
Browse files Browse the repository at this point in the history
  • Loading branch information
Robdel12 committed Apr 24, 2016
1 parent 4cb8e3a commit b966ffa
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 133 deletions.
2 changes: 1 addition & 1 deletion build/js/dropkick.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ gulp.task('docs-move-api', function() {
gulp.task('test', function() {
//TODO: fix
// return gulp.src(['./tests/src/runner.html', './tests/src/iframe.html'])
return gulp.src(['./tests/src/runner.html'])
return gulp.src(['./tests/src/runner.html', './tests/src/runner_mobile.html'])
.pipe(qunit());
});
8 changes: 5 additions & 3 deletions lib/dropkick.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,9 @@ Dropkick.prototype = {
* ```
*/
refresh: function() {
this.dispose().init( this.data.select, this.data.settings );
if(Object.keys(this).length > 0 && !( isMobile && !this.data.settings.mobile )) {
this.dispose().init( this.data.select, this.data.settings );
}
},

/**
Expand All @@ -961,8 +963,8 @@ Dropkick.prototype = {
* ```
*/
dispose: function() {
delete Dropkick.cache[ this.data.cacheID ];
if (!( isMobile && !this.data.settings.mobile )) {
if (Object.keys(this).length > 0 && !( isMobile && !this.data.settings.mobile )) {
delete Dropkick.cache[ this.data.cacheID ];
this.data.elem.parentNode.removeChild( this.data.elem );
this.data.select.removeAttribute( "data-dkCacheId" );
}
Expand Down
256 changes: 128 additions & 128 deletions tests/src/runner_mobile.html
Original file line number Diff line number Diff line change
@@ -1,131 +1,131 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>DropKick tests</title>
<link rel="stylesheet" href="qunit-1.14.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<button id="btn">Open</button>
<select id="normal_select">
<option disabled selected class="hidden-option">Choose One</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
<select multiple id="multiple">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
<script>
// Fake the UA before DK is loaded
navigator.__defineGetter__('userAgent', function(){
    return 'Android' // fake mobile
});
</script>
<script src="../../build/js/dropkick.min.js"></script>
<script src="jquery-1.11.2.js"></script>
<script src="qunit-1.14.0.js"></script>
<script src="../unit/tests_mobile.js"></script>
</body>
<head>
<meta charset="utf-8">
<title>DropKick tests</title>
<link rel="stylesheet" href="../../node_modules/qunitjs/qunit/qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<button id="btn">Open</button>
<select id="normal_select">
<option disabled selected class="hidden-option">Choose One</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
<select multiple id="multiple">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</div>
<script>
// Fake the UA before DK is loaded
navigator.__defineGetter__('userAgent', function(){
return 'Android'; // fake mobile
});
</script>
<script src="../../build/js/dropkick.min.js"></script>
<script src="jquery-1.11.2.js"></script>
<script src="../../node_modules/qunitjs/qunit/qunit.js"></script>
<script src="../unit/tests_mobile.js"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions tests/unit/tests_mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ QUnit.test( "Dropkick methods should still work when not rendered on mobile", 3,
assert.notEqual($sel.attr("data-dkCacheId"), dk.data.cacheID + '');

dk.select(2); //2 = Alaska
dk.refresh();

assert.equal($sel.val(), dk.value);
});

QUnit.test( "Dropkick shouldn't blow up when calling methods on mobile: false dks", 1, function( assert ) {
var $sel = $("#normal_select", {mobile: false}),
dk = new Dropkick($sel[0]);

assert.equal(navigator.userAgent, "Android");

dk.refresh();
});

0 comments on commit b966ffa

Please sign in to comment.