stream.spec.jsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {queryToObj, objToQuery} from 'app/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. });
  31. describe('objToQuery()', function() {
  32. it('should convert a query object to a query string', function() {
  33. expect(
  34. objToQuery({
  35. is: 'unresolved',
  36. })
  37. ).toEqual('is:unresolved');
  38. expect(
  39. objToQuery({
  40. is: 'unresolved',
  41. assigned: 'foo@bar.com',
  42. })
  43. ).toEqual('is:unresolved assigned:foo@bar.com');
  44. expect(
  45. objToQuery({
  46. is: 'unresolved',
  47. __text: 'python exception',
  48. })
  49. ).toEqual('is:unresolved python exception');
  50. });
  51. it('should quote query values that contain spaces', function() {
  52. expect(
  53. objToQuery({
  54. browser: 'Chrome 36',
  55. })
  56. ).toEqual('browser:"Chrome 36"');
  57. });
  58. });
  59. });