globalSelectionLink.spec.jsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React from 'react';
  2. import {shallow} from 'sentry-test/enzyme';
  3. import GlobalSelectionLink from 'app/components/globalSelectionLink';
  4. const path = 'http://some.url/';
  5. describe('GlobalSelectionLink', function() {
  6. it('has global selection values in query', function() {
  7. const query = {
  8. project: ['foo', 'bar'],
  9. environment: 'staging',
  10. };
  11. const wrapper = shallow(
  12. <GlobalSelectionLink to={path}>Go somewhere!</GlobalSelectionLink>,
  13. {
  14. context: {
  15. location: {
  16. query,
  17. },
  18. },
  19. }
  20. );
  21. const updatedToProp = wrapper.find('Link').prop('to');
  22. expect(updatedToProp).toEqual({pathname: path, query});
  23. expect(wrapper).toMatchSnapshot();
  24. });
  25. it('does not have global selection values in query', function() {
  26. const wrapper = shallow(
  27. <GlobalSelectionLink to={path}>Go somewhere!</GlobalSelectionLink>,
  28. {
  29. context: {
  30. location: {
  31. query: {},
  32. },
  33. },
  34. }
  35. );
  36. const updatedToProp = wrapper.find('Link').prop('to');
  37. expect(updatedToProp).toEqual(path);
  38. expect(wrapper).toMatchSnapshot();
  39. });
  40. it('combines query parameters with custom query', function() {
  41. const query = {
  42. project: ['foo', 'bar'],
  43. environment: 'staging',
  44. };
  45. const customQuery = {query: 'something'};
  46. const wrapper = shallow(
  47. <GlobalSelectionLink to={{pathname: path, query: customQuery}}>
  48. Go somewhere!
  49. </GlobalSelectionLink>,
  50. {
  51. context: {
  52. location: {
  53. query,
  54. },
  55. },
  56. }
  57. );
  58. const updatedToProp = wrapper.find('Link').prop('to');
  59. expect(updatedToProp).toEqual({
  60. pathname: path,
  61. query: {project: ['foo', 'bar'], environment: 'staging', query: 'something'},
  62. });
  63. });
  64. it('combines query parameters with no query', function() {
  65. const query = {
  66. project: ['foo', 'bar'],
  67. environment: 'staging',
  68. };
  69. const wrapper = shallow(
  70. <GlobalSelectionLink to={{pathname: path}}>Go somewhere!</GlobalSelectionLink>,
  71. {
  72. context: {
  73. location: {
  74. query,
  75. },
  76. },
  77. }
  78. );
  79. const updatedToProp = wrapper.find('Link').prop('to');
  80. expect(updatedToProp).toEqual({pathname: path, query});
  81. });
  82. });