bulkNotice.spec.jsx 2.8 KB

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