path-utils.test.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const { isTopPage, convertToNewAffiliationPath } = require('../../lib/util/path-utils');
  2. describe('TopPage Path test', () => {
  3. test('Path is only "/"', () => {
  4. const result = isTopPage('/');
  5. expect(result).toBe(true);
  6. });
  7. test('Path is not match string ', () => {
  8. const result = isTopPage('/test');
  9. expect(result).toBe(false);
  10. });
  11. test('Path is integer', () => {
  12. const result = isTopPage(1);
  13. expect(result).toBe(false);
  14. });
  15. test('Path is null', () => {
  16. const result = isTopPage(null);
  17. expect(result).toBe(false);
  18. });
  19. });
  20. describe('convertToNewAffiliationPath test', () => {
  21. test('Child path is not converted normally', () => {
  22. const result = convertToNewAffiliationPath('parent/', 'parent2/', 'parent/child');
  23. expect(result).toBe('parent2/child');
  24. });
  25. test('Parent path is not converted normally', () => {
  26. const result = convertToNewAffiliationPath('parent/', 'parent3/', 'parent/child');
  27. expect(result === 'parent/child').toBe(false);
  28. });
  29. test('Parent and Child path names are switched unexpectedly', () => {
  30. const result = convertToNewAffiliationPath('parent/', 'parent4/', 'parent/child');
  31. expect(result === 'child/parent4').toBe(false);
  32. });
  33. test('Child path is null', () => {
  34. expect(() => {
  35. convertToNewAffiliationPath('parent/', 'parent5/', null);
  36. }).toThrow();
  37. });
  38. test('Old parent path is null', () => {
  39. expect(() => {
  40. convertToNewAffiliationPath(null, 'parent5/', 'child');
  41. }).toThrow();
  42. });
  43. test('New parent path is null', () => {
  44. expect(() => {
  45. convertToNewAffiliationPath('parent/', null, 'child');
  46. }).toThrow();
  47. });
  48. });