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

        function afterElementLoad($element, callback) {
            if (typeof $element === 'undefined') {
                setTimeout(function () {
                    afterElementLoad($element, callback);
                }, 1000);
            } else {
                callback();
            }
        }

        module("#SCV47/#SCV16 - Patient EWL can see a list of fields on the summary list");
        test('#43 - a.Validate the footer', function () {
            // Given I am on the Scheduling app
	        ok(true, "The tests are running.");

	        $(window).load(function () {
	            asyncSeries(function () {
	                afterElementLoad($("#calendar-specialty-input"), function () {

	                    ok($('.ui-title').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 1500;

	                // Validate the footer
	            },
	            function () {
	                ok($('#footer-booking-btn .ui-btn-text:contains("Booking")'),
	                    'Booking',
	                    'Booking button is  displayed');
	                ok($('#footer-wait-list-btn .ui-btn-text:contains("Wait List")'),
	                    'Wait List',
	                    'Wait List button is  displayed');
	                ok($('#footer-consults-btn .ui-btn-text:contains("Consults")'),
	                    'Consults',
	                    'Consults button is  displayed');
	                ok($('#footer-veteran-requests-btn .ui-btn-text:contains("Veteran Requests")'),
	                    'Veteran Requests', 'Veteran Requests button is  displayed');
	                ok($('#footer-more-btn .ui-btn-text:contains("More")'),
	                    'More', 'More button is  displayed');

	            });
	        });
        });


        module("#SCV47/#SCV13 - Patient EWL can see a list of fields for Patient Details");

        // Validate wait list section for a single patient
        test('#35 - Validate WL details for Patient', function () {
            asyncSeries(function () {
	            return 1000;
            }, function () {
                afterElementLoad($("#calendar-specialty-input"), function () {
                    $(window).load(function () {
                        ok($('.ui-title').is(':visible'),
                            "Header is visible");
                    });
                });
                // Then I can see the header info
            }, function () {
                // Then I can see the header info
                ok($('#left-navigation:contains("Open Menu")').text(),
                    "Then I can see the header bar");
            }, function () {
                $(window).load(function () {
                    ok($("#inner-content").find('p').text(),
                        'Please select a Service/Specialty and Clinic to view availability.');
                    // Search and select a patient
                    var e = $.Event("keypress");
                    e.which = 13; // # Some key
                    // code value
                    e.keyCode = 13;
                    $("#patient-search-input").val(
                        '666000004')
                        .trigger(e);
                    $('#patient-search-results li:nth-child(2) a')
                        .trigger('tap');
                    afterElementLoad($("#patient-button:not(.ui-disabled)"),
                        function () {
                            $('#patient-button').trigger('tap');
                            ok($("#future-appointments-table").is(':visible'),
                                'Future Appointments table is visible');
                        });
                    //SCV-20:Validate default sort order
                    $("#waitlist h3").trigger('click');
                    ok($("#waitlist-table").find('th').eq(2).text(), 'Date', 'Date column is the default sort');
                    equal($("#waitlist-table").find('th').eq(2).attr('aria-sort'),
                        'descending', 'Default sort is descending');
                    //validate the column headers
                    ok($("#waitlist-table").find('th').eq(0).text(), 'Source List', 'Source List-1st column');
                    ok($("#waitlist-table").find('th').eq(1).text(), 'Clinic / Specialty', 'Clinic / Specialty-2nd column');
                    ok($("#waitlist-table").find('th').eq(2).text(), 'Days', 'Days-3rd column');
                    ok($("#waitlist-table").find('th').eq(3).text(), 'Desired Date', 'Desired Date-4th column');

                    //Expand the Wait List section

                    $('#waitlist-table tr:nth-child(1)').trigger('tap');
                    return 500;
                });
            }, function () {
                $(window).load(function () {
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Clinic', 'Clinic is displayed');
                    ok($("#inner-content").find('li').eq(1).find('span').eq(0).text(), 'Stop Code', 'Stop Code is displayed');
                    ok($("#inner-content").find('li').eq(2).find('span').eq(0).text(), 'Desired Date of Appointment', 'Desired Date of Appointment is displayed');
                    ok($("#inner-content").find('li').eq(3).find('span').eq(0).text(), 'Date Entered', 'Date Entered is displayed');
                    ok($("#inner-content").find('li').eq(4).find('span').eq(0).text(), 'Days on EWL', 'Days on EWL is displayed');
                    ok($("#inner-content").find('li').eq(5).find('span').eq(0).text(), 'Service Connected', 'Service Connected is displayed');
                    ok($("#inner-content").find('li').eq(6).find('span').eq(0).text(), 'Priority', 'Priority is displayed');
                    //ok($("#inner-content").find('li').eq(7).find('span').eq(0).text(),'Last Updated','Last Updated is displayed');
                    //ok($("#inner-content").find('li').eq(8).find('span').eq(0).text(),'Last Name','Last Name is displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'SSN', 'SSN is displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Enrollee Status', 'Enrollee Status');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Zip Code', 'Zip Code is displayed');
                });
            });
        });
    });
//});
