template.spec.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import type { TemplateSummary } from '../interfaces';
  2. import { getLocalizedTemplate, extractSupportedLocales } from './template';
  3. describe('getLocalizedTemplate', () => {
  4. it('should return undefined if templateSummary is undefined', () => {
  5. expect(getLocalizedTemplate(undefined)).toBeUndefined();
  6. });
  7. it('should return the default template if locale is not provided', () => {
  8. const templateSummary: TemplateSummary = {
  9. default: {
  10. id: 'templateId',
  11. locale: 'en_US',
  12. isValid: true,
  13. isDefault: true,
  14. title: 'Default Title',
  15. },
  16. };
  17. expect(getLocalizedTemplate(templateSummary)).toEqual(templateSummary.default);
  18. });
  19. it('should return the localized template if locale is provided and exists in templateSummary', () => {
  20. const templateSummary: TemplateSummary = {
  21. default: {
  22. id: 'templateId',
  23. locale: 'en_US',
  24. isValid: true,
  25. isDefault: true,
  26. title: 'Default Title',
  27. },
  28. ja_JP: {
  29. id: 'templateId',
  30. locale: 'ja_JP',
  31. isValid: true,
  32. isDefault: false,
  33. title: 'Japanese Title',
  34. },
  35. };
  36. expect(getLocalizedTemplate(templateSummary, 'ja_JP')).toEqual(templateSummary.ja_JP);
  37. });
  38. it('should return the default template if locale is provided but does not exist in templateSummary', () => {
  39. const templateSummary: TemplateSummary = {
  40. default: {
  41. id: 'templateId',
  42. locale: 'en_US',
  43. isValid: true,
  44. isDefault: true,
  45. title: 'Default Title',
  46. },
  47. };
  48. expect(getLocalizedTemplate(templateSummary, 'fr')).toEqual(templateSummary.default);
  49. });
  50. });
  51. describe('extractSupportedLocales', () => {
  52. it('should return undefined if templateSummary is undefined', () => {
  53. expect(extractSupportedLocales(undefined)).toBeUndefined();
  54. });
  55. it('should return a set of locales from the templateSummary', () => {
  56. const templateSummary: TemplateSummary = {
  57. default: {
  58. id: 'templateId',
  59. locale: 'en_US',
  60. isValid: true,
  61. isDefault: true,
  62. title: 'Default Title',
  63. },
  64. ja_JP: {
  65. id: 'templateId',
  66. locale: 'ja_JP',
  67. isValid: true,
  68. isDefault: false,
  69. title: 'Japanese Title',
  70. },
  71. };
  72. expect(extractSupportedLocales(templateSummary)).toEqual(new Set(['en_US', 'ja_JP']));
  73. });
  74. });