tagStore.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import TagStore from 'sentry/stores/tagStore';
  3. describe('TagStore', function () {
  4. beforeEach(() => {
  5. TagStore.reset();
  6. });
  7. afterEach(() => {});
  8. describe('loadTagsSuccess()', () => {
  9. it('should add a new tag with empty values and trigger the new addition', () => {
  10. jest.spyOn(TagStore, 'trigger');
  11. TagStore.loadTagsSuccess([
  12. {
  13. key: 'mytag',
  14. name: 'My Custom Tag',
  15. },
  16. {key: 'other', name: 'Other'},
  17. ]);
  18. const tags = TagStore.getState();
  19. expect(tags.mytag).toEqual({
  20. key: 'mytag',
  21. name: 'My Custom Tag',
  22. values: [],
  23. });
  24. expect(tags.other).toEqual({
  25. key: 'other',
  26. name: 'Other',
  27. values: [],
  28. });
  29. expect(TagStore.trigger).toHaveBeenCalledTimes(1);
  30. });
  31. });
  32. describe('getIssueAttributes()', function () {
  33. it('should populate the has tag with values', () => {
  34. TagStore.loadTagsSuccess([
  35. {
  36. key: 'mytag',
  37. name: 'My Custom Tag',
  38. },
  39. {
  40. key: 'otherkey',
  41. name: 'My other tag',
  42. },
  43. ]);
  44. expect(TagStore.getIssueAttributes().has).toEqual({
  45. key: 'has',
  46. name: 'Has Tag',
  47. values: ['mytag', 'otherkey'],
  48. predefined: true,
  49. });
  50. });
  51. it('should not overwrite predefined filters', () => {
  52. TagStore.loadTagsSuccess([
  53. {
  54. key: 'is',
  55. name: 'Custom Assigned To',
  56. },
  57. ]);
  58. const tags = TagStore.getIssueAttributes();
  59. expect(tags.is).toBeTruthy();
  60. expect(tags.is.key).toBe('is');
  61. expect(tags.assigned).toBeTruthy();
  62. });
  63. it('should replace ignore with archive', () => {
  64. TagStore.loadTagsSuccess([
  65. {
  66. key: 'is',
  67. name: 'Custom Assigned To',
  68. },
  69. ]);
  70. const tags = TagStore.getIssueAttributes();
  71. expect(tags.is.values).toContain('archived');
  72. });
  73. });
  74. describe('getIssueTags()', function () {
  75. it('should have built in, state, and issue attribute tags', () => {
  76. TagStore.loadTagsSuccess([
  77. {
  78. key: 'mytag',
  79. name: 'My Custom Tag',
  80. },
  81. ]);
  82. const tags = TagStore.getIssueTags(OrganizationFixture());
  83. // state
  84. expect(tags.mytag).toBeTruthy();
  85. expect(tags.mytag.key).toBe('mytag');
  86. // attribute
  87. expect(tags.has).toBeTruthy();
  88. expect(tags.has.key).toBe('has');
  89. // built in
  90. expect(tags['device.family']).toBeTruthy();
  91. expect(tags['device.family'].key).toBe('device.family');
  92. });
  93. });
  94. it('returns a stable reference from getState', () => {
  95. TagStore.loadTagsSuccess([
  96. {
  97. key: 'mytag',
  98. name: 'My Custom Tag',
  99. },
  100. ]);
  101. const state = TagStore.getState();
  102. expect(Object.is(state, TagStore.getState())).toBe(true);
  103. });
  104. });