tooltip.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import Quill from '../../../../core';
  2. import { BaseTooltip } from '../../../../themes/base'
  3. class Tooltip extends BaseTooltip {
  4. }
  5. Tooltip.TEMPLATE = '<input type="text">';
  6. describe('BaseTooltip', function() {
  7. describe('save', function() {
  8. beforeEach(function() {
  9. this.quill = this.initialize(Quill, '');
  10. this.tooltip = new Tooltip(this.quill)
  11. });
  12. it('converts youtube video url to embedded', function() {
  13. insertVideo(this.tooltip, 'http://youtube.com/watch?v=QHH3iSeDBLo');
  14. expect(this.container.querySelector('.ql-video').src).toContain('http://www.youtube.com/embed/QHH3iSeDBLo');
  15. });
  16. it('converts www.youtube video url to embedded', function() {
  17. insertVideo(this.tooltip, 'http://www.youtube.com/watch?v=QHH3iSeDBLo');
  18. expect(this.container.querySelector('.ql-video').src).toContain('http://www.youtube.com/embed/QHH3iSeDBLo');
  19. });
  20. it('converts m.youtube video url to embedded', function() {
  21. insertVideo(this.tooltip, 'http://m.youtube.com/watch?v=QHH3iSeDBLo');
  22. expect(this.container.querySelector('.ql-video').src).toContain('http://www.youtube.com/embed/QHH3iSeDBLo');
  23. });
  24. it('preserves youtube video url protocol', function() {
  25. insertVideo(this.tooltip, 'https://m.youtube.com/watch?v=QHH3iSeDBLo');
  26. expect(this.container.querySelector('.ql-video').src).toContain('https://www.youtube.com/embed/QHH3iSeDBLo');
  27. });
  28. it('uses https as default youtube video url protocol', function() {
  29. insertVideo(this.tooltip, 'youtube.com/watch?v=QHH3iSeDBLo');
  30. expect(this.container.querySelector('.ql-video').src).toContain('https://www.youtube.com/embed/QHH3iSeDBLo');
  31. });
  32. it('converts vimeo video url to embedded', function() {
  33. insertVideo(this.tooltip, 'http://vimeo.com/47762693');
  34. expect(this.container.querySelector('.ql-video').src).toContain('http://player.vimeo.com/video/47762693/');
  35. });
  36. it('converts www.vimeo video url to embedded', function() {
  37. insertVideo(this.tooltip, 'http://www.vimeo.com/47762693');
  38. expect(this.container.querySelector('.ql-video').src).toContain('http://player.vimeo.com/video/47762693/');
  39. });
  40. it('preserves vimeo video url protocol', function() {
  41. insertVideo(this.tooltip, 'https://www.vimeo.com/47762693');
  42. expect(this.container.querySelector('.ql-video').src).toContain('https://player.vimeo.com/video/47762693/');
  43. });
  44. it('uses https as default vimeo video url protocol', function() {
  45. insertVideo(this.tooltip, 'vimeo.com/47762693');
  46. expect(this.container.querySelector('.ql-video').src).toContain('https://player.vimeo.com/video/47762693/');
  47. });
  48. function insertVideo(tooltip, url) {
  49. tooltip.textbox.value = url;
  50. tooltip.root.setAttribute('data-mode', 'video');
  51. tooltip.save();
  52. }
  53. });
  54. });