commentsSpec.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @copyright 2018 Joas Schilling <nickvergessen@owncloud.com>
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  6. * License as published by the Free Software Foundation; either
  7. * version 3 of the License, or any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public
  15. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. */
  18. describe('OCP.Comments tests', function() {
  19. function dataProvider() {
  20. return [
  21. {input: 'nextcloud.com', expected: 'nextcloud.com'},
  22. {input: 'http://nextcloud.com', expected: '<a class="external" target="_blank" rel="noopener noreferrer" href="http://nextcloud.com">http://nextcloud.com</a>'},
  23. {input: 'https://nextcloud.com', expected: '<a class="external" target="_blank" rel="noopener noreferrer" href="https://nextcloud.com">nextcloud.com</a>'},
  24. {input: 'hi nextcloud.com', expected: 'hi nextcloud.com'},
  25. {input: 'hi http://nextcloud.com', expected: 'hi <a class="external" target="_blank" rel="noopener noreferrer" href="http://nextcloud.com">http://nextcloud.com</a>'},
  26. {input: 'hi https://nextcloud.com', expected: 'hi <a class="external" target="_blank" rel="noopener noreferrer" href="https://nextcloud.com">nextcloud.com</a>'},
  27. {input: 'nextcloud.com foobar', expected: 'nextcloud.com foobar'},
  28. {input: 'http://nextcloud.com foobar', expected: '<a class="external" target="_blank" rel="noopener noreferrer" href="http://nextcloud.com">http://nextcloud.com</a> foobar'},
  29. {input: 'https://nextcloud.com foobar', expected: '<a class="external" target="_blank" rel="noopener noreferrer" href="https://nextcloud.com">nextcloud.com</a> foobar'},
  30. {input: 'hi nextcloud.com foobar', expected: 'hi nextcloud.com foobar'},
  31. {input: 'hi http://nextcloud.com foobar', expected: 'hi <a class="external" target="_blank" rel="noopener noreferrer" href="http://nextcloud.com">http://nextcloud.com</a> foobar'},
  32. {input: 'hi https://nextcloud.com foobar', expected: 'hi <a class="external" target="_blank" rel="noopener noreferrer" href="https://nextcloud.com">nextcloud.com</a> foobar'},
  33. {input: 'hi help.nextcloud.com/category/topic foobar', expected: 'hi help.nextcloud.com/category/topic foobar'},
  34. {input: 'hi http://help.nextcloud.com/category/topic foobar', expected: 'hi <a class="external" target="_blank" rel="noopener noreferrer" href="http://help.nextcloud.com/category/topic">http://help.nextcloud.com/category/topic</a> foobar'},
  35. {input: 'hi https://help.nextcloud.com/category/topic foobar', expected: 'hi <a class="external" target="_blank" rel="noopener noreferrer" href="https://help.nextcloud.com/category/topic">help.nextcloud.com/category/topic</a> foobar'},
  36. {input: 'noreply@nextcloud.com', expected: 'noreply@nextcloud.com'},
  37. {input: 'hi noreply@nextcloud.com', expected: 'hi noreply@nextcloud.com'},
  38. {input: 'hi <noreply@nextcloud.com>', expected: 'hi <noreply@nextcloud.com>'},
  39. {input: 'FirebaseInstanceId.getInstance().deleteInstanceId()', expected: 'FirebaseInstanceId.getInstance().deleteInstanceId()'},
  40. {input: 'I mean...it', expected: 'I mean...it'},
  41. ];
  42. }
  43. it('should parse URLs only', function () {
  44. dataProvider().forEach(function(data) {
  45. var result = OCP.Comments.plainToRich(data.input);
  46. expect(result).toEqual(data.expected);
  47. });
  48. });
  49. });