select.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. var select = require('../src/select');
  2. describe('select editable elements', function() {
  3. before(function() {
  4. global.input = document.createElement('input');
  5. global.input.value = 'lorem ipsum';
  6. global.textarea = document.createElement('textarea');
  7. global.textarea.value = 'lorem ipsum';
  8. document.body.appendChild(global.input);
  9. document.body.appendChild(global.textarea);
  10. });
  11. after(function() {
  12. document.body.innerHTML = '';
  13. });
  14. it('should return the selected text on input', function() {
  15. var result = select(global.input);
  16. assert.equal(result, global.input.value);
  17. });
  18. it('should return the selected text on textarea', function() {
  19. var result = select(global.textarea);
  20. assert.equal(result, global.textarea.value);
  21. });
  22. });
  23. describe('select non-editable element with no children', function() {
  24. before(function() {
  25. global.paragraph = document.createElement('p');
  26. global.paragraph.textContent = 'lorem ipsum';
  27. document.body.appendChild(global.paragraph);
  28. });
  29. after(function() {
  30. document.body.innerHTML = '';
  31. });
  32. it('should return the selected text', function() {
  33. var result = select(global.paragraph);
  34. assert.equal(result, global.paragraph.textContent);
  35. });
  36. });
  37. describe('select non-editable element with child node', function() {
  38. before(function() {
  39. global.li = document.createElement('li');
  40. global.li.textContent = 'lorem ipsum';
  41. global.ul = document.createElement('ul');
  42. global.ul.appendChild(global.li);
  43. document.body.appendChild(global.ul);
  44. });
  45. after(function() {
  46. document.body.innerHTML = '';
  47. });
  48. it('should return the selected text', function() {
  49. var result = select(global.ul);
  50. assert.equal(result, global.ul.textContent);
  51. });
  52. });
  53. describe('select non-editable svg element w/ multiple text children', function() {
  54. before(function() {
  55. global.text1 = document.createElement('text');
  56. global.text1.textContent = 'lorem ipsum';
  57. global.text2 = document.createElement('text');
  58. global.text2.textContent = 'dolor zet';
  59. global.svg = document.createElement('svg');
  60. global.svg.appendChild(global.text1);
  61. global.svg.appendChild(global.text2);
  62. document.body.appendChild(global.svg);
  63. });
  64. after(function() {
  65. document.body.innerHTML = '';
  66. });
  67. it('should return the selected text', function() {
  68. var result = select(global.svg);
  69. assert.equal(result, global.text1.textContent +
  70. global.text2.textContent);
  71. });
  72. });