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("SCV49, SCV948 |SCV280 |SCV172 |SCV1128- Select Service/Specialty to book appointment| User must select a clinic to filter availability by|Validate clear btn in clinic menu");
        test('SCV292, SCV1131 - Validate that a Service/Specialty and a Clinic must be selected to view available appointments, Validate clear btn in clinic menu',
            function () {
                asyncSeries( function () {
                        return 1000;
                    },
                    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');

                        //SCV-948 Validate the Clear button in the clinic menu
                        $("#calendar-clinic-menu label").eq(0)
                            .trigger('click');

                        ok($("#clinics-form div:nth-child(1)").eq(0).text(), 'SELECT UP TO: 4');
                        //Click the clear button
                        $("#clear-btn").trigger('click');
                        ok($("#clinics-form div:nth-child(1)").eq(0).text(), 'SELECT UP TO: 5');

                        // 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 () {
                        // Click View Availability to display the
                        // calendar
                        $("#appointment-button a").trigger('tap');
                        afterElementLoad($("#calendar"), function () {
                            ok($("#calendar")
                                    .is(':visible'),
                                'Calendar is visible');
                        });
                        //Navigate to month that has available appts
                        $('.fc-button-next').trigger('click');

                    }
                );
            }
        );
            

        module("SCV49, SCV691 |SCV24, SCV802- User can see availability with a patient already in context"
        );
        test('SCV294, SCV902- Validate that available appointments can be viewed with Patient in Context',
            function () {
                asyncSeries(function () {
                        return 1000;
                    },
                    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 () {
                        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:eq(2) a").trigger('tap');

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

                        // Select Clinic
                        $("#calendar-clinic-menu label").eq(0)
                            .trigger('click');

                        var date = new Date();

                        date.setDate(date.getDate() + 10);

                        $('#desired-date').val(formatDate(date)).trigger('blur');

                    }, 
                    function () {
                        // Click View Availability to
                        // display the calendar
                        $("#appointment-button button")
                            .trigger('tap');
                        afterElementLoad(
                            $("#calendar"),
                            function () {
                                ok($("#calendar").is(':visible'),
                                    'Calendar is visible');
                            });
                    }, 
                    function () {
                        $('#patient-search').trigger('click');

                        return 1500;
                    }, 
                    function () {
                        // Search and select a patient
                        var e = $.Event("keydown");
                        e.which = 13; // # Some key
                        // code value
                        e.keyCode = 13;
                        $("#primary-search-filter input").val(
                            '666000004')
                            .trigger(e);
                        $('#patient-list li:nth-child(1) a')
                            .trigger('tap');

                        return 500;
                    }, 
                    function () {
                        $('#confirm-button').trigger('tap');

                        return 0000;
                    }, 
                    function () {
                        ok($("#calendar").is(':visible'),
                                    'Calendar is visible');
					}
                );
            }
        );
    }
);