Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit ee534d4

Browse files
author
Gabriel Schulhof
committed
Listview: Test refresh() _addClass() call sequence
1 parent 17c5879 commit ee534d4

File tree

5 files changed

+83
-4
lines changed

5 files changed

+83
-4
lines changed

tests/integration/listview/backcompat-tests.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
<li>Item 2</li>
3535
</ul>
3636
</div>
37+
38+
<ul id="sparing-check" data-nstest-role="listview">
39+
<li id="sparing-check-first-item">Item 1</li>
40+
<li id="sparing-check-second-item">Item 2</li>
41+
</ul>
3742
</div>
3843
</body>
3944
</html>

tests/integration/listview/backcompat_core.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
define( [
22
"qunit",
3-
"jquery"
4-
], function( QUnit, $ ) {
3+
"jquery",
4+
"../tests/integration/listview/sparing-setup-teardown"
5+
], function( QUnit, $, sparingSetupTeardown ) {
56

67
var helper = $.testHelper;
78

@@ -106,4 +107,17 @@ QUnit.test( "Turning on class ui-shadow", function( assert ) {
106107
"Option shadow is true whenever ui-shadow is present in ui-listview-inset" );
107108
} );
108109

110+
QUnit.module( "Sparingness of refresh()", sparingSetupTeardown );
111+
112+
QUnit.test( "refresh()", function( assert ) {
113+
assert.expect( 2 );
114+
115+
this.listview.refresh();
116+
117+
assert.strictEqual( this.calls[ 1 ][ 0 ].length, 1,
118+
"One element was passed to _addClass()" );
119+
assert.deepEqual( this.calls[ 1 ][ 0 ].get( 0 ), this.newItem[ 0 ],
120+
"The single item in the call is as expected" );
121+
} );
122+
109123
} );

tests/integration/listview/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@
180180
</a>
181181
</li>
182182
</ul>
183+
184+
<ul data-ui-role="listview" id="sparing-check">
185+
<li id="sparing-check-first-item">Item 1</li>
186+
<li id="sparing-check-second-item">Item 2</li>
187+
</ul>
183188
</div>
184189
</div>
185190

tests/integration/listview/listview_core.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
// TODO split out into separate test files
66
define( [
77
"qunit",
8-
"jquery"
9-
], function( QUnit, $ ) {
8+
"jquery",
9+
"../tests/integration/listview/sparing-setup-teardown"
10+
], function( QUnit, $, sparingSetupTeardown ) {
1011

1112
QUnit.module( "Basic Linked list" );
1213

@@ -458,4 +459,34 @@ QUnit.test( "basic pre-enhanced listview", function( assert ) {
458459
"Listview refresh() enhances new items" );
459460
} );
460461

462+
QUnit.module( "Sparingness of refresh() and updateItems()", sparingSetupTeardown );
463+
464+
QUnit.test( "refresh()", function( assert ) {
465+
assert.expect( 5 );
466+
467+
this.listview.refresh();
468+
469+
assert.strictEqual( this.calls[ 0 ][ 0 ].length, 3,
470+
"Three elements were passed to _addClass()" );
471+
assert.strictEqual( this.calls[ 0 ][ 1 ], "ui-listview-item ui-listview-item-static",
472+
"Class ui-listview-item-static was assigned" );
473+
assert.strictEqual( this.calls[ 0 ][ 0 ].first().attr( "id" ), "sparing-check-first-item",
474+
"The first item in the call is as expected" );
475+
assert.deepEqual( this.calls[ 0 ][ 0 ].get( 1 ), this.newItem[ 0 ],
476+
"The second item in the call is as expected" );
477+
assert.strictEqual( this.calls[ 0 ][ 0 ].last().attr( "id" ), "sparing-check-second-item",
478+
"The last item in the call is as expected" );
479+
} );
480+
481+
QUnit.test( "updateItems()", function( assert ) {
482+
assert.expect( 2 );
483+
484+
this.listview.updateItems( this.newItem );
485+
486+
assert.strictEqual( this.calls[ 0 ][ 0 ].length, 1,
487+
"One element was passed to _addClass()" );
488+
assert.deepEqual( this.calls[ 0 ][ 0 ].get( 0 ), this.newItem[ 0 ],
489+
"The single item in the call is as expected" );
490+
} );
491+
461492
} );
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
define( [ "jquery" ], function( $ ) {
2+
3+
return {
4+
setup: function() {
5+
var that = this;
6+
7+
this.template = $( "#sparing-check" ).clone();
8+
this.listview = $( "#sparing-check" ).listview().listview( "instance" );
9+
this.newItem = $( "<li>Something</li>" ).insertAfter( "#sparing-check-first-item" );
10+
this.calls = [];
11+
this._addClass = $.mobile.listview.prototype._addClass;
12+
13+
$.mobile.listview.prototype._addClass = function() {
14+
that.calls.push( arguments );
15+
return that._addClass.apply( this, arguments );
16+
};
17+
},
18+
teardown: function() {
19+
$( "#sparing-check" ).before( this.template ).remove();
20+
$.mobile.listview.prototype._addClass = this._addClass;
21+
}
22+
};
23+
24+
} );

0 commit comments

Comments
 (0)