Sha256: 75e779431aec6156dce3c884d06dbf99ffde954af13929739d545ad866b80f6f

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

<script>
  function ready(fn) {
    if (document.readyState !== 'loading'){
      fn();
    } else {
      document.addEventListener('DOMContentLoaded', fn);
    }
  }

  ready(function() {
    enableKeyboardShortcuts();
  });


  function enableKeyboardShortcuts() {
    function keydown(event) {
      if (event.ctrlKey && event.shiftKey && event.key === 'A') {
        event.preventDefault();
        generateAssertion();
      }
    }

    document.addEventListener('keydown', keydown, false);

    function generateAssertion() {
      var text = selectedText().trim();
      if (text.length > 0) {
        var action = "assert page.has_content? '" + text.replace("'", "\\\'") +  "'";
        var testingOutput = JSON.parse(sessionStorage.getItem("testingOutput"));
        var target = "";
        var options = "";
        testingOutput.push({action: action, target: target, options: options});
        sessionStorage.setItem("testingOutput", JSON.stringify(testingOutput));
        alert("Generated an assertion for \"" + selectedText() + "\". Type `flush` in the debugger console to add it to your test file.");
      }
    }

    function selectedText() {
      var text = "";
      if (window.getSelection) {
          text = window.getSelection().toString();
      } else if (document.selection && document.selection.type != "Control") {
          text = document.selection.createRange().text;
      }
      return text;
    }
  }
</script>

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
magic_test-0.0.9 app/views/magic_test/_context_menu.html
magic_test-0.0.7 app/views/magic_test/_context_menu.html
magic_test-0.0.6 app/views/magic_test/_context_menu.html