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


        module("SCV-356, SCV-359 |SCV-169,SCV-471,SCV-472,SCV-474,SCV-475,SCV-735,SCV-738 - All columns are sortable, NEAR-Default sort, NEAR-Meta data column headers, Recall-Default sort, Recall-Meta data column headers,");
        test('SCV-454 - Validate the NEAR and Recall list entries for facility', function () {
            ok(true, "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 1500;
                }, 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 NEAR section
                    //By default the section is collapsed
                    equal($("#near h3").hasClass('ui-collapsible-heading-collapsed'), true, 'NEAR section collapsed');
                    //Section header displays record count
                    equal($("#near h3").find('span').eq(1).find('span').eq(0).hasClass('ctn-count'), true, 'Section header has record count');
                    //Click to expand the section
                    $("#near h3").trigger('click');
                    equal($("#near h3").hasClass('ui-collapsible-heading-collapsed'), false, 'NEAR section expanded');

                    //Validate the Column names within the NEAR table
                    ok($("#near-table").find('th').eq(0).text(), 'Patient', '1st column');
                    ok($("#near-table").find('th').eq(1).text(), 'Service Connected', '2nd column');
                    ok($("#near-table").find('th').eq(2).text(), 'Request Date', '1st column');

                    //Validate that each column is sortable
                    //Originating Date column - default is ascending, click to sort descending
                    equal($("#near-table").find('th').eq(2).attr('aria-sort'),
                        'ascending', 'Request Date column ascending');
                    $("#near-table").find('th').eq(2).trigger('click');
                    equal($("#near-table").find('th').eq(2).attr('aria-sort'),
                        'descending', 'Request Date descending');
                    //Patient Name column - ascending
                    $("#near-table").find('th').eq(0).trigger('click');
                    equal($("#near-table").find('th').eq(0).attr('aria-sort'),
                        'ascending', 'Patient Name ascending');
                    //Patient Name column - descending
                    $("#near-table").find('th').eq(0).trigger('click');
                    equal($("#near-table").find('th').eq(0).attr('aria-sort'),
                        'descending', 'Patient Name descending');
                    //Service Connected column - ascending
                    $("#near-table").find('th').eq(1).trigger('click');
                    equal($("#near-table").find('th').eq(1).attr('aria-sort'),
                        'ascending', 'Service Connected ascending');
                    //Service Connected column - descending
                    $("#near-table").find('th').eq(1).trigger('click');
                    equal($("#near-table").find('th').eq(1).attr('aria-sort'),
                        'descending', 'Service Connected descending');

                    //**************************************************//

                    //Validating Recall Section
                    //By default the section is collapsed
                    equal($("#recall h3").hasClass('ui-collapsible-heading-collapsed'), true, 'Recall section collapsed');
                    //Section header displays record count
                    equal($("#recall h3").find('span').eq(1).find('span').eq(0).hasClass('ctn-count'), true, 'Section header has record count');
                    //Click to expand the section
                    $("#recall h3").trigger('click');
                    equal($("#recall h3").hasClass('ui-collapsible-heading-collapsed'), false, 'Recall section expanded');

                    //Validate the Column names within the NEAR table
                    ok($("#recall-table").find('th').eq(0).text(), 'Patient', '1st column');
                    ok($("#recall-table").find('th').eq(1).text(), 'Clinic', '2nd column');
                    ok($("#recall-table").find('th').eq(2).text(), 'Recall Date', '1st column');

                    //Validate that each column is sortable
                    //Recall Date column - default is ascending, click to sort descending
                    equal($("#recall-table").find('th').eq(2).attr('aria-sort'),
                        'ascending', 'Recall Date column ascending');
                    $("#recall-table").find('th').eq(2).trigger('click');
                    equal($("#recall-table").find('th').eq(2).attr('aria-sort'),
                        'descending', 'Recall Date descending');
                    //Patient Name column - ascending
                    $("#recall-table").find('th').eq(0).trigger('click');
                    equal($("#recall-table").find('th').eq(0).attr('aria-sort'),
                        'ascending', 'Patient Name ascending');
                    //Patient Name column - descending
                    $("#recall-table").find('th').eq(0).trigger('click');
                    equal($("#recall-table").find('th').eq(0).attr('aria-sort'),
                        'descending', 'Patient Name descending');
                    //Clinic column - ascending
                    $("#recall-table").find('th').eq(1).trigger('click');
                    equal($("#recall-table").find('th').eq(1).attr('aria-sort'),
                        'ascending', 'Clinic ascending');
                    //Service Connected column - descending
                    $("#recall-table").find('th').eq(1).trigger('click');
                    equal($("#recall-table").find('th').eq(1).attr('aria-sort'),
                        'descending', 'Clinic descending');

                });
            });
        });

        module("SCV-356, SCV-359, SCV-54, SCV-84 |SCV-473,SCV-476,SCV-733,SCV-735,SCV-734,SCV-737,SCV-738,SCV-739,SCV-740 - Details for NEAR and Recall");
        test('SCV-771 - Validate the NEAR and Recall details for facility', function () {
            ok(true, "Tests are running.");

            $(window).load(function () {
                //737 - patient context
                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 1500;
                }, function () {
                    afterElementLoad($("#inner-content p:contains('Please select a Service/Specialty and Clinic to view availability.')"), 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');

                    //Expand the NEAR section, select the meta data row and display the details
                    $("#near h3").trigger('click');
                    return 500;
                }, function () {
                    $("#near-table").find('td').eq(0).trigger('tap');
                    return 500;
                }, function () {
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Patient Name displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'SSN displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Cell Phone displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Home Phone displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Request Date displayed');

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

                    //Expand the Recall section, select the meta data row and display the details
                    $("#recall h3").trigger('click');
                    $("#recall-table").find('td').eq(0).trigger('tap');
                    return 500;
                }, function () {
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Clinic displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Accession Number displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Test App displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Appointment Length displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Patient Name displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Provider Name displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Fasting displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Recall Date displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Second Print Date displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Date Reminder Sent displayed');
                    ok($("#inner-content").find('li').eq(0).find('span').eq(0).text(), 'Comments displayed');

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


    });
//});