diff --git a/app/assets/javascripts/user-satisfaction-survey.js b/app/assets/javascripts/user-satisfaction-survey.js index 5c111c631..c75ecd66d 100644 --- a/app/assets/javascripts/user-satisfaction-survey.js +++ b/app/assets/javascripts/user-satisfaction-survey.js @@ -14,6 +14,14 @@ ' ' + '', + TEST_TEMPLATE: '
' + + '
' + + '

Are you visiting GOV.UK for professional or personal reasons?

' + + '

No thanks

' + + '

Take the 1 question survey This will open a short survey on another website

' + + '
' + + '
', + cookieNameTakenSurvey: "govuk_takenUserSatisfactionSurvey", trackEvent: function (action, label) { GOVUK.analytics.trackEvent('user_satisfaction_survey', action, { @@ -37,7 +45,7 @@ return false; }); $takeSurvey.click(function () { - userSatisfaction.setCookieTakenSurvey() + userSatisfaction.setCookieTakenSurvey(); userSatisfaction.trackEvent('banner_taken', 'User taken survey'); }); }, @@ -47,7 +55,8 @@ return; } - $("#user-satisfaction-survey-container").append(userSatisfaction.TEMPLATE); + var template = userSatisfaction.inTestPeriod() ? userSatisfaction.TEST_TEMPLATE : userSatisfaction.TEMPLATE; + $("#user-satisfaction-survey-container").append(template); userSatisfaction.setEventHandlers(); userSatisfaction.setSurveyUrl(); @@ -67,12 +76,9 @@ setSurveyUrl: function(href) { var $surveyLink = $('#take-survey'); var surveyUrl = $('#user-satisfaction-survey-container').data('survey-url'); - var surveyStarts = new Date("February 1, 2016").getTime(); - var surveyEnds = new Date("May 1, 2016 23:59:59").getTime(); - if (userSatisfaction.currentDate() >= surveyStarts && - userSatisfaction.currentDate() <= surveyEnds) { - surveyUrl = 'https://www.surveymonkey.co.uk/r/2MRDLTW'; + if (userSatisfaction.inTestPeriod()) { + surveyUrl = 'https://www.surveymonkey.co.uk/r/D668G5Z'; } if (surveyUrl.indexOf('?c=') === -1) { @@ -81,6 +87,13 @@ $surveyLink.attr('href', surveyUrl); }, + inTestPeriod: function() { + var starts = new Date("March 2, 2016").getTime(); + var ends = new Date("March 3, 2016 23:59:59").getTime(); + + return userSatisfaction.currentDate() >= starts && + userSatisfaction.currentDate() <= ends; + }, currentDate: function() { return new Date().getTime(); } }; diff --git a/app/views/root/_base.html.erb b/app/views/root/_base.html.erb index d785eaac6..1f002696a 100644 --- a/app/views/root/_base.html.erb +++ b/app/views/root/_base.html.erb @@ -22,7 +22,7 @@ <% end %> <% content_for :after_header do %> -
+
<% unless local_assigns[:hide_banner_notification] %> <%= banner_notification %> diff --git a/spec/javascripts/user-satisfaction-survey-spec.js b/spec/javascripts/user-satisfaction-survey-spec.js index e9e3fb427..cbbe83751 100644 --- a/spec/javascripts/user-satisfaction-survey-spec.js +++ b/spec/javascripts/user-satisfaction-survey-spec.js @@ -1,12 +1,12 @@ describe("User Satisfaction Survey", function () { describe("Cookies", function () { - var survey, $surveyBar, $block; + var survey, $surveyBar, $block, inTestPeriodSpy; beforeEach(function () { $block = $('' + '' + '' + - '
'); + '
'); $('body').append($block); $("#user-satisfaction-survey").remove(); @@ -37,30 +37,54 @@ describe("User Satisfaction Survey", function () { expect(survey.currentDate()).not.toBe(undefined); }); - it("uses the temporary survey URL on 01/02/2016", function() { - spyOn(survey, 'currentDate').and.returnValue(new Date("February 1, 2016").getTime()); + it("uses the temporary survey URL in the test period", function() { + spyOn(GOVUK.userSatisfaction, 'inTestPeriod').and.returnValue(true); survey.showSurveyBar(); - expect($('#take-survey').attr('href')).toMatch("https://www.surveymonkey.co.uk/r/2MRDLTW?"); + expect($('#take-survey').attr('href')).toMatch("https://www.surveymonkey.co.uk/r/D668G5Z?"); }); - it("uses the temporary survey URL on 01/05/2016", function() { - spyOn(survey, 'currentDate').and.returnValue(new Date("May 1, 2016 12:15:30").getTime()); + it("uses the original survey URL outside the test period", function() { + spyOn(GOVUK.userSatisfaction, 'inTestPeriod').and.returnValue(false); survey.showSurveyBar(); - expect($('#take-survey').attr('href')).toMatch("https://www.surveymonkey.co.uk/r/2MRDLTW?"); + expect($('#take-survey').attr('href')).toMatch("https://www.surveymonkey.com/r/some-survey-id?"); + }); + + it("uses the temporary survey heading in the test period", function() { + spyOn(GOVUK.userSatisfaction, 'inTestPeriod').and.returnValue(true); + survey.showSurveyBar(); + expect($('#user-satisfaction-survey h1').text()).toBe("Are you visiting GOV.UK for professional or personal reasons?"); + }); + + it("uses the original survey heading outside the test period", function() { + spyOn(GOVUK.userSatisfaction, 'inTestPeriod').and.returnValue(false); + survey.showSurveyBar(); + expect($('#user-satisfaction-survey h1').text()).toBe("Tell us what you think of GOV.UK"); + }); + + it("uses the temporary survey link in the test period", function() { + spyOn(GOVUK.userSatisfaction, 'inTestPeriod').and.returnValue(true); + survey.showSurveyBar(); + expect($('#user-satisfaction-survey a#take-survey').text()).toBe("Take the 1 question survey"); + }); + + it("uses the original survey link outside the test period", function() { + spyOn(GOVUK.userSatisfaction, 'inTestPeriod').and.returnValue(false); + survey.showSurveyBar(); + expect($('#user-satisfaction-survey a#take-survey').text()).toBe("Take the 3 minute survey"); }); it("should set the take survey link's href to the survey monkey's url as defined by the wrapper's data-survey-url, appending the page's current path when not already specified", function() { - spyOn(survey, 'currentDate').and.returnValue(new Date("January 1, 2016").getTime()); - $("#user-satisfaction-survey-container").data('survey-url', 'http://www.surveymonkey.com/some-survey-id'); + spyOn(GOVUK.userSatisfaction, 'inTestPeriod').and.returnValue(false); + $("#user-satisfaction-survey-container").data('survey-url', 'https://www.surveymonkey.com/r/some-survey-id'); survey.showSurveyBar(); - expect($('#take-survey').attr('href')).toBe("http://www.surveymonkey.com/some-survey-id?c="+window.location.pathname); + expect($('#take-survey').attr('href')).toBe("https://www.surveymonkey.com/r/some-survey-id?c="+window.location.pathname); }); it("should set the take survey link's href to the survey monkey's url as defined by the wrapper's data-survey-url, appending nothing when a path is already specified", function() { - spyOn(survey, 'currentDate').and.returnValue(new Date("January 1, 2016").getTime()); - $("#user-satisfaction-survey-container").data('survey-url', 'http://www.surveymonkey.com/some-survey-id?c=/somewhere'); + spyOn(GOVUK.userSatisfaction, 'inTestPeriod').and.returnValue(false); + $("#user-satisfaction-survey-container").data('survey-url', 'https://www.surveymonkey.com/r/some-survey-id?c=/somewhere'); survey.showSurveyBar(); - expect($('#take-survey').attr('href')).toBe("http://www.surveymonkey.com/some-survey-id?c=/somewhere") + expect($('#take-survey').attr('href')).toBe("https://www.surveymonkey.com/r/some-survey-id?c=/somewhere"); }); it("should randomly display the user satisfaction div", function () { @@ -128,5 +152,27 @@ describe("User Satisfaction Survey", function () { expect($('#user-satisfaction-survey').hasClass('visible')).toBe(false); }); }); + + describe("inTestPeriod", function () { + it("should be false on 1st March 2016", function() { + spyOn(survey, 'currentDate').and.returnValue(new Date("March 1, 2016 23:50:00").getTime()); + expect(survey.inTestPeriod()).toBe(false); + }); + + it("should be true on 2nd March 2016", function() { + spyOn(survey, 'currentDate').and.returnValue(new Date("March 2, 2016 00:01:00").getTime()); + expect(survey.inTestPeriod()).toBe(true); + }); + + it("should be true on 2nd March 2016", function() { + spyOn(survey, 'currentDate').and.returnValue(new Date("March 3, 2016 23:50:00").getTime()); + expect(survey.inTestPeriod()).toBe(true); + }); + + it("should be false on 4th March 2016", function() { + spyOn(survey, 'currentDate').and.returnValue(new Date("March 4, 2016 00:01:00").getTime()); + expect(survey.inTestPeriod()).toBe(false); + }); + }); }); });