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

        /*function patientSelect(name) {
         // This method is used by patient viewer to search and select a
         // patient before proceeding
         if (window.location.href.indexOf('scheduling-manager')) {
         var e = $.Event("keypress"), $input = $("#patient-search-input");
         e.which = e.keyCode = 13;
         $input.val(name).trigger(e);

         }
         }*/

        module("SCV47,SCV-357, SCV-358,SCV-71, SCV-53, SCV-82 |SCV16, SCV-13, SCV170, SCV-171,SCV-473, SCV-476, SCV-169, SCV-732, SCV-733, SCV-734, SCV-741,SCV-742- WL,NEAR and Recall entries for Patient, Sort order, Near and Recall details, Book Apptment button");
        test('SCV-483 - Validate NEAR and recall entries for patient', function () {
            ok(true, "The tests are running");

            $(window).load(function () {
                asyncSeries(slotsGenMed1,
                    fourPatient1,
                    fourPatientinfo,
                    bookedAppts1,
                    fourPatientWl1,
                    facRecall1,
                    facNear1,
                    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");
                    }, 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');
                        });
                        // Search and select a patient
                        var e = $.Event("keypress");
                        e.which = 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
                        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');

                        //Validate that each column is sortable
                        // Days - default is descending, click to sort ascending
                        equal($("#waitlist-table").find('th').eq(2).attr('aria-sort'),
                            'descending', 'Days column descending');
                        $("#waitlist-table").find('th').eq(2).trigger('click');
                        equal($("#waitlist-table").find('th').eq(2).attr('aria-sort'),
                            'ascending', 'Days column ascending');
                        //Source List column - ascending
                        $("#waitlist-table").find('th').eq(0).trigger('click');
                        equal($("#waitlist-table").find('th').eq(0).attr('aria-sort'),
                            'ascending', 'Source List ascending');
                        //Source List column - descending
                        $("#waitlist-table").find('th').eq(0).trigger('click');
                        equal($("#waitlist-table").find('th').eq(0).attr('aria-sort'),
                            'descending', 'Source List descending');
                        //Clinic/ Specialty column - ascending
                        $("#waitlist-table").find('th').eq(1).trigger('click');
                        equal($("#waitlist-table").find('th').eq(1).attr('aria-sort'),
                            'ascending', 'Service/Specialty ascending');
                        //Clinic/ Specialty column - descending
                        $("#waitlist-table").find('th').eq(1).trigger('click');
                        equal($("#waitlist-table").find('th').eq(1).attr('aria-sort'),
                            'descending', 'Clinic/ Specialty descending');
                        //Desired Date column - ascending
                        $("#waitlist-table").find('th').eq(3).trigger('click');
                        equal($("#waitlist-table").find('th').eq(3).attr('aria-sort'),
                            'ascending', 'Desired Date ascending');
                        //Desired Date column - descending
                        $("#waitlist-table").find('th').eq(3).trigger('click');
                        equal($("#waitlist-table").find('th').eq(3).attr('aria-sort'),
                            'descending', 'Desired Date descending');


                        //Select NEAR appointment meta data to display details
                        // Search and select a patient
                        /*var e = $.Event("keypress");
                         e.which = 13; // # Some key
                         // code value
                         e.keyCode = 13;*/
                        $("#patient-search-input").val(
                            'graphingpatientdemo')
                            .trigger(e);
                        $('#patient-search-results li:nth-child(2) a')
                            .trigger('tap');
                        afterElementLoad($("#waitlist"),
                            function () {
                                ok($("#waitlist").is(':visible'),
                                    'Wait List table is visible');
                            });
                        //Expand the wait list table
                        $("#waitlist h3").trigger('click');
                        return 200;
                    }, function () {
                        $("#waitlist-table").find('tr').eq(1).trigger('tap');
                        return 500;
                    }, function () {
                        ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Patient Name', 'Patient Name displayed');
                        ok($("#inner-content").find('li').eq(1).find('span').eq(0).text(), 'SSN', 'SSN displayed');
                        ok($("#inner-content").find('li').eq(2).find('span').eq(0).text(), 'Cell Phone', 'Cell Phone displayed');
                        ok($("#inner-content").find('li').eq(3).find('span').eq(0).text(), 'Home Phone', 'Home Phone displayed');
                        ok($("#inner-content").find('li').eq(4).find('span').eq(0).text(), 'Facility', 'Facility displayed');
                        ok($("#inner-content").find('li').eq(5).find('span').eq(0).text(), 'Service Connected', 'Service Connected displayed');
                        ok($("#inner-content").find('li').eq(6).find('span').eq(0).text(), 'Request Date', 'Request Date displayed');

                        //Validate that clicking on Book Appointment shows the calendar
                        $("#process-request").trigger('click');
                        return 700;
                    }, function () {
                        equal($("#calendar").is(':visible'), true, 'Calendar is visible');

                        //Select Recall appointment meta data to display details
                        // Search and select a patient
                        var e = $.Event("keypress");
                        e.which = 13; // # Some key
                        // code value
                        e.keyCode = 13;
                        $("#patient-search-input").val(
                            'bcmademo,eighteen-patient')
                            .trigger(e);
                        $('#patient-search-results li:nth-child(2) a')
                            .trigger('tap');
                        afterElementLoad($("#patient-button:not(.ui-disabled)"),
                            function () {
                                $('#patient-button').trigger('tap');
                                ok($("#waitlist").is(':visible'),
                                    'Wait List table is visible');
                            });
                        //Expand the wait list table
                        $("#waitlist h3").trigger('click');
                        return 200;
                    }, function () {
                        $("#waitlist-table").find('tr').eq(1).trigger('tap');
                        return 500;
                    }, function () {
                        ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Clinic', 'Clinic displayed');
                        ok($("#inner-content").find('li').eq(1).find('span').eq(0).text(), 'Accession Number', 'Accession Number displayed');
                        ok($("#inner-content").find('li').eq(2).find('span').eq(0).text(), 'Appointment Length', 'Appointment Length displayed');
                        ok($("#inner-content").find('li').eq(3).find('span').eq(0).text(), 'Patient Name', 'Patient Name displayed');
                        ok($("#inner-content").find('li').eq(4).find('span').eq(0).text(), 'Fasting', 'Fasting displayed');
                        ok($("#inner-content").find('li').eq(5).find('span').eq(0).text(), 'Recall Date', 'Recall Date displayed');
                        ok($("#inner-content").find('li').eq(6).find('span').eq(0).text(), 'Recall Date 1', 'Recall Date 1 displayed');
                        ok($("#inner-content").find('li').eq(7).find('span').eq(0).text(), 'Comments', 'Comments displayed');

                        //Validate that clicking on Book Appointment shows the calendar
                        $("#process-request").trigger('click');
                        return 500;
                    }, function () {
                        equal($("#calendar").is(':visible'), true, 'Calendar is visible');
                    });

            });
        });


    });
