stream.spec.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {objToQuery, queryToObj} from 'sentry/utils/stream';
  2. describe('utils/stream', function () {
  3. describe('queryToObj()', function () {
  4. it('should convert a basic query string to a query object', function () {
  5. expect(queryToObj('is:unresolved')).toEqual({
  6. __text: '',
  7. is: 'unresolved',
  8. });
  9. expect(queryToObj('is:unresolved browser:"Chrome 36"')).toEqual({
  10. __text: '',
  11. is: 'unresolved',
  12. browser: 'Chrome 36',
  13. });
  14. expect(queryToObj('python is:unresolved browser:"Chrome 36"')).toEqual({
  15. __text: 'python',
  16. is: 'unresolved',
  17. browser: 'Chrome 36',
  18. });
  19. });
  20. it('should convert separate query tokens into a single __text property', function () {
  21. expect(queryToObj('python exception')).toEqual({
  22. __text: 'python exception',
  23. });
  24. // NOTE: "python exception" is extracted despite being broken up by "is:unresolved"
  25. expect(queryToObj('python is:unresolved exception')).toEqual({
  26. __text: 'python exception',
  27. is: 'unresolved',
  28. });
  29. });
  30. it('should use empty string as __text and not fail if query is undefined', function () {
  31. expect(queryToObj()).toEqual({
  32. __text: '',
  33. });
  34. });
  35. });
  36. describe('objToQuery()', function () {
  37. it('should convert a query object to a query string', function () {
  38. expect(
  39. objToQuery({
  40. is: 'unresolved',
  41. })
  42. ).toEqual('is:unresolved');
  43. expect(
  44. objToQuery({
  45. is: 'unresolved',
  46. assigned: 'foo@bar.com',
  47. })
  48. ).toEqual('is:unresolved assigned:foo@bar.com');
  49. expect(
  50. objToQuery({
  51. is: 'unresolved',
  52. __text: 'python exception',
  53. })
  54. ).toEqual('is:unresolved python exception');
  55. });
  56. it('should quote query values that contain spaces', function () {
  57. expect(
  58. objToQuery({
  59. browser: 'Chrome 36',
  60. })
  61. ).toEqual('browser:"Chrome 36"');
  62. });
  63. });
  64. });