bulkNotice.spec.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  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 = render(<BulkNotice {...props} />);
  16. expect(wrapper.container).toBeEmptyDOMElement();
  17. });
  18. it('shows the right page summary', function () {
  19. const wrapper = render(<BulkNotice {...props} isPageSelected />);
  20. expect(wrapper.container).toHaveTextContent(
  21. `${props.selectedRowsCount} items on this page selected. Select all ${props.allRowsCount} items.`
  22. );
  23. wrapper.rerender(<BulkNotice {...props} isPageSelected allRowsCount={undefined} />);
  24. expect(wrapper.container).toHaveTextContent('Select all items across all pages');
  25. wrapper.rerender(
  26. <BulkNotice {...props} isPageSelected allRowsCount={1001} bulkLimit={1000} />
  27. );
  28. expect(wrapper.container).toHaveTextContent('Select the first 1000 items.');
  29. });
  30. it('can select all rows across all pages', function () {
  31. const onSelectAllRows = jest.fn();
  32. render(<BulkNotice {...props} isPageSelected onSelectAllRows={onSelectAllRows} />);
  33. userEvent.click(screen.getByRole('button', {name: 'Select all 64 items.'}));
  34. expect(onSelectAllRows).toHaveBeenCalled();
  35. });
  36. it('can deselect all once everything is selected', function () {
  37. const onUnselectAllRows = jest.fn();
  38. const wrapper = render(
  39. <BulkNotice
  40. {...props}
  41. isPageSelected
  42. isAllSelected
  43. onUnselectAllRows={onUnselectAllRows}
  44. />
  45. );
  46. expect(wrapper.container).toHaveTextContent(
  47. `Selected all ${props.allRowsCount} items. Cancel selection.`
  48. );
  49. userEvent.click(screen.getByRole('button', {name: 'Cancel selection.'}));
  50. expect(onUnselectAllRows).toHaveBeenCalled();
  51. });
  52. it('show the right selected all across all pages summary', function () {
  53. const wrapper = render(
  54. <BulkNotice
  55. {...props}
  56. isPageSelected
  57. isAllSelected
  58. allRowsCount={undefined}
  59. bulkLimit={undefined}
  60. />
  61. );
  62. expect(wrapper.container).toHaveTextContent('Selected all items across all pages.');
  63. wrapper.rerender(
  64. <BulkNotice
  65. {...props}
  66. isPageSelected
  67. isAllSelected
  68. allRowsCount={123}
  69. bulkLimit={undefined}
  70. />
  71. );
  72. expect(wrapper.container).toHaveTextContent('Selected all 123 items.');
  73. wrapper.rerender(
  74. <BulkNotice
  75. {...props}
  76. isPageSelected
  77. isAllSelected
  78. allRowsCount={1001}
  79. bulkLimit={1000}
  80. />
  81. );
  82. expect(wrapper.container).toHaveTextContent('Selected up to the first 1000 items.');
  83. });
  84. });