Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/views/magic_test/_context_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@
}
}

// Override the alert and confirm functions to register capybara actions.
(function() {
var _old_alert = window.alert;
window.alert = function() {
if(!window.generatingAssertion) {
window.registerAcceptAlert = true;
}
return _old_alert.apply(window, arguments);
};
})();

(function() {
var _old_confirm = window.confirm;
window.confirm = function() {
if(!window.generatingAssertion) {
window.registerAcceptConfirm = true;
}
return _old_confirm.apply(window, arguments);
}
})();

ready(function() {
enableKeyboardShortcuts();
});
Expand All @@ -31,13 +52,16 @@
var target = "";
var options = "";
var accept = "You selected:\n\r" + text + "\n\rOk: Type `flush` into debugger console to add to test.\nCancel: To select new text."

window.generatingAssertion = true;
if (window.confirm(accept)) {
testingOutput.push({action: action, target: target, options: options});
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
}
else {
console.log("Assertion was not generated.")
}
window.generatingAssertion = false;
}
}

Expand Down
13 changes: 13 additions & 0 deletions app/views/magic_test/_javascript_helpers.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@
var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
testingOutput.push({action: action, target: target, options: options });
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));

// Register Capybara actions for `alert` and `confirm` methods.
if (window.registerAcceptAlert) {
var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
testingOutput.push({action: "accept_alert", target: "", options: ""})
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
window.registerAcceptAlert = false;
} else if (window.registerAcceptConfirm) {
var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
testingOutput.push({action: "accept_confirm", target: "", options: ""})
sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
window.registerAcceptConfirm = false;
}
};

function keypressFunction(evt) {
Expand Down