define(
    [ 'jQuery', 'asyncSeries', 'testUtilities' ],
    function ($$, asyncSeries, utilities) {


        module("SCV-222 |SCV-1445 - Ability to navigate from page to page retaining the same sort order,");
        test('SCV-1446 - Validate the pagination', function () {
	        ok(true, "The tests are running.");

	        $(window).load(function () {
	            asyncSeries(function () {
	                afterElementLoad($("#calendar-specialty-input"), function () {
	                    ok($('#left-navigation').is(':visible'),
	                        "Header is visible");
	                });

	                // Then I can see the header info
	                ok($('#left-navigation:contains("Open Menu")').text(),
	                    "Then I can see the header bar");
	                return 500;
	            }, function () {
	                ok($("#inner-content p:contains('Please select a Service/Specialty and Clinic to view availability.')")
	                        .text(),
	                    'Select Service/Specialty and Clinic to display calendar');
	                // Select Service/Specialty and Clinic to
	                // show calendar
	                $("#calendar-specialty-input").val('General')
	                    .keyup();
	                $("#calendar-specialty li:nth-child(4) a")
	                    .trigger('tap');

	                $('#calendar-clinic-button')
	                    .trigger('click');

	                // Select Clinic
	                $("#calendar-clinic-menu label").eq(0)
	                    .trigger('click');

	            }, function () {
	                // Click View Availability to display the
	                // calendar
	                $("#appointment-button a").trigger('tap');
	                afterElementLoad($("#calendar"), function () {
	                    ok($("#calendar")
	                            .is(':visible'),
	                        'Calendar is visible');
	                });
	            }, function () {

	                //Go to Wait List tab on the footer
	                $('#footer-waitlist-btn').trigger('tap');
	                return 500;
	            }, function () {
	                afterElementLoad($("#ewl"), function () {
	                    ok($("#ewl").is(':visible'),
	                        "EWL table visible");
	                });
	                //EWL, NEAR and Recall
	                equal($("#ewl h3:contains('EWL')").length > 0, true, 'EWL section');
	                equal($("#near h3:contains('NEAR')").length > 0, true, 'NEAR section');
	                equal($("#recall h3:contains('Recall')").length > 0, true, 'Recall section');

	                //Validate the pagination for EWL table
	                equal($("#ewl").find('button').eq(0).hasClass('first paginate_button'), true, 'First button to navigate');
	                equal($("#ewl").find('button').eq(1).hasClass('previous paginate_button'), true, 'Previous button to navigate');
	                equal($("#ewl").find('button').eq(2).hasClass('paginate_active'), true, 'Page number that is currently active');
	                equal($("#ewl").find('button').eq(3).hasClass('next paginate_button'), true, 'Next button to navigate');
	                equal($("#ewl").find('button').eq(4).hasClass('last paginate_button'), true, 'Last button to navigate');
	                ok($("#ewl").find('div').eq(10).text(), 'Showing');

	                //Expand the Near table and validate pagination
	                $("#near h3").trigger('click');
	                equal($("#near h3").hasClass('ui-collapsible-heading-collapsed'), false, 'NEAR section expanded');

	                //Validate the pagination for EWL table
	                equal($("#near").find('button').eq(0).hasClass('first paginate_button'), true, 'First button to navigate');
	                equal($("#near").find('button').eq(1).hasClass('previous paginate_button'), true, 'Previous button to navigate');
	                equal($("#near").find('button').eq(2).hasClass('paginate_active'), true, 'Page number that is currently active');
	                equal($("#near").find('button').eq(3).hasClass('next paginate_button'), true, 'Next button to navigate');
	                equal($("#near").find('button').eq(4).hasClass('last paginate_button'), true, 'Last button to navigate');
	                ok($("#near").find('div').eq(10).text(), 'Showing');

	                //Expand the Near table and validate pagination
	                $("#recall h3").trigger('click');
	                equal($("#recall h3").hasClass('ui-collapsible-heading-collapsed'), false, 'Recall section expanded');

	                //Validate the pagination for EWL table
	                equal($("#recall").find('button').eq(0).hasClass('first paginate_button'), true, 'First button to navigate');
	                equal($("#recall").find('button').eq(1).hasClass('previous paginate_button'), true, 'Previous button to navigate');
	                equal($("#recall").find('button').eq(2).hasClass('paginate_active'), true, 'Page number that is currently active');
	                equal($("#recall").find('button').eq(3).hasClass('next paginate_button'), true, 'Next button to navigate');
	                equal($("#recall").find('button').eq(4).hasClass('last paginate_button'), true, 'Last button to navigate');
	                ok($("#recall").find('div').eq(10).text(), 'Showing');

	                //Go to consults page and validate pagination
	                $("#footer-consults-btn").trigger('tap');
	                return 500;
	            }, function () {
	                afterElementLoad($("#consults-filter"), function () {
	                    ok($("#consults-filter").is(':visible'),
	                        'Consults page is visible');
	                });
	                // show calendar
	                $("#service-specialty-input").val('Gastro')
	                    .keyup();
	                $("#service-specialty li:nth-child(24) a")
	                    .trigger('tap');

	                return 800;

	            }, function () {
	                // Consults table is loaded
	                afterElementLoad($("#consults-filter-table"), function () {
	                    ok($("#consults-filter-table").is(':visible'),
	                        'Consults table is visible');
	                });

	                //Validate the consults table
	                //Validate the pagination for EWL table
	                equal($("#consults-filter").find('button').eq(0).hasClass('first paginate_button'), true, 'First button to navigate');
	                equal($("#consults-filter").find('button').eq(0).hasClass('paginate_button_disabled'), true, 'First button disabled');
	                equal($("#consults-filter").find('button').eq(1).hasClass('previous paginate_button'), true, 'Previous button to navigate');
	                equal($("#consults-filter").find('button').eq(1).hasClass('paginate_button_disabled'), true, 'Previous button disabled');
	                equal($("#consults-filter").find('button').eq(2).hasClass('paginate_active'), true, 'Page number that is currently active');
	                equal($("#consults-filter").find('button').eq(3).hasClass('next paginate_button'), true, 'Next button to navigate');
	                equal($("#consults-filter").find('button').eq(4).hasClass('last paginate_button'), true, 'Last button to navigate');
	                ok($("#consults-filter").find('div').eq(10).text(), 'Showing');

	                //Validate that sort is retained even when navigating to next page of consults
	                equal($("#consults-filter-table").find('th').eq(3).attr('aria-sort'),
	                    'descending', 'Days column descending');
	                //Click Next page button
	                $("#consults-filter").find('button').eq(3).trigger('click');

	                //Validate the pagination and sort
	                equal($("#consults-filter-table").find('th').eq(3).attr('aria-sort'),
	                    'descending', 'Days column descending');
	                equal($("#consults-filter").find('button').eq(2).hasClass('paginate_active'), true, 'Page number that is currently active');
	                equal($("#consults-filter").find('button').eq(3).hasClass('paginate_button_disabled'), true, 'Next button disabled');
	                equal($("#consults-filter").find('button').eq(4).hasClass('paginate_button_disabled'), true, 'Last button disabled');

	                //Change sorting to different column and validate the pagination
	                $("#consults-filter-table").find('th').eq(2).trigger('click');
	                return 800;
	            }, function () {
	                equal($("#consults-filter-table").find('th').eq(2).attr('aria-sort'),
	                    'ascending', 'Order Date column ascending');
	                equal($("#consults-filter").find('button').eq(0).hasClass('first paginate_button paginate_button_disabled'), true, 'First button disabled');
	            });
	        });
        });
    });
//});