Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

71 rinda
2.0 KiB

  1. import test from 'ava';
  2. import {getDomainName, _ipIsValid, isWebExtension, getCurrentUrl, getSite} from '../src/domain/url-parser';
  3. test(t => {
  4. t.is('lesspass.com', getDomainName('https://lesspass.com/#!/'));
  5. t.is('lesspass.com', getDomainName('https://lesspass.com/api/'));
  6. t.is('lesspass.com', getDomainName('https://api.lesspass.com/'));
  7. t.is('192.168.1.1', getDomainName('https://192.168.1.1:10443/webapp/'));
  8. });
  9. test('ip validator', t => {
  10. t.true(_ipIsValid('192.168.23.215'));
  11. t.true(_ipIsValid('127.0.0.1'));
  12. t.false(_ipIsValid('210.110'), 'must have 4 octets');
  13. t.false(_ipIsValid('255'), 'must have 4 octets');
  14. t.false(_ipIsValid('y.y.y.y'), 'only digits are allowed');
  15. t.false(_ipIsValid('255.0.0.y'), 'only digits are allowed');
  16. t.false(_ipIsValid('666.10.10.20'), 'octet number must be between [0-255]');
  17. t.false(_ipIsValid('4444.11.11.11'), 'octet number must be between [0-255]');
  18. t.false(_ipIsValid('33.3333.33.3'), 'octet number must be between [0-255]');
  19. });
  20. test('get web extension context', t => {
  21. global.chrome = undefined;
  22. t.false(isWebExtension())
  23. });
  24. test('get web extension context', t => {
  25. global.chrome = {
  26. tabs: {
  27. query(a, b){
  28. console.log(a, b)
  29. }
  30. }
  31. };
  32. t.true(isWebExtension())
  33. });
  34. test('get current tab', t => {
  35. const url = 'example.org';
  36. global.chrome = {
  37. tabs: {
  38. query(a, callback){
  39. callback([{url}])
  40. }
  41. }
  42. };
  43. return getCurrentUrl().then(currentUrl => {
  44. t.is(currentUrl, url)
  45. });
  46. });
  47. test('get default site', t => {
  48. global.chrome = {
  49. tabs: {
  50. query(a, callback){
  51. callback([{url: 'https://example.org'}])
  52. }
  53. }
  54. };
  55. return getSite().then(site => {
  56. t.is(site, 'example.org')
  57. });
  58. });
  59. test('get default site if not in web extension', t => {
  60. global.chrome = undefined;
  61. return getSite().then(site => {
  62. t.is(site, '')
  63. });
  64. });