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


        module("SCV-180,SCV-1280|SCV-1229, SCV-1231, 1232, 1233,1312 - Click on VAAC button on footer take user to VAAC page, VAAC section displayed only for VAAC requests, validate book, cancel and Unavailable dialog," +
            "Display Provider information");
        test('SCV-1239 - Validate the VAAC integration within SCV', function () {
            ok(true, "fix an issue where it won't test at all.");
            $(window).load(function () {
                asyncSeries(
                    varARequest1,
                    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 () {
                        //VAAC details section not displayed
                        equal($("#VAAC-request-details h3").is(':visible'), false, 'VAAC request details section not displayed.');
                        //Go to VAAC page by clicking the button on the footer
                        $('#footer-veteran-requests-btn').trigger('tap');
                        return 500;
                    }, function () {
                        afterElementLoad($("#list-refresh-btn"), function () {

                            ok($("#appointment-requests-table")
                                    .is(':visible'),
                                'Appointment Request table is visible');
                        });
                        //Click Process button to take user to booking page
                        $('#appointment-requests-table tr:contains("onedemo, patient"):contains("Primary Care"):contains("Submitted")').trigger('tap');
                        return 500;
                    }, function () {
                        afterElementLoad($("#process-request"), function () {
                            ok($("#process-request").is(':visible'),
                                "Process Request button is visible");
                            //Click the Process Request button and validate the VAAC details
                            $("#process-request").trigger('click');
                            return 500;
                        });
                    }, function () {
                        afterElementLoad($("#VAAC-request-details"), function () {
                            ok($("#VAAC-request-details h3").is(':visible'),
                                "VAAC Request details is visible");
                        });
                        equal($("#VAAC-request-details h3").is(':visible'), true, 'VAAC request details section is displayed.');

                        //Validate the section - following are displayed:Type of Care, Request Date/Time, Cancel Request button and Unavailable button
                        //Section is expanded by default
                        equal($("#VAAC-request-details h3").hasClass('ui-collapsible-heading-collapsed'), false, 'VAAC request details section expanded by default');
                        //Collapse section
                        $("#VAAC-request-details h3").trigger('click');
                        equal($("#VAAC-request-details h3").hasClass('ui-collapsible-heading-collapsed'), true, 'VAAC request details section is collapsed');

                        //Re-Expand the section
                        $("#VAAC-request-details h3").trigger('click');
                        ok($("#VAAC-request-content").find('ul').eq(0).find('span').eq(0).text(), 'Type of Care');
                        //SCV1280-Display provider info
                        ok($("#VAAC-request-content").find('ul').eq(0).find('span').eq(2).text(), 'Provider');
                        ok($("#VAAC-request-content").find('ul').eq(1).find('span').eq(0).text(), 'Request Date/Time');
                        ok($("#cancel-VAAC-btn").is(':visible'), 'Cancel Request button is displayed');
                        ok($("#unavailable-btn").is(':visible'), 'Unavailable button is displayed');

                        //Validate the messaging section
                        ok($("#new-message").is(':visible'), 'Messaging section is displayed');

                        //VALIDATE THE BOOKING DIALOG FOR VAAC REQUESTS
                        //Navigate back to VAAC page by clicking the button on the footer
                        $('#footer-veteran-requests-btn').trigger('tap');
                        return 500;
                    }, function () {
                        afterElementLoad($("#list-refresh-btn"), function () {
                            ok($("#appointment-requests-table")
                                    .is(':visible'),
                                'Appointment Request table is visible');
                        });
                        //Click Process button to take user to booking page
                        $('#appointment-requests-table tr:contains("onedemo, patient"):contains("Primary Care"):contains("Submitted")').trigger('tap');
                        return 500;
                    }, function () {
                        afterElementLoad($("#process-request"), function () {
                            ok($("#process-request").is(':visible'),
                                "Process Request button is visible");
                        });
                        //Click the Process Request button
                        $("#process-request").trigger('click');
                        return 1500;
                    }, function () {
                        afterElementLoad($("#VAAC-request-details"), function () {
                            ok($("#VAAC-request-details h3").is(':visible'),
                                "VAAC Request details is visible");
                        });
                        equal($("#VAAC-request-details h3").is(':visible'), true, 'VAAC request details section is displayed.');

                        //Select Service/Specialty and Clinic
                        $("#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(0)
                            .trigger('click');
                        $("#appointment-button a")
                            .trigger('tap');
                        return 200;
                    }, function () {
                        afterElementLoad($("#calendar"), function () {
                            ok($("#calendar").is(':visible'),
                                'Calendar is visible');
                        });
                    }, function () {
                        //Click the available slot and validate the book appointment dialog
                        $('.fc-button-next').trigger('click');
                        $("#calendar").find('.available').eq(1).trigger('click');
                        return 500;
                    }, function () {
                        //Day view is displayed
                        equal($("#calendar").find('button').eq(5).hasClass('fc-state-active'), true, 'Day view');

                        //Validate that a patient must be in context before booking an appointment
                        $("#calendar .fc-view-agendaDay .fc-event:not(.patient-appt):not(.transparent)").eq(0).trigger('click');
                        return 1000;
                    }, function () {
                        afterElementLoad($("#book-appointment"), function () {
                            ok($("#book-appointment h3").is(':visible'),
                                'Book Appointment dialog is visible');
                        });
                        //Validate the booking dialog for VAAC request
                        ok($("#book-appt-content div:nth-child(3)").find('h3').eq(0).text(), 'Fulfills the Following VAAC Request:');
                        ok($("#book-appt-content div:nth-child(3)").find('span').eq(0).text(), 'Type of Care');
                        //SCV-1280- Display provider
                        ok($("#book-appt-content div:nth-child(3)").find('span').eq(2).text(), 'Provider');
                        ok($("#book-appt-content div:nth-child(3)").find('span').eq(1).text(), 'Primary Care');
                        ok($("#request-date-time").find('legend').eq(0).text(), 'Request Date/Time');

                        //Click Cancel to close the dialog
                        $("#appt-type-menu").find('li').eq(1).trigger('click');
                        $("#cancel-btn").trigger('click');
                        return 1000;
                    }, function () {
                        afterElementLoad($("#VAAC-request-details"), function () {
                            ok($("#VAAC-request-details h3").is(':visible'),
                                "VAAC Request details is visible");
                        });
                        equal($("#calendar").find('button').eq(5).hasClass('fc-state-active'), true, 'Day view general');

                        //Validate the Unavailable button
                        $("#unavailable-btn").trigger('click');
                        return 1000;
                    }, function () {
                        ok($("#message-for-user h1").text(), 'Unavailable Appointment popup displayed');

                        //Validate the Unavailable pop-up
                        //Check box unchecked by default
                        equal($("#VAAC-form").find('fieldset').find('div').eq(2).find('span').eq(2).hasClass('ui-icon-checkbox-off'), true, 'Check box not selected');
                        ok($("#VAAC-close-btn").is(':visible'), 'Return button is displayed and enabled');
                        ok($("#VAAC-confirm-btn").attr('data-disabled'), 'true-Save button is disabled');
                        //Select the check-box
                        $("#VAAC-form").find('fieldset').find('div').eq(2).find('span').eq(2).trigger('click');
                        ok($("#VAAC-confirm-btn").attr('data-disabled'), 'false-Save button is enabled');

                        //Close Unavailable pop-up
                        $("#VAAC-close-btn").trigger('click');
                        ok($("#VAAC-request-details h3").is(':visible'), 'VAAC request details section is displayed.');

                        //Validate Cancel dialog
                        $("#cancel-VAAC-btn").trigger('click');
                        ok($("#message-for-user h1").text(), 'Cancel Appointment Request');

                        //Validate the Cancel dialog
                        ok($("#VAAC-form").find('fieldset').find('div').eq(2).find('span').eq(1).text(), 'Veteran Request');
                        ok($("#VAAC-form").find('fieldset').find('div').eq(3).find('span').eq(1).text(), 'Clinic');
                        //Radio button not selected by default
                        ok($("#VAAC-close-btn").is(':visible'), 'Return button is displayed and enabled');
                        ok($("#VAAC-confirm-btn").attr('data-disabled'), 'true-Save button is disabled');
                        //Select the radio button
                        $("#VAAC-form").find('fieldset').find('div').eq(2).find('span').eq(2).trigger('click');
                        ok($("#VAAC-confirm-btn").attr('data-disabled'), 'false-Save button is enabled');

                        $("#VAAC-close-btn").trigger('click');
                        return 500;
                    }, function () {
                        afterElementLoad($("#VAAC-request-details"), function () {
                            ok($("#VAAC-request-details h3").is(':visible'),
                                "VAAC Request details is visible");
                        });
                        ok($("#VAAC-request-details h3").is(':visible'), 'VAAC request details section is displayed.');

                        $('#patient-search .ui-input-clear').trigger('tap');
                    });
            });

        });
    });
//});