useDragNDropColumns.spec.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {useState} from 'react';
  2. import {act, render} from 'sentry-test/reactTestingLibrary';
  3. import {useDragNDropColumns} from './useDragNDropColumns';
  4. describe('useDragNDropColumns', () => {
  5. const initialColumns = ['span.op', 'span_id', 'timestamp'];
  6. it('should insert a column', () => {
  7. let columns, setColumns, insertColumn;
  8. function TestPage() {
  9. [columns, setColumns] = useState(initialColumns);
  10. ({insertColumn} = useDragNDropColumns({columns, setColumns}));
  11. return null;
  12. }
  13. render(<TestPage />, {disableRouterMocks: true});
  14. act(() => {
  15. insertColumn();
  16. });
  17. expect(columns).toEqual(['span.op', 'span_id', 'timestamp', '']);
  18. });
  19. it('should update a column at a specific index', () => {
  20. let columns, setColumns, updateColumnAtIndex;
  21. function TestPage() {
  22. [columns, setColumns] = useState(initialColumns);
  23. ({updateColumnAtIndex} = useDragNDropColumns({columns, setColumns}));
  24. return null;
  25. }
  26. render(<TestPage />, {disableRouterMocks: true});
  27. act(() => {
  28. updateColumnAtIndex(0, 'span.description');
  29. });
  30. expect(columns).toEqual(['span.description', 'span_id', 'timestamp']);
  31. });
  32. it('should delete a column at a specific index', () => {
  33. let columns, setColumns, deleteColumnAtIndex;
  34. function TestPage() {
  35. [columns, setColumns] = useState(initialColumns);
  36. ({deleteColumnAtIndex} = useDragNDropColumns({columns, setColumns}));
  37. return null;
  38. }
  39. render(<TestPage />, {disableRouterMocks: true});
  40. act(() => {
  41. deleteColumnAtIndex(0);
  42. });
  43. expect(columns).toEqual(['span_id', 'timestamp']);
  44. });
  45. it('should swap two columns at specific indices', () => {
  46. let columns, setColumns, onDragEnd;
  47. function TestPage() {
  48. [columns, setColumns] = useState(initialColumns);
  49. ({onDragEnd} = useDragNDropColumns({columns, setColumns}));
  50. return null;
  51. }
  52. render(<TestPage />, {disableRouterMocks: true});
  53. act(() => {
  54. onDragEnd({
  55. active: {id: 1},
  56. over: {id: 3},
  57. });
  58. });
  59. expect(columns).toEqual(['span_id', 'timestamp', 'span.op']);
  60. });
  61. });