Skip to content

Commit

Permalink
Merge pull request #812 from alphagov/fix-bug-introduced-in-survey-re…
Browse files Browse the repository at this point in the history
…factor

Fix transaction bug introduced in 8f1f835
  • Loading branch information
kalleth authored Jul 22, 2016
2 parents 05c2625 + 9558145 commit 1463f8d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/assets/javascripts/surveys.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@
},

userCompletedTransaction: function() {
var currentURL = window.location.pathname;
var path = userSurveys.currentPath();

function stringContains(str, substr) {
return str.indexOf(substr) > -1;
}

if (stringContains(currentURL, "/done") &&
stringContains(currentURL, "/transaction-finished") &&
stringContains(currentURL, "/driving-transaction-finished")) {
if (stringContains(path, "/done") ||
stringContains(path, "/transaction-finished") ||
stringContains(path, "/driving-transaction-finished")) {
return true;
}
},
Expand Down Expand Up @@ -147,7 +147,8 @@
return "govuk_" + cookieStub;
},

currentTime: function() { return new Date().getTime(); }
currentTime: function() { return new Date().getTime(); },
currentPath: function() { return window.location.pathname; }
};

root.GOVUK.userSurveys = userSurveys;
Expand Down
22 changes: 22 additions & 0 deletions spec/javascripts/surveys-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ describe("Surveys", function() {
});
});

describe("userCompletedTransaction", function() {
it("normally returns false", function() {
spyOn(surveys, 'currentPath').and.returnValue('/');
expect(surveys.userCompletedTransaction()).toBeFalsy();
});

it("returns true when /done", function() {
spyOn(surveys, 'currentPath').and.returnValue('/done');
expect(surveys.userCompletedTransaction()).toBeTruthy();
});

it("returns true when /transaction-finished", function() {
spyOn(surveys, 'currentPath').and.returnValue('/transaction-finished');
expect(surveys.userCompletedTransaction()).toBeTruthy();
});

it("returns true when /driving-transaction-finished", function() {
spyOn(surveys, 'currentPath').and.returnValue('/driving-transaction-finished');
expect(surveys.userCompletedTransaction()).toBeTruthy();
});
});

describe("Event handlers", function () {
beforeEach(function() {
surveys.displaySurvey(defaultSurvey);
Expand Down

0 comments on commit 1463f8d

Please sign in to comment.