Editor.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. require('../common');
  3. const fc = require('fast-check');
  4. describe('Editor', function () {
  5. describe('show, hide, getText, setText & isPreview', function () {
  6. this.timeout(30000);
  7. it('returns text fed into the textarea, handles editor tabs', () => {
  8. fc.assert(fc.property(
  9. fc.string(),
  10. function (text) {
  11. var clean = globalThis.cleanup(),
  12. results = [];
  13. document.body.innerHTML = (
  14. '<ul id="editorTabs" class="nav nav-tabs hidden">' +
  15. '<li role="presentation" class="active">' +
  16. '<a id="messageedit" href="#">Editor</a>' +
  17. '</li>' +
  18. '<li role="presentation">' +
  19. '<a id="messagepreview" href="#">Preview</a>' +
  20. '</li>' +
  21. '</ul>' +
  22. '<div id="placeholder" class="hidden">+++ no document text +++</div>' +
  23. '<div id="prettymessage" class="hidden">' +
  24. '<pre id="prettyprint" class="prettyprint linenums:1"></pre>' +
  25. '</div>' +
  26. '<div id="plaintext" class="hidden"></div>' +
  27. '<p>' +
  28. '<textarea id="message" name="message" cols="80" rows="25" class="form-control hidden"></textarea>' +
  29. '</p>' +
  30. '<input id="messagetab" type="checkbox" checked="checked" />'
  31. );
  32. PrivateBin.Editor.init();
  33. results.push(
  34. document.getElementById('editorTabs').classList.contains('hidden') &&
  35. document.getElementById('message').classList.contains('hidden')
  36. );
  37. PrivateBin.Editor.show();
  38. results.push(
  39. !document.getElementById('editorTabs').classList.contains('hidden') &&
  40. !document.getElementById('message').classList.contains('hidden')
  41. );
  42. PrivateBin.Editor.hide();
  43. results.push(
  44. document.getElementById('editorTabs').classList.contains('hidden') &&
  45. document.getElementById('message').classList.contains('hidden')
  46. );
  47. PrivateBin.Editor.show();
  48. PrivateBin.Editor.focusInput();
  49. results.push(
  50. PrivateBin.Editor.getText().length === 0
  51. );
  52. PrivateBin.Editor.setText(text);
  53. results.push(
  54. PrivateBin.Editor.getText() === document.getElementById('message').value
  55. );
  56. PrivateBin.Editor.setText();
  57. results.push(
  58. !PrivateBin.Editor.isPreview() &&
  59. !document.getElementById('message').classList.contains('hidden')
  60. );
  61. document.getElementById('messagepreview').click();
  62. results.push(
  63. PrivateBin.Editor.isPreview() &&
  64. document.getElementById('message').classList.contains('hidden')
  65. );
  66. document.getElementById('messageedit').click();
  67. results.push(
  68. !PrivateBin.Editor.isPreview() &&
  69. !document.getElementById('message').classList.contains('hidden')
  70. );
  71. clean();
  72. return results.every(element => element);
  73. }
  74. ));
  75. });
  76. });
  77. });