releaseSeries.spec.jsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import React from 'react';
  2. import {mount} from 'sentry-test/enzyme';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import ReleaseSeries from 'app/components/charts/releaseSeries';
  5. describe('ReleaseSeries', function() {
  6. const renderFunc = jest.fn(() => null);
  7. const {routerContext, organization} = initializeOrg();
  8. const releases = [TestStubs.Release()];
  9. let releasesMock;
  10. beforeEach(function() {
  11. MockApiClient.clearMockResponses();
  12. releasesMock = MockApiClient.addMockResponse({
  13. url: `/organizations/${organization.slug}/releases/`,
  14. body: releases,
  15. });
  16. });
  17. it('does not fetch releases if releases is truthy', function() {
  18. mount(
  19. <ReleaseSeries organization={organization} releases={[]}>
  20. {renderFunc}
  21. </ReleaseSeries>,
  22. routerContext
  23. );
  24. expect(releasesMock).not.toHaveBeenCalled();
  25. });
  26. it('fetches releases if no releases passed through props', async function() {
  27. const wrapper = mount(<ReleaseSeries>{renderFunc}</ReleaseSeries>, routerContext);
  28. await tick();
  29. wrapper.update();
  30. expect(releasesMock).toHaveBeenCalled();
  31. expect(renderFunc).toHaveBeenCalledWith(
  32. expect.objectContaining({
  33. releases,
  34. })
  35. );
  36. });
  37. it('fetches releases with project conditions', async function() {
  38. const wrapper = mount(
  39. <ReleaseSeries projects={[1, 2]}>{renderFunc}</ReleaseSeries>,
  40. routerContext
  41. );
  42. await tick();
  43. wrapper.update();
  44. expect(releasesMock).toHaveBeenCalledWith(
  45. expect.anything(),
  46. expect.objectContaining({
  47. query: {project: [1, 2]},
  48. })
  49. );
  50. });
  51. it('generates an eCharts `markLine` series from releases', async function() {
  52. const wrapper = mount(<ReleaseSeries>{renderFunc}</ReleaseSeries>, routerContext);
  53. await tick();
  54. wrapper.update();
  55. expect(renderFunc).toHaveBeenCalledWith(
  56. expect.objectContaining({
  57. releaseSeries: [
  58. expect.objectContaining({
  59. // we don't care about the other properties for now
  60. markLine: expect.objectContaining({
  61. data: [
  62. expect.objectContaining({
  63. name: '92eccef',
  64. value: '92eccef',
  65. xAxis: 1530206345000,
  66. }),
  67. ],
  68. }),
  69. }),
  70. ],
  71. })
  72. );
  73. });
  74. });