Açıklama Yok

utils.spec.ts 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { joinUrl, getFullUrlPath, parseQueryString } from '../src/utils';
  2. describe('Utils', function () {
  3. describe('parseQueryString()', () => {
  4. it('should be defined', () => {
  5. expect(parseQueryString).toBeDefined();
  6. });
  7. it('should parse a query string', () => {
  8. const querystring = 'hello=world&foo=bar';
  9. expect(parseQueryString(querystring)).toEqual({ hello: 'world', foo: 'bar' });
  10. });
  11. });
  12. describe('joinUrl()', () => {
  13. it('should be defined', () => {
  14. expect(joinUrl).toBeDefined();
  15. });
  16. it('should merge baseUrl with relative url', () => {
  17. const baseUrl = 'http://localhost:3000';
  18. const urlPath = '/auth/facebook';
  19. expect(joinUrl(baseUrl, urlPath)).toEqual('http://localhost:3000/auth/facebook');
  20. });
  21. });
  22. describe('getFullUrlPath()', () => {
  23. it('should be defined', () => {
  24. expect(getFullUrlPath).toBeDefined();
  25. });
  26. it('should normalize full url from window.location', () => {
  27. const url1 = getFullUrlPath({
  28. hash: '#/',
  29. host: 'localhost:3000',
  30. hostname: 'localhost',
  31. href: 'http://localhost:3000/#/',
  32. origin: 'http://localhost:3000',
  33. pathname: '/',
  34. port: '3000',
  35. protocol: 'http:',
  36. search: ''
  37. });
  38. const url2 = getFullUrlPath({
  39. protocol: 'http:',
  40. hostname: 'google.com',
  41. port: '',
  42. pathname: '/test'
  43. });
  44. const url3 = getFullUrlPath({
  45. protocol: 'https:',
  46. hostname: 'google.com',
  47. port: '',
  48. pathname: '/test'
  49. });
  50. expect(url1).toEqual('http://localhost:3000/');
  51. expect(url2).toEqual('http://google.com:80/test');
  52. expect(url3).toEqual('https://google.com:443/test');
  53. });
  54. it('should normalize full url from createElement("a")', function () {
  55. const urlElement = document.createElement('a');
  56. urlElement.href = 'http://d4507eb5.ngrok.io/#/';
  57. const url1 = getFullUrlPath(urlElement);
  58. urlElement.href = 'https://google.com/test';
  59. const url2 = getFullUrlPath(urlElement);
  60. urlElement.href = 'http://localhost:3000/';
  61. const url3 = getFullUrlPath(urlElement);
  62. expect(url1).toEqual('http://d4507eb5.ngrok.io:80/');
  63. expect(url2).toEqual('https://google.com:443/test');
  64. expect(url3).toEqual('http://localhost:3000/');
  65. });
  66. });
  67. });