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("SCV74|SCV1289,SCV1290,SCV-1291- Display consults for a service, All columns are sortable, Display consults details");
        test('SCV1292 - Validate consults for a service', 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 1500;
                }, function () {
                    afterElementLoad($("#consults-filter"), function () {
                        ok($("#consults-filter").is(':visible'),
                            'Consults page is visible');
                    });
                    // show calendar
                    $("#service-specialty-input").val('radio')
                        .keyup();
                    $("#service-specialty li:nth-child(16) 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
                    ok($("#consults-filter-table").find('th').eq(0).text(), 'Patient Name', '1st column');
                    ok($("#consults-filter-table").find('th').eq(1).text(), 'Status', '2nd column');
                    ok($("#consults-filter-table").find('th').eq(2).text(), 'Order Date', '3rd column');
                    ok($("#consults-filter-table").find('th').eq(3).text(), 'Days', '4th column');

                    //Validate that each column is sortable
                    //Days column - default is ascending, click to sort descending
                    equal($("#consults-filter-table").find('th').eq(3).attr('aria-sort'),
                        'descending', 'Days column ascending');
                    $("#consults-filter-table").find('th').eq(3).trigger('click');
                    equal($("#consults-filter-table").find('th').eq(3).attr('aria-sort'),
                        'ascending', 'Days column descending');
                    //Patient Name column - ascending
                    $("#consults-filter-table").find('th').eq(0).trigger('click');
                    equal($("#consults-filter-table").find('th').eq(0).attr('aria-sort'),
                        'ascending', 'Patient Name ascending');
                    //Patient Name column - descending
                    $("#consults-filter-table").find('th').eq(0).trigger('click');
                    equal($("#consults-filter-table").find('th').eq(0).attr('aria-sort'),
                        'descending', 'Patient Name descending');
                    //Status column - ascending
                    $("#consults-filter-table").find('th').eq(1).trigger('click');
                    equal($("#consults-filter-table").find('th').eq(1).attr('aria-sort'),
                        'ascending', 'Status column ascending');
                    //Status column - descending
                    $("#consults-filter-table").find('th').eq(1).trigger('click');
                    equal($("#consults-filter-table").find('th').eq(1).attr('aria-sort'),
                        'descending', 'Status column descending');
                    //Order Date column - ascending
                    $("#consults-filter-table").find('th').eq(2).trigger('click');
                    equal($("#consults-filter-table").find('th').eq(2).attr('aria-sort'),
                        'ascending', 'Order Date column ascending');
                    //Order Date column - descending
                    $("#consults-filter-table").find('th').eq(2).trigger('click');
                    equal($("#consults-filter-table").find('th').eq(2).attr('aria-sort'),
                        'descending', 'Order Date column descending');

                    //Select a consults list item
                    $("#consults-filter-table").find('th').eq(2).trigger('click');
                    $("#consults-filter-table").find('tr').eq(2).trigger('tap');
                    return 500;
                }, function () {
                    //Validate the details are displayed
                    equal($("#inner-content").find('section').eq(1).is(':visible'), true, 'Consult details are displayed');
                    //Print consult button is displayed and enabled
                    equal($("#print-consult").is(':visible'), true, 'Print Consult button displayed');
                });
            });

        });
    });
