define(
    [ 'jQuery', 'asyncSeries', 'testUtilities'],
    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("SCV948 |SCV1128- Clear button to clear clinic selections");
        test('SCV1131 - Validate the Clear button within the clinic menu',
            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 () {
                        $(window).load(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');
                            //Validate the clinic menu
                            $("#calendar-specialty-input").val('Rehab Medicine')
                                .keyup();
                            $("#calendar-specialty li:nth-child(10) a")
                                .trigger('tap');
                            return 200;
                        });
                    }, function () {
                        $(window).load(function () {
                            $('#calendar-clinic-button')
                                .trigger('click');
                            equal($("#clear-btn").length > 0, false, 'Clear button is not displayed');
                            ok($("#clinics-form").text(), 'NO CLINICS AVAILABLE');
                            //Close clinic menu
                            $("#close-btn").trigger('tap');
                            return 100;
                        });
                    }, function () {
                        $(window).load(function () {
                            $("#calendar-specialty-input").val('General')
                                .keyup();
                            $("#calendar-specialty li:nth-child(4) a")
                                .trigger('tap');

                            $('#calendar-clinic-button')
                                .trigger('click');
                            ok($("#clear-btn").is(':visible'), 'Clear button is displayed');

                            // Select Clinic
                            $("#calendar-clinic-menu label").eq(0)
                                .trigger('click');
                            //validate the count
                            ok($("#clinics-form .select-countdown").text(), 'SELECT UP TO: 4');

                            //Click the Clear button and validate that the selection is cleared
                            $("#clear-btn").eq(0).trigger('click');
                            //Validate the text and that the check box is unselected.
                            ok($("#clinics-form .select-countdown").text(), 'SELECT UP TO: 5');
                            equal($("#calendar-clinic-menu label").find('span').eq(0).find('span').eq(1).hasClass('ui-icon-checkbox-off'), true, 'Checkbox is unselected');

                            //Close clinic menu
                            $("#close-btn").trigger('tap');
                        });
                    });
                })
            });
    });
//});
