index.spec.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import {initializeOrg} from 'app-test/helpers/initializeOrg';
  4. import OrganizationIncidentsList from 'app/views/organizationIncidents/list';
  5. describe('OrganizationIncidentsList', function() {
  6. const {routerContext} = initializeOrg();
  7. let mock;
  8. beforeEach(function() {
  9. mock = MockApiClient.addMockResponse({
  10. url: '/organizations/org-slug/incidents/',
  11. body: [
  12. TestStubs.Incident({id: '123', identifier: '1', title: 'First incident'}),
  13. TestStubs.Incident({id: '342', identifier: '2', title: 'Second incident'}),
  14. ],
  15. });
  16. });
  17. afterEach(function() {
  18. MockApiClient.clearMockResponses();
  19. });
  20. it('displays list', function() {
  21. const wrapper = mount(
  22. <OrganizationIncidentsList params={{orgId: 'org-slug'}} location={{query: {}}} />,
  23. TestStubs.routerContext()
  24. );
  25. const items = wrapper.find('PanelItem');
  26. expect(items).toHaveLength(2);
  27. expect(items.at(0).text()).toContain('First incident');
  28. expect(items.at(1).text()).toContain('Second incident');
  29. });
  30. it('displays empty state', function() {
  31. MockApiClient.addMockResponse({
  32. url: '/organizations/org-slug/incidents/',
  33. body: [],
  34. });
  35. const wrapper = mount(
  36. <OrganizationIncidentsList params={{orgId: 'org-slug'}} location={{query: {}}} />,
  37. routerContext
  38. );
  39. expect(wrapper.find('PanelItem')).toHaveLength(0);
  40. expect(wrapper.text()).toContain("You don't have any incidents yet");
  41. });
  42. it('toggles all/unresolved', function() {
  43. const wrapper = mount(
  44. <OrganizationIncidentsList
  45. params={{orgId: 'org-slug'}}
  46. location={{query: {}, search: ''}}
  47. />,
  48. routerContext
  49. );
  50. expect(
  51. wrapper
  52. .find('.btn-group')
  53. .find('a')
  54. .at(0)
  55. .hasClass('active')
  56. ).toBe(true);
  57. expect(mock).toHaveBeenCalledTimes(1);
  58. expect(mock).toHaveBeenCalledWith(
  59. '/organizations/org-slug/incidents/',
  60. expect.objectContaining({query: {}})
  61. );
  62. wrapper.setProps({location: {query: {status: ''}, search: '?status='}});
  63. expect(
  64. wrapper
  65. .find('.btn-group')
  66. .find('Button')
  67. .at(1)
  68. .hasClass('active')
  69. ).toBe(true);
  70. expect(mock).toHaveBeenCalledTimes(2);
  71. expect(mock).toHaveBeenCalledWith(
  72. '/organizations/org-slug/incidents/',
  73. expect.objectContaining({query: expect.objectContaining({status: ''})})
  74. );
  75. });
  76. });