Skip to content

Commit

Permalink
Merge pull request #748 from alphagov/survey-test-march-2016
Browse files Browse the repository at this point in the history
Implement 48 hour test User Satisfaction Survey
  • Loading branch information
jamiecobbett committed Feb 26, 2016
2 parents 370735d + 7ccaa96 commit a759deb
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 22 deletions.
27 changes: 20 additions & 7 deletions app/assets/javascripts/user-satisfaction-survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
' </div>' +
'</section>',

TEST_TEMPLATE: '<section id="user-satisfaction-survey" class="visible" aria-hidden="false">' +
' <div class="wrapper">' +
' <h1>Are you visiting GOV.UK for professional or personal reasons?</h1>' +
' <p class="right"><a href="#survey-no-thanks" id="survey-no-thanks">No thanks</a></p>' +
' <p><a href="javascript:void()" id="take-survey" target="_blank">Take the 1 question survey</a> This will open a short survey on another website</p>' +
' </div>' +
'</section>',

cookieNameTakenSurvey: "govuk_takenUserSatisfactionSurvey",
trackEvent: function (action, label) {
GOVUK.analytics.trackEvent('user_satisfaction_survey', action, {
Expand All @@ -37,7 +45,7 @@
return false;
});
$takeSurvey.click(function () {
userSatisfaction.setCookieTakenSurvey()
userSatisfaction.setCookieTakenSurvey();
userSatisfaction.trackEvent('banner_taken', 'User taken survey');
});
},
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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(); }
};

Expand Down
2 changes: 1 addition & 1 deletion app/views/root/_base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<% end %>

<% content_for :after_header do %>
<div id="user-satisfaction-survey-container" data-survey-url="https://www.surveymonkey.com/s/6HZFSVC"></div>
<div id="user-satisfaction-survey-container" data-survey-url="https://www.surveymonkey.com/s/2MRDLTW"></div>

<% unless local_assigns[:hide_banner_notification] %>
<%= banner_notification %>
Expand Down
74 changes: 60 additions & 14 deletions spec/javascripts/user-satisfaction-survey-spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
describe("User Satisfaction Survey", function () {
describe("Cookies", function () {
var survey, $surveyBar, $block;
var survey, $surveyBar, $block, inTestPeriodSpy;

beforeEach(function () {
$block = $('<div id="banner-notification" style="display: none"></div>' +
'<div id="global-cookie-message" style="display: none"></div>' +
'<div id="global-browser-prompt" style="display: none"></div>' +
'<div id="user-satisfaction-survey-container" data-survey-url="http://www.surveymonkey.com/some-survey-id"></div>');
'<div id="user-satisfaction-survey-container" data-survey-url="https://www.surveymonkey.com/r/some-survey-id"></div>');

$('body').append($block);
$("#user-satisfaction-survey").remove();
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
});
});
});
});

0 comments on commit a759deb

Please sign in to comment.