bulkNotice.spec.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import React from 'react';
  2. import {shallow} from 'sentry-test/enzyme';
  3. import BulkNotice from 'app/components/bulkController/bulkNotice';
  4. const props = {
  5. allRowsCount: 64,
  6. selectedRowsCount: 10,
  7. bulkLimit: undefined,
  8. onUnselectAllRows: () => {},
  9. onSelectAllRows: () => {},
  10. columnsCount: 4,
  11. isPageSelected: false,
  12. isAllSelected: false,
  13. };
  14. describe('BulkNotice', function () {
  15. it('does not render if the whole page is not selected', function () {
  16. const wrapper = shallow(<BulkNotice {...props} />);
  17. expect(wrapper.isEmptyRender()).toBe(true);
  18. });
  19. it('shows the right page summary', function () {
  20. const wrapper = shallow(<BulkNotice {...props} isPageSelected />);
  21. expect(wrapper.text()).toBe(
  22. `${props.selectedRowsCount} items on this page selected. Select all ${props.allRowsCount} items.`
  23. );
  24. expect(
  25. shallow(<BulkNotice {...props} isPageSelected allRowsCount={undefined} />).text()
  26. ).toContain('Select all items across all pages');
  27. expect(
  28. shallow(
  29. <BulkNotice {...props} isPageSelected allRowsCount={1001} bulkLimit={1000} />
  30. ).text()
  31. ).toContain('Select the first 1000 items.');
  32. });
  33. it('can select all rows across all pages', function () {
  34. const onSelectAllRows = jest.fn();
  35. const wrapper = shallow(
  36. <BulkNotice {...props} isPageSelected onSelectAllRows={onSelectAllRows} />
  37. );
  38. wrapper.find('AlertButton').simulate('click');
  39. expect(onSelectAllRows).toHaveBeenCalled();
  40. });
  41. it('can deselect all once everything is selected', function () {
  42. const onUnselectAllRows = jest.fn();
  43. const wrapper = shallow(
  44. <BulkNotice
  45. {...props}
  46. isPageSelected
  47. isAllSelected
  48. onUnselectAllRows={onUnselectAllRows}
  49. />
  50. );
  51. expect(wrapper.text()).toBe(
  52. `Selected all ${props.allRowsCount} items. Cancel selection.`
  53. );
  54. wrapper.find('AlertButton').simulate('click');
  55. expect(onUnselectAllRows).toHaveBeenCalled();
  56. });
  57. it('show the right selected all across all pages summary', function () {
  58. expect(
  59. shallow(
  60. <BulkNotice
  61. {...props}
  62. isPageSelected
  63. isAllSelected
  64. allRowsCount={undefined}
  65. bulkLimit={undefined}
  66. />
  67. ).text()
  68. ).toContain('Selected all items across all pages.');
  69. expect(
  70. shallow(
  71. <BulkNotice
  72. {...props}
  73. isPageSelected
  74. isAllSelected
  75. allRowsCount={123}
  76. bulkLimit={undefined}
  77. />
  78. ).text()
  79. ).toContain('Selected all 123 items.');
  80. expect(
  81. shallow(
  82. <BulkNotice
  83. {...props}
  84. isPageSelected
  85. isAllSelected
  86. allRowsCount={1001}
  87. bulkLimit={1000}
  88. />
  89. ).text()
  90. ).toContain('Selected up to the first 1000 items.');
  91. });
  92. });