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

Commit

Permalink
Table: Add individual-modules tests for reflow and columntoggle
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Schulhof committed May 16, 2014
1 parent ff36efd commit d9c44a4
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
91 changes: 91 additions & 0 deletions tests/unit/individual-modules/table-tests.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Collapsible Test Suite</title>

<script src="../../../external/requirejs/require.js"></script>
<script src="../../../js/requirejs.config.js"></script>
<script src="../../../js/jquery.tag.inserter.js"></script>
<script src="../../../tests/jquery.testHelper.js"></script>

<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css"/>
<link rel="stylesheet" href="../../../external/qunit/qunit.css"/>
<link rel="stylesheet" href="../../jqm-tests.css"/>
<script src="../../../external/qunit/qunit.js"></script>
<script>
$.testHelper.asyncLoad([
[
"widgets/table.reflow",
"widgets/table.columntoggle"
],
[
"../../jquery.setNameSpace.immediately.js"
],
[
"table_core.js"
]
]);
</script>

<script src="../../swarminject.js"></script>
</head>
<body>
<div id="qunit"></div>

<table id="reflow-test" data-nstest-mode="reflow">
<thead>
<tr>
<th>Name</th>
<th>Color</th>
<th>Shape</th>
</tr>
</thead>
<tbody>
<tr>
<td>Orange</td>
<td>Orange</td>
<td>Round</td>
</tr>
<tr>
<td>Watermelon</td>
<td>Green</td>
<td>Oval</td>
</tr>
<tr>
<td>Banana</td>
<td>Yellow</td>
<td>Sickle</td>
</tr>
</tbody>
</table>

<table id="columntoggle-test" data-nstest-mode="columntoggle">
<thead>
<tr>
<th data-nstest-priority="permanent">Name</th>
<th data-nstest-priority="1">Color</th>
<th data-nstest-priority="2">Shape</th>
</tr>
</thead>
<tbody>
<tr>
<td>Orange</td>
<td>Orange</td>
<td>Round</td>
</tr>
<tr>
<td>Watermelon</td>
<td>Green</td>
<td>Oval</td>
</tr>
<tr>
<td>Banana</td>
<td>Yellow</td>
<td>Sickle</td>
</tr>
</tbody>
</table>
</body>
</html>
53 changes: 53 additions & 0 deletions tests/unit/individual-modules/table_core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
test( "Reflow table is enhanced correctly", function() {
var table = $( "#reflow-test" ).table();

deepEqual( table.hasClass( "ui-table" ), true, "Table has class 'ui-table'" );
deepEqual( table.hasClass( "ui-table-reflow" ), true, "Table has class 'ui-table-reflow'" );
deepEqual(
table
.children( "thead" )
.children()
.children()
.is( table.children( "thead" )
.children()
.children( "[data-" + $.mobile.ns + "colstart]" ) ), true,
"All thead cells have the '[data-colstart]' attribute" );
deepEqual( table.children( "tbody" ).children().children().is( function() {
return ( $( this ).children( "b.ui-table-cell-label" ).length !== 1 );
}), false, "All tbody cells have a bold child with class ui-table-cell-label" );
});

test( "Columntoggle table is enhanced correctly", function() {
var table = $( "#columntoggle-test" ).table(),
correctPriorities = true;

deepEqual( table.hasClass( "ui-table" ), true, "Table has class 'ui-table'" );
deepEqual( table.hasClass( "ui-table-columntoggle" ), true,
"Table has class 'ui-table-column-toggle'" );
deepEqual( $( "a[href='#columntoggle-test-popup']#columntoggle-test-button" ).length, 1,
"A button with id 'columntoggle-test-button' and href='#columntoggle-test-popup' exists" );
deepEqual( $( "#columntoggle-test-popup:data(mobile-popup)" ).length, 1,
"A popup widget with id 'columntoggle-test-popup' exists" );

// Try to find incorrectly assigned priority classes
table.children( "thead" ).children().children().each( function( index ) {
var cell = $( this ),
priority = cell.attr( "data-" + $.mobile.ns + "priority" );

if ( priority ) {
correctPriorities =
( table
.children( "tbody" )
.children()
.children( ":nth(" + index + ")" )
.filter( ":not(.ui-table-priority-" + priority + ")" ).length === 0 );
}

// If incorrect priorities have been identified, stop .each()-ing
return correctPriorities;
});

deepEqual( correctPriorities, true,
"All tbody cells have priority classes assigned in accordance with their header " +
"'data-priority' value" );
});

0 comments on commit d9c44a4

Please sign in to comment.