tagStore.spec.jsx 2.3 KB

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