globalSelectionLink.spec.jsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import GlobalSelectionLink from 'app/components/globalSelectionLink';
  3. const path = 'http://some.url/';
  4. describe('GlobalSelectionLink', function () {
  5. it('has global selection values in query', function () {
  6. const query = {
  7. project: ['foo', 'bar'],
  8. environment: 'staging',
  9. };
  10. const wrapper = mountWithTheme(
  11. <GlobalSelectionLink location={{query}} to={path}>
  12. Go somewhere!
  13. </GlobalSelectionLink>
  14. );
  15. const updatedToProp = wrapper.find('Link').at(0).prop('to');
  16. expect(updatedToProp).toEqual({pathname: path, query});
  17. expect(wrapper).toSnapshot();
  18. });
  19. it('does not have global selection values in query', function () {
  20. const wrapper = mountWithTheme(
  21. <GlobalSelectionLink location={{}} to={path}>
  22. Go somewhere!
  23. </GlobalSelectionLink>
  24. );
  25. const updatedToProp = wrapper.find('Link').at(0).prop('to');
  26. expect(updatedToProp).toEqual(path);
  27. expect(wrapper).toSnapshot();
  28. });
  29. it('combines query parameters with custom query', function () {
  30. const query = {
  31. project: ['foo', 'bar'],
  32. environment: 'staging',
  33. };
  34. const customQuery = {query: 'something'};
  35. const wrapper = mountWithTheme(
  36. <GlobalSelectionLink location={{query}} to={{pathname: path, query: customQuery}}>
  37. Go somewhere!
  38. </GlobalSelectionLink>
  39. );
  40. const updatedToProp = wrapper.find('Link').at(0).prop('to');
  41. expect(updatedToProp).toEqual({
  42. pathname: path,
  43. query: {project: ['foo', 'bar'], environment: 'staging', query: 'something'},
  44. });
  45. });
  46. it('combines query parameters with no query', function () {
  47. const query = {
  48. project: ['foo', 'bar'],
  49. environment: 'staging',
  50. };
  51. const wrapper = mountWithTheme(
  52. <GlobalSelectionLink location={{query}} to={{pathname: path}}>
  53. Go somewhere!
  54. </GlobalSelectionLink>
  55. );
  56. const updatedToProp = wrapper.find('Link').at(0).prop('to');
  57. expect(updatedToProp).toEqual({pathname: path, query});
  58. });
  59. });