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("SCV727 |SCV817- Change default view when not in Calendar tab under booking page");
        test('SCV922 - Validate default view when navigating within SCV', 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 () {
                    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('Medicine')
                        .keyup();
                    $("#calendar-specialty li:nth-child(6) a")
                        .trigger('tap');

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

                    // Select Clinic
                    $("#calendar-clinic-menu label").eq(3)
                        .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');
                    });

                    //Click the available slot
                    $('.fc-button-next').trigger('click');
                    //Search and select 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');
                    return 1000;
                }, function () {
                    $("#calendar").find('.available').eq(1).trigger('click');
                    return 500;
                }, function () {
                    equal($("#legend div:nth-child(3)").hasClass('legend patient-appt'), true, 'Patient has appt legend displayed');
                    //Default view is still the Day view
                    equal($("#calendar").find('button').eq(5).hasClass('fc-state-active'), true, 'Day view');

                    //select an appointment slot
                    $("#calendar .fc-view-agendaDay .fc-event:not(.patient-appt):not(.transparent)").eq(0).trigger('click');
                    return 500;
                }, function () {
                    //Book Appointment dialog is displayed
                    ok($("#book-appointment h3").text(), 'Book Appointment', 'Book appointment dialog');
                    return 500; //Wait till the purpose is loaded from vista
                }, function () {
                    //****Scenario#1****//

                    //Click Cancel Appt button and validate the default view.
                    $("#cancel-btn").trigger('click');
                    return 500;
                }, function () {
                    equal($("#calendar").find('button').eq(5).hasClass('fc-state-active'), true, 'Day view');

                    //****Scenario#2-View future details, navigate to calendar and navigate back to patient.

                    //Select future appointment meta data to display details
                    $("#patient-button").trigger('tap');
                    return 500;
                }, function () {
                    afterElementLoad($("#patient-button.ui-btn-active"), function () {
                        $("#future-appointments-table").find('tr').eq(1).trigger('tap');
                    });

                    return 500;
                }, function () {
                    equal($("#inner-content h3").is(':visible'), true, 'Future appointment details displayed');

                    //Navigate to calendar tab
                    $("#calendar-button").trigger('tap');
                    return 500;
                }, function () {
                    ok($("#calendar-specialty-input").is(':visible'), 'Calendar tab is visible');
                    equal($("#calendar-button").hasClass('ui-btn-active'), true, 'Calendar tab is active');

                    //Navigate back to Patient Tab
                    $("#patient-button").trigger('tap');
                    return 500;
                }, function () {
                    afterElementLoad($("#patient-button.ui-btn-active"), function () {
                        ok($("#future-appointments-table").is(':visible'), 'Future Appointments table is visible');
                    });

                    ok($("#inner-content h3").eq(3).text(), 'Please select List Item to view details or go to Calendar tab to view the Calendar.', 'Default view is not the Calendar');
                    equal($("#patient-button").hasClass('ui-btn-active'), true, 'Patient tab is active');

                    //****Scenario#3-view wait list detail, go to calendar tab and navigate back to patient tab

                    //Select an item from the wait list table to display details
                    //Expand the wait list table
                    $("#waitlist h3").trigger('click');
                    return 200;
                }, function () {
                    $("#waitlist-table").find('tr').eq(1).trigger('tap');
                    return 500;
                }, function () {
                    equal($("#inner-content h3").is(':visible'), true, 'Waitlist details displayed');

                    //Navigate to calendar tab
                    $("#calendar-button").trigger('tap');
                    return 500;
                }, function () {
                    ok($("#calendar-specialty-input").is(':visible'), 'Calendar tab is visible');
                    equal($("#calendar-button").hasClass('ui-btn-active'), true, 'Calendar tab is active');

                    //Navigate back to Patient Tab
                    $("#patient-button").trigger('tap');
                    return 500;
                }, function () {
                    afterElementLoad($("#patient-button.ui-btn-active"), function () {
                        ok($("#future-appointments").is(':visible'), 'Future Appointments section is visible');
                    });

                    ok($("#inner-content h3").eq(3).text(),
                        'Please select List Item to view details or go to Calendar tab to view the Calendar.', 'Default view is not the Calendar');
                    equal($("#patient-button").hasClass('ui-btn-active'), true, 'Patient tab is active');

                    //****Scenario#4-Go to wait list page and view wl details, go to booking page and come navigate back to WL page

                    //Click on Wait List from the footer
                    $('#footer-waitlist-btn').trigger('tap');
                    return 1500;
                }, function () {
                    afterElementLoad($("#ewl-table"), function () {
                        ok($("#ewl-table").is(':visible'),
                            "EWL table visible");
                    });

                    //Select the list item to display the details
                    $("#ewl-table").find('tr').eq(1).trigger('tap');
                    return 500;
                }, function () {
                    equal($("#process-request").is(':visible'), true, 'Book Appointment button displayed as part of details');

                    //Navigate to booking page
                    $("#footer-booking-btn").trigger('tap');
                    return 500;
                }, function () {
                    afterElementLoad($("#footer-booking-btn.ui-btn-active"), function () {
                        ok($("#future-appointments-table").is(':visible'), 'Future Appointments section is visible');
                    });

                    //Patient tab is displayed as it was the last accessed under booking page
                    /*afterElementLoad($("#future-appointments-table"),function() {
                     ok($("#future-appointments-table").is(':visible'),
                     "future-appointments table visible");
                     });*/
                    equal($("#patient-button").hasClass('ui-btn-active'), true, 'Patient tab is active');
                    equal($("#footer-booking-btn").hasClass('ui-btn-active'), true, 'Booking page is displayed');

                    //Now go back to the Wait List page from footer and validate the default view
                    $('#footer-waitlist-btn').trigger('tap');
                    return 800;
                }, function () {
                    afterElementLoad($("#ewl-table"), function () {
                        ok($("#ewl-table").is(':visible'),
                            "EWL table visible");
                    });

                    //****Scenario#5-After viewing the details of WL, canceling book appt should display calendar
                    $("#ewl-table").find('tr').eq(1).trigger('tap');
                    return 500;
                }, function () {
                    equal($("#process-request").is(':visible'), true, 'Book Appointment button displayed as part of details');
                    $("#process-request").trigger('click');


                });
	        });
        });
    });
