commentsSpec.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. describe('OCP.Comments tests', function() {
  6. function dataProvider() {
  7. return [
  8. {input: 'nextcloud.com', expected: 'nextcloud.com'},
  9. {input: 'http://nextcloud.com', expected: '<a class="external" target="_blank" rel="noopener noreferrer" href="http://nextcloud.com">http://nextcloud.com</a>'},
  10. {input: 'https://nextcloud.com', expected: '<a class="external" target="_blank" rel="noopener noreferrer" href="https://nextcloud.com">nextcloud.com</a>'},
  11. {input: 'hi nextcloud.com', expected: 'hi nextcloud.com'},
  12. {input: 'hi http://nextcloud.com', expected: 'hi <a class="external" target="_blank" rel="noopener noreferrer" href="http://nextcloud.com">http://nextcloud.com</a>'},
  13. {input: 'hi https://nextcloud.com', expected: 'hi <a class="external" target="_blank" rel="noopener noreferrer" href="https://nextcloud.com">nextcloud.com</a>'},
  14. {input: 'nextcloud.com foobar', expected: 'nextcloud.com foobar'},
  15. {input: 'http://nextcloud.com foobar', expected: '<a class="external" target="_blank" rel="noopener noreferrer" href="http://nextcloud.com">http://nextcloud.com</a> foobar'},
  16. {input: 'https://nextcloud.com foobar', expected: '<a class="external" target="_blank" rel="noopener noreferrer" href="https://nextcloud.com">nextcloud.com</a> foobar'},
  17. {input: 'hi nextcloud.com foobar', expected: 'hi nextcloud.com foobar'},
  18. {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'},
  19. {input: 'hi https://nextcloud.com foobar', expected: 'hi <a class="external" target="_blank" rel="noopener noreferrer" href="https://nextcloud.com">nextcloud.com</a> foobar'},
  20. {input: 'hi help.nextcloud.com/category/topic foobar', expected: 'hi help.nextcloud.com/category/topic foobar'},
  21. {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'},
  22. {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'},
  23. {input: 'noreply@nextcloud.com', expected: 'noreply@nextcloud.com'},
  24. {input: 'hi noreply@nextcloud.com', expected: 'hi noreply@nextcloud.com'},
  25. {input: 'hi <noreply@nextcloud.com>', expected: 'hi <noreply@nextcloud.com>'},
  26. {input: 'FirebaseInstanceId.getInstance().deleteInstanceId()', expected: 'FirebaseInstanceId.getInstance().deleteInstanceId()'},
  27. {input: 'I mean...it', expected: 'I mean...it'},
  28. ];
  29. }
  30. it('should parse URLs only', function () {
  31. dataProvider().forEach(function(data) {
  32. var result = OCP.Comments.plainToRich(data.input);
  33. expect(result).toEqual(data.expected);
  34. });
  35. });
  36. });