eventView.spec.jsx 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569
  1. import {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
  2. import EventView, {
  3. isAPIPayloadSimilar,
  4. pickRelevantLocationQueryStrings,
  5. } from 'sentry/utils/discover/eventView';
  6. import {
  7. CHART_AXIS_OPTIONS,
  8. DISPLAY_MODE_OPTIONS,
  9. DisplayModes,
  10. } from 'sentry/utils/discover/types';
  11. const generateFields = fields =>
  12. fields.map(field => ({
  13. field,
  14. }));
  15. const generateSorts = sorts =>
  16. sorts.map(sortName => ({
  17. field: sortName,
  18. kind: 'desc',
  19. }));
  20. describe('EventView constructor', function () {
  21. it('instantiates default values', function () {
  22. const eventView = new EventView({});
  23. expect(eventView).toMatchObject({
  24. id: undefined,
  25. name: undefined,
  26. fields: [],
  27. sorts: [],
  28. query: '',
  29. project: [],
  30. start: undefined,
  31. end: undefined,
  32. statsPeriod: undefined,
  33. environment: [],
  34. yAxis: undefined,
  35. display: undefined,
  36. });
  37. });
  38. });
  39. describe('EventView.fromLocation()', function () {
  40. it('maps query strings', function () {
  41. const location = {
  42. query: {
  43. id: '42',
  44. name: 'best query',
  45. field: ['count()', 'id'],
  46. widths: ['123', '456'],
  47. sort: ['title', '-count'],
  48. query: 'event.type:transaction',
  49. project: [123],
  50. team: ['myteams', '1', '2'],
  51. start: '2019-10-01T00:00:00',
  52. end: '2019-10-02T00:00:00',
  53. statsPeriod: '14d',
  54. environment: ['staging'],
  55. yAxis: 'p95',
  56. display: 'previous',
  57. },
  58. };
  59. const eventView = EventView.fromLocation(location);
  60. expect(eventView).toMatchObject({
  61. id: '42',
  62. name: 'best query',
  63. fields: [
  64. {field: 'count()', width: 123},
  65. {field: 'id', width: 456},
  66. ],
  67. sorts: generateSorts(['count']),
  68. query: 'event.type:transaction',
  69. project: [123],
  70. team: ['myteams', 1, 2],
  71. start: undefined,
  72. end: undefined,
  73. statsPeriod: '14d',
  74. environment: ['staging'],
  75. yAxis: 'p95',
  76. display: 'previous',
  77. });
  78. });
  79. it('includes first valid statsPeriod', function () {
  80. const location = {
  81. query: {
  82. id: '42',
  83. name: 'best query',
  84. field: ['count()', 'id'],
  85. widths: ['123', '456'],
  86. sort: ['title', '-count'],
  87. query: 'event.type:transaction',
  88. project: [123],
  89. start: '2019-10-01T00:00:00',
  90. end: '2019-10-02T00:00:00',
  91. statsPeriod: ['invalid', '28d'],
  92. environment: ['staging'],
  93. },
  94. };
  95. const eventView = EventView.fromLocation(location);
  96. expect(eventView).toMatchObject({
  97. id: '42',
  98. name: 'best query',
  99. fields: [
  100. {field: 'count()', width: 123},
  101. {field: 'id', width: 456},
  102. ],
  103. sorts: generateSorts(['count']),
  104. query: 'event.type:transaction',
  105. project: [123],
  106. start: undefined,
  107. end: undefined,
  108. statsPeriod: '28d',
  109. environment: ['staging'],
  110. });
  111. });
  112. it('includes start and end', function () {
  113. const location = {
  114. query: {
  115. id: '42',
  116. name: 'best query',
  117. field: ['count()', 'id'],
  118. widths: ['123', '456'],
  119. sort: ['title', '-count'],
  120. query: 'event.type:transaction',
  121. project: [123],
  122. start: '2019-10-01T00:00:00',
  123. end: '2019-10-02T00:00:00',
  124. environment: ['staging'],
  125. },
  126. };
  127. const eventView = EventView.fromLocation(location);
  128. expect(eventView).toMatchObject({
  129. id: '42',
  130. name: 'best query',
  131. fields: [
  132. {field: 'count()', width: 123},
  133. {field: 'id', width: 456},
  134. ],
  135. sorts: generateSorts(['count']),
  136. query: 'event.type:transaction',
  137. project: [123],
  138. start: '2019-10-01T00:00:00.000',
  139. end: '2019-10-02T00:00:00.000',
  140. environment: ['staging'],
  141. });
  142. });
  143. it('generates event view when there are no query strings', function () {
  144. const location = {
  145. query: {},
  146. };
  147. const eventView = EventView.fromLocation(location);
  148. expect(eventView).toMatchObject({
  149. id: void 0,
  150. name: void 0,
  151. fields: [],
  152. sorts: [],
  153. query: '',
  154. project: [],
  155. start: void 0,
  156. end: void 0,
  157. statsPeriod: '14d',
  158. environment: [],
  159. yAxis: void 0,
  160. });
  161. });
  162. });
  163. describe('EventView.fromSavedQuery()', function () {
  164. it('maps basic properties of saved query', function () {
  165. const saved = {
  166. id: '42',
  167. name: 'best query',
  168. fields: ['count()', 'id'],
  169. query: 'event.type:transaction',
  170. projects: [123],
  171. teams: ['myteams', 1],
  172. range: '14d',
  173. start: '2019-10-01T00:00:00',
  174. end: '2019-10-02T00:00:00',
  175. orderby: '-id',
  176. environment: ['staging'],
  177. display: 'previous',
  178. };
  179. const eventView = EventView.fromSavedQuery(saved);
  180. expect(eventView).toMatchObject({
  181. id: saved.id,
  182. name: saved.name,
  183. fields: [
  184. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  185. {field: 'id', width: COL_WIDTH_UNDEFINED},
  186. ],
  187. sorts: [{field: 'id', kind: 'desc'}],
  188. query: 'event.type:transaction',
  189. project: [123],
  190. team: ['myteams', 1],
  191. start: undefined,
  192. end: undefined,
  193. // statsPeriod has precedence
  194. statsPeriod: '14d',
  195. environment: ['staging'],
  196. yAxis: undefined,
  197. display: 'previous',
  198. });
  199. const eventView2 = EventView.fromSavedQuery({
  200. ...saved,
  201. range: undefined,
  202. });
  203. expect(eventView2).toMatchObject({
  204. id: saved.id,
  205. name: saved.name,
  206. fields: [
  207. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  208. {field: 'id', width: COL_WIDTH_UNDEFINED},
  209. ],
  210. sorts: [{field: 'id', kind: 'desc'}],
  211. query: 'event.type:transaction',
  212. project: [123],
  213. team: ['myteams', 1],
  214. start: '2019-10-01T00:00:00.000',
  215. end: '2019-10-02T00:00:00.000',
  216. statsPeriod: undefined,
  217. environment: ['staging'],
  218. });
  219. });
  220. it('maps saved query with no conditions', function () {
  221. const saved = {
  222. orderby: '-count',
  223. name: 'foo bar',
  224. fields: ['release', 'count()'],
  225. widths: [111, 222],
  226. dateCreated: '2019-10-30T06:13:17.632078Z',
  227. environment: ['dev', 'production'],
  228. version: 2,
  229. createdBy: '1',
  230. dateUpdated: '2019-10-30T06:13:17.632096Z',
  231. id: '5',
  232. projects: [1],
  233. yAxis: 'count()',
  234. };
  235. const eventView = EventView.fromSavedQuery(saved);
  236. const expected = {
  237. id: '5',
  238. name: 'foo bar',
  239. fields: [
  240. {field: 'release', width: 111},
  241. {field: 'count()', width: 222},
  242. ],
  243. sorts: generateSorts(['count']),
  244. query: '',
  245. project: [1],
  246. environment: ['dev', 'production'],
  247. yAxis: 'count()',
  248. };
  249. expect(eventView).toMatchObject(expected);
  250. });
  251. it('maps properties from v2 saved query', function () {
  252. const saved = {
  253. name: 'best query',
  254. fields: ['count()', 'title'],
  255. range: '14d',
  256. start: '',
  257. end: '',
  258. };
  259. const eventView = EventView.fromSavedQuery(saved);
  260. expect(eventView.fields).toEqual([
  261. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  262. {field: 'title', width: COL_WIDTH_UNDEFINED},
  263. ]);
  264. expect(eventView.name).toEqual(saved.name);
  265. expect(eventView.statsPeriod).toEqual('14d');
  266. expect(eventView.start).toEqual(undefined);
  267. expect(eventView.end).toEqual(undefined);
  268. });
  269. it('saved queries are equal when start and end datetime differ in format', function () {
  270. const saved = {
  271. orderby: '-count_timestamp',
  272. end: '2019-10-23T19:27:04+0000',
  273. name: 'release query',
  274. fields: ['release', 'count(timestamp)'],
  275. dateCreated: '2019-10-30T05:10:23.718937Z',
  276. environment: ['dev', 'production'],
  277. start: '2019-10-20T21:02:51+0000',
  278. version: 2,
  279. createdBy: '1',
  280. dateUpdated: '2019-10-30T07:25:58.291917Z',
  281. id: '3',
  282. projects: [1],
  283. };
  284. const eventView = EventView.fromSavedQuery(saved);
  285. const eventView2 = EventView.fromSavedQuery({
  286. ...saved,
  287. start: '2019-10-20T21:02:51Z',
  288. end: '2019-10-23T19:27:04Z',
  289. });
  290. expect(eventView.isEqualTo(eventView2)).toBe(true);
  291. const eventView3 = EventView.fromSavedQuery({
  292. ...saved,
  293. start: '2019-10-20T21:02:51Z',
  294. });
  295. expect(eventView.isEqualTo(eventView3)).toBe(true);
  296. const eventView4 = EventView.fromSavedQuery({
  297. ...saved,
  298. end: '2019-10-23T19:27:04Z',
  299. });
  300. expect(eventView.isEqualTo(eventView4)).toBe(true);
  301. });
  302. it('saved queries are not equal when datetime selection are invalid', function () {
  303. const saved = {
  304. orderby: '-count_timestamp',
  305. end: '2019-10-23T19:27:04+0000',
  306. name: 'release query',
  307. fields: ['release', 'count(timestamp)'],
  308. dateCreated: '2019-10-30T05:10:23.718937Z',
  309. environment: ['dev', 'production'],
  310. start: '2019-10-20T21:02:51+0000',
  311. version: 2,
  312. createdBy: '1',
  313. dateUpdated: '2019-10-30T07:25:58.291917Z',
  314. id: '3',
  315. projects: [1],
  316. };
  317. const eventView = EventView.fromSavedQuery(saved);
  318. const eventView2 = EventView.fromSavedQuery({
  319. ...saved,
  320. start: '',
  321. });
  322. expect(eventView.isEqualTo(eventView2)).toBe(false);
  323. const eventView3 = EventView.fromSavedQuery({
  324. ...saved,
  325. end: '',
  326. });
  327. expect(eventView.isEqualTo(eventView3)).toBe(false);
  328. // this is expected since datetime (start and end) are normalized
  329. expect(eventView2.isEqualTo(eventView3)).toBe(true);
  330. });
  331. it('saved queries with undefined yAxis are defaulted to count() when comparing with isEqualTo', function () {
  332. const saved = {
  333. orderby: '-count_timestamp',
  334. end: '2019-10-23T19:27:04+0000',
  335. name: 'release query',
  336. fields: ['release', 'count(timestamp)'],
  337. dateCreated: '2019-10-30T05:10:23.718937Z',
  338. environment: ['dev', 'production'],
  339. start: '2019-10-20T21:02:51+0000',
  340. version: 2,
  341. createdBy: '1',
  342. dateUpdated: '2019-10-30T07:25:58.291917Z',
  343. id: '3',
  344. projects: [1],
  345. };
  346. const eventView = EventView.fromSavedQuery(saved);
  347. const eventView2 = EventView.fromSavedQuery({
  348. ...saved,
  349. yAxis: 'count()',
  350. });
  351. expect(eventView.isEqualTo(eventView2)).toBe(true);
  352. });
  353. it('uses the first yAxis from the SavedQuery', function () {
  354. const saved = {
  355. id: '42',
  356. name: 'best query',
  357. fields: ['count()', 'id'],
  358. query: 'event.type:transaction',
  359. projects: [123],
  360. teams: ['myteams', 1],
  361. range: '14d',
  362. start: '2019-10-01T00:00:00',
  363. end: '2019-10-02T00:00:00',
  364. orderby: '-id',
  365. environment: ['staging'],
  366. display: 'previous',
  367. yAxis: ['count()'],
  368. };
  369. const eventView = EventView.fromSavedQuery(saved);
  370. expect(eventView).toMatchObject({
  371. id: saved.id,
  372. name: saved.name,
  373. fields: [
  374. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  375. {field: 'id', width: COL_WIDTH_UNDEFINED},
  376. ],
  377. sorts: [{field: 'id', kind: 'desc'}],
  378. query: 'event.type:transaction',
  379. project: [123],
  380. team: ['myteams', 1],
  381. start: undefined,
  382. end: undefined,
  383. statsPeriod: '14d',
  384. environment: ['staging'],
  385. yAxis: 'count()',
  386. display: 'previous',
  387. });
  388. });
  389. it('preserves utc with start/end', function () {
  390. const saved = {
  391. name: 'best query',
  392. query: 'event.type:transaction',
  393. fields: ['count()', 'title'],
  394. start: '2019-10-20T21:02:51+0000',
  395. end: '2019-10-23T19:27:04+0000',
  396. utc: 'true',
  397. };
  398. const eventView = EventView.fromSavedQuery(saved);
  399. expect(eventView).toMatchObject({
  400. id: saved.id,
  401. name: saved.name,
  402. fields: [
  403. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  404. {field: 'title', width: COL_WIDTH_UNDEFINED},
  405. ],
  406. query: 'event.type:transaction',
  407. start: '2019-10-20T21:02:51.000',
  408. end: '2019-10-23T19:27:04.000',
  409. utc: 'true',
  410. });
  411. });
  412. });
  413. describe('EventView.fromNewQueryWithLocation()', function () {
  414. const prebuiltQuery = {
  415. id: undefined,
  416. name: 'All Events',
  417. query: '',
  418. projects: [],
  419. fields: ['title', 'event.type', 'project', 'user', 'timestamp'],
  420. orderby: '-timestamp',
  421. version: 2,
  422. };
  423. it('maps basic properties of a prebuilt query', function () {
  424. const location = {
  425. query: {
  426. statsPeriod: '99d',
  427. },
  428. };
  429. const eventView = EventView.fromNewQueryWithLocation(prebuiltQuery, location);
  430. expect(eventView).toMatchObject({
  431. id: undefined,
  432. name: 'All Events',
  433. fields: [
  434. {field: 'title'},
  435. {field: 'event.type'},
  436. {field: 'project'},
  437. {field: 'user'},
  438. {field: 'timestamp'},
  439. ],
  440. sorts: [{field: 'timestamp', kind: 'desc'}],
  441. query: '',
  442. project: [],
  443. start: undefined,
  444. end: undefined,
  445. // statsPeriod has precedence
  446. statsPeriod: '99d',
  447. environment: [],
  448. yAxis: undefined,
  449. });
  450. });
  451. it('merges global selection values', function () {
  452. const location = {
  453. query: {
  454. statsPeriod: '99d',
  455. project: ['456'],
  456. environment: ['prod'],
  457. },
  458. };
  459. const eventView = EventView.fromNewQueryWithLocation(prebuiltQuery, location);
  460. expect(eventView).toMatchObject({
  461. id: undefined,
  462. name: 'All Events',
  463. fields: [
  464. {field: 'title'},
  465. {field: 'event.type'},
  466. {field: 'project'},
  467. {field: 'user'},
  468. {field: 'timestamp'},
  469. ],
  470. sorts: [{field: 'timestamp', kind: 'desc'}],
  471. query: '',
  472. project: [456],
  473. start: undefined,
  474. end: undefined,
  475. statsPeriod: '99d',
  476. environment: ['prod'],
  477. yAxis: undefined,
  478. });
  479. });
  480. it('new query takes precedence over global selection values', function () {
  481. const location = {
  482. query: {
  483. statsPeriod: '99d',
  484. project: ['456'],
  485. environment: ['prod'],
  486. },
  487. };
  488. const prebuiltQuery2 = {
  489. ...prebuiltQuery,
  490. range: '42d',
  491. projects: [987],
  492. environment: ['staging'],
  493. };
  494. const eventView = EventView.fromNewQueryWithLocation(prebuiltQuery2, location);
  495. expect(eventView).toMatchObject({
  496. id: undefined,
  497. name: 'All Events',
  498. fields: [
  499. {field: 'title'},
  500. {field: 'event.type'},
  501. {field: 'project'},
  502. {field: 'user'},
  503. {field: 'timestamp'},
  504. ],
  505. sorts: [{field: 'timestamp', kind: 'desc'}],
  506. query: '',
  507. project: [987],
  508. start: undefined,
  509. end: undefined,
  510. statsPeriod: '42d',
  511. environment: ['staging'],
  512. yAxis: undefined,
  513. });
  514. // also test start and end
  515. const location2 = {
  516. query: {
  517. start: '2019-10-01T00:00:00',
  518. end: '2019-10-02T00:00:00',
  519. project: ['456'],
  520. environment: ['prod'],
  521. },
  522. };
  523. const prebuiltQuery3 = {
  524. ...prebuiltQuery,
  525. start: '2019-10-01T00:00:00',
  526. end: '2019-10-02T00:00:00',
  527. projects: [987],
  528. environment: ['staging'],
  529. };
  530. const eventView2 = EventView.fromNewQueryWithLocation(prebuiltQuery3, location2);
  531. expect(eventView2).toMatchObject({
  532. id: undefined,
  533. name: 'All Events',
  534. fields: [
  535. {field: 'title'},
  536. {field: 'event.type'},
  537. {field: 'project'},
  538. {field: 'user'},
  539. {field: 'timestamp'},
  540. ],
  541. sorts: [{field: 'timestamp', kind: 'desc'}],
  542. query: '',
  543. project: [987],
  544. start: '2019-10-01T00:00:00.000',
  545. end: '2019-10-02T00:00:00.000',
  546. statsPeriod: undefined,
  547. environment: ['staging'],
  548. yAxis: undefined,
  549. });
  550. });
  551. });
  552. describe('EventView.fromSavedQueryOrLocation()', function () {
  553. it('maps basic properties of saved query', function () {
  554. const saved = {
  555. id: '42',
  556. name: 'best query',
  557. fields: ['count()', 'id'],
  558. query: 'event.type:transaction',
  559. projects: [123],
  560. range: '14d',
  561. start: '2019-10-01T00:00:00',
  562. end: '2019-10-02T00:00:00',
  563. orderby: '-id',
  564. environment: ['staging'],
  565. display: 'previous',
  566. };
  567. const location = {
  568. query: {
  569. statsPeriod: '14d',
  570. project: ['123'],
  571. team: ['myteams', '1', '2'],
  572. environment: ['staging'],
  573. },
  574. };
  575. const eventView = EventView.fromSavedQueryOrLocation(saved, location);
  576. expect(eventView).toMatchObject({
  577. id: saved.id,
  578. name: saved.name,
  579. fields: [
  580. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  581. {field: 'id', width: COL_WIDTH_UNDEFINED},
  582. ],
  583. sorts: [{field: 'id', kind: 'desc'}],
  584. query: 'event.type:transaction',
  585. project: [123],
  586. team: ['myteams', 1, 2],
  587. start: undefined,
  588. end: undefined,
  589. // statsPeriod has precedence
  590. statsPeriod: '14d',
  591. environment: ['staging'],
  592. yAxis: undefined,
  593. display: 'previous',
  594. });
  595. const savedQuery2 = {...saved, range: undefined};
  596. const location2 = {
  597. query: {
  598. project: ['123'],
  599. environment: ['staging'],
  600. start: '2019-10-01T00:00:00',
  601. end: '2019-10-02T00:00:00',
  602. },
  603. };
  604. const eventView2 = EventView.fromSavedQueryOrLocation(savedQuery2, location2);
  605. expect(eventView2).toMatchObject({
  606. id: saved.id,
  607. name: saved.name,
  608. fields: [
  609. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  610. {field: 'id', width: COL_WIDTH_UNDEFINED},
  611. ],
  612. sorts: [{field: 'id', kind: 'desc'}],
  613. query: 'event.type:transaction',
  614. project: [123],
  615. start: '2019-10-01T00:00:00.000',
  616. end: '2019-10-02T00:00:00.000',
  617. statsPeriod: undefined,
  618. environment: ['staging'],
  619. });
  620. });
  621. it('overrides saved query params with location params', function () {
  622. const saved = {
  623. id: '42',
  624. name: 'best query',
  625. fields: ['count()', 'id'],
  626. query: 'event.type:transaction',
  627. projects: [123],
  628. range: '14d',
  629. start: '2019-10-01T00:00:00',
  630. end: '2019-10-02T00:00:00',
  631. orderby: '-id',
  632. environment: ['staging'],
  633. display: 'previous',
  634. };
  635. const location = {
  636. query: {
  637. id: '42',
  638. statsPeriod: '7d',
  639. project: ['3'],
  640. },
  641. };
  642. const eventView = EventView.fromSavedQueryOrLocation(saved, location);
  643. expect(eventView).toMatchObject({
  644. id: saved.id,
  645. name: saved.name,
  646. fields: [
  647. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  648. {field: 'id', width: COL_WIDTH_UNDEFINED},
  649. ],
  650. sorts: [{field: 'id', kind: 'desc'}],
  651. query: 'event.type:transaction',
  652. project: [3],
  653. start: undefined,
  654. end: undefined,
  655. // statsPeriod has precedence
  656. statsPeriod: '7d',
  657. environment: [],
  658. yAxis: undefined,
  659. display: 'previous',
  660. });
  661. });
  662. it('maps saved query with no conditions', function () {
  663. const saved = {
  664. orderby: '-count',
  665. name: 'foo bar',
  666. fields: ['release', 'count()'],
  667. widths: [111, 222],
  668. dateCreated: '2019-10-30T06:13:17.632078Z',
  669. query: '',
  670. environment: [],
  671. version: 2,
  672. createdBy: '1',
  673. dateUpdated: '2019-10-30T06:13:17.632096Z',
  674. id: '5',
  675. yAxis: 'count()',
  676. };
  677. const location = {
  678. query: {
  679. id: '5',
  680. project: [1],
  681. },
  682. };
  683. const eventView = EventView.fromSavedQueryOrLocation(saved, location);
  684. const expected = {
  685. id: '5',
  686. name: 'foo bar',
  687. fields: [
  688. {field: 'release', width: 111},
  689. {field: 'count()', width: 222},
  690. ],
  691. sorts: generateSorts(['count']),
  692. query: '',
  693. project: [1],
  694. yAxis: 'count()',
  695. };
  696. expect(eventView).toMatchObject(expected);
  697. });
  698. it('maps query with cleared conditions', function () {
  699. const saved = {
  700. id: '42',
  701. name: 'best query',
  702. fields: ['count()', 'id'],
  703. query: 'event.type:transaction',
  704. projects: [123],
  705. range: '14d',
  706. start: '2019-10-01T00:00:00',
  707. end: '2019-10-02T00:00:00',
  708. orderby: '-id',
  709. environment: ['staging'],
  710. display: 'previous',
  711. };
  712. const location = {
  713. query: {
  714. id: '42',
  715. statsPeriod: '7d',
  716. },
  717. };
  718. const eventView = EventView.fromSavedQueryOrLocation(saved, location);
  719. expect(eventView).toMatchObject({
  720. id: saved.id,
  721. name: saved.name,
  722. fields: [
  723. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  724. {field: 'id', width: COL_WIDTH_UNDEFINED},
  725. ],
  726. sorts: [{field: 'id', kind: 'desc'}],
  727. query: 'event.type:transaction',
  728. start: undefined,
  729. end: undefined,
  730. // statsPeriod has precedence
  731. statsPeriod: '7d',
  732. environment: [],
  733. yAxis: undefined,
  734. display: 'previous',
  735. });
  736. const location2 = {
  737. query: {
  738. id: '42',
  739. statsPeriod: '7d',
  740. query: '',
  741. },
  742. };
  743. const eventView2 = EventView.fromSavedQueryOrLocation(saved, location2);
  744. expect(eventView2).toMatchObject({
  745. id: saved.id,
  746. name: saved.name,
  747. fields: [
  748. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  749. {field: 'id', width: COL_WIDTH_UNDEFINED},
  750. ],
  751. sorts: [{field: 'id', kind: 'desc'}],
  752. query: '',
  753. start: undefined,
  754. end: undefined,
  755. // statsPeriod has precedence
  756. statsPeriod: '7d',
  757. environment: [],
  758. yAxis: undefined,
  759. display: 'previous',
  760. });
  761. });
  762. it('event views are equal when start and end datetime differ in format', function () {
  763. const saved = {
  764. orderby: '-count_timestamp',
  765. end: '2019-10-23T19:27:04+0000',
  766. name: 'release query',
  767. fields: ['release', 'count(timestamp)'],
  768. dateCreated: '2019-10-30T05:10:23.718937Z',
  769. environment: ['dev', 'production'],
  770. start: '2019-10-20T21:02:51+0000',
  771. version: 2,
  772. createdBy: '1',
  773. dateUpdated: '2019-10-30T07:25:58.291917Z',
  774. id: '3',
  775. };
  776. const location = {
  777. query: {
  778. id: '3',
  779. start: '2019-10-20T21:02:51+0000',
  780. end: '2019-10-23T19:27:04+0000',
  781. },
  782. };
  783. const eventView = EventView.fromSavedQueryOrLocation(saved, location);
  784. const location2 = {
  785. query: {
  786. id: '3',
  787. start: '2019-10-20T21:02:51Z',
  788. end: '2019-10-23T19:27:04Z',
  789. },
  790. };
  791. const eventView2 = EventView.fromSavedQueryOrLocation(saved, location2);
  792. expect(eventView.isEqualTo(eventView2)).toBe(true);
  793. const location3 = {
  794. query: {
  795. id: '3',
  796. start: '2019-10-20T21:02:51Z',
  797. end: '2019-10-23T19:27:04+0000',
  798. },
  799. };
  800. const eventView3 = EventView.fromSavedQueryOrLocation(saved, location3);
  801. expect(eventView.isEqualTo(eventView3)).toBe(true);
  802. const location4 = {
  803. query: {
  804. id: '3',
  805. start: '2019-10-20T21:02:51+0000',
  806. end: '2019-10-23T19:27:04Z',
  807. },
  808. };
  809. const eventView4 = EventView.fromSavedQueryOrLocation(saved, location4);
  810. expect(eventView.isEqualTo(eventView4)).toBe(true);
  811. });
  812. it('event views are not equal when datetime selection are invalid', function () {
  813. const saved = {
  814. orderby: '-count_timestamp',
  815. end: '2019-10-23T19:27:04+0000',
  816. name: 'release query',
  817. fields: ['release', 'count(timestamp)'],
  818. dateCreated: '2019-10-30T05:10:23.718937Z',
  819. environment: ['dev', 'production'],
  820. start: '2019-10-20T21:02:51+0000',
  821. version: 2,
  822. createdBy: '1',
  823. dateUpdated: '2019-10-30T07:25:58.291917Z',
  824. id: '3',
  825. projects: [1],
  826. };
  827. const location = {
  828. query: {
  829. id: '3',
  830. end: '2019-10-23T19:27:04+0000',
  831. start: '2019-10-20T21:02:51+0000',
  832. },
  833. };
  834. const eventView = EventView.fromSavedQueryOrLocation(saved, location);
  835. const location2 = {
  836. query: {
  837. id: '3',
  838. end: '2019-10-23T19:27:04+0000',
  839. start: '',
  840. },
  841. };
  842. const eventView2 = EventView.fromSavedQueryOrLocation(saved, location2);
  843. expect(eventView.isEqualTo(eventView2)).toBe(false);
  844. const location3 = {
  845. query: {
  846. id: '3',
  847. end: '',
  848. start: '2019-10-20T21:02:51+0000',
  849. },
  850. };
  851. const eventView3 = EventView.fromSavedQueryOrLocation(saved, location3);
  852. expect(eventView.isEqualTo(eventView3)).toBe(false);
  853. // this is expected since datetime (start and end) are normalized
  854. expect(eventView2.isEqualTo(eventView3)).toBe(true);
  855. });
  856. it('uses the first yAxis from the SavedQuery', function () {
  857. const saved = {
  858. id: '42',
  859. name: 'best query',
  860. fields: ['count()', 'id'],
  861. query: 'event.type:transaction',
  862. projects: [123],
  863. range: '14d',
  864. start: '2019-10-01T00:00:00',
  865. end: '2019-10-02T00:00:00',
  866. orderby: '-id',
  867. environment: ['staging'],
  868. display: 'previous',
  869. yAxis: ['count()', 'failure_count()'],
  870. };
  871. const location = {
  872. query: {
  873. statsPeriod: '14d',
  874. project: ['123'],
  875. team: ['myteams', '1', '2'],
  876. environment: ['staging'],
  877. },
  878. };
  879. const eventView = EventView.fromSavedQueryOrLocation(saved, location);
  880. expect(eventView).toMatchObject({
  881. id: saved.id,
  882. name: saved.name,
  883. fields: [
  884. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  885. {field: 'id', width: COL_WIDTH_UNDEFINED},
  886. ],
  887. sorts: [{field: 'id', kind: 'desc'}],
  888. query: 'event.type:transaction',
  889. project: [123],
  890. team: ['myteams', 1, 2],
  891. start: undefined,
  892. end: undefined,
  893. statsPeriod: '14d',
  894. environment: ['staging'],
  895. yAxis: 'count()',
  896. display: 'previous',
  897. });
  898. });
  899. it('filters out invalid teams', function () {
  900. const eventView = EventView.fromSavedQueryOrLocation(undefined, {
  901. query: {
  902. statsPeriod: '14d',
  903. project: ['123'],
  904. team: ['myteams', '1', 'unassigned'],
  905. environment: ['staging'],
  906. },
  907. });
  908. expect(eventView.team).toEqual(['myteams', 1]);
  909. });
  910. });
  911. describe('EventView.generateQueryStringObject()', function () {
  912. it('skips empty values', function () {
  913. const eventView = new EventView({
  914. fields: generateFields(['id', 'title']),
  915. sorts: [],
  916. project: [],
  917. environment: '',
  918. statsPeriod: '',
  919. start: null,
  920. end: undefined,
  921. yAxis: undefined,
  922. display: 'previous',
  923. });
  924. const expected = {
  925. id: undefined,
  926. name: undefined,
  927. field: ['id', 'title'],
  928. widths: [],
  929. sort: [],
  930. query: '',
  931. project: [],
  932. environment: [],
  933. display: 'previous',
  934. yAxis: 'count()',
  935. };
  936. expect(eventView.generateQueryStringObject()).toEqual(expected);
  937. });
  938. it('generates query string object', function () {
  939. const state = {
  940. id: '1234',
  941. name: 'best query',
  942. fields: [
  943. {field: 'count()', width: 123},
  944. {field: 'project.id', width: 456},
  945. ],
  946. sorts: generateSorts(['count']),
  947. query: 'event.type:error',
  948. project: [42],
  949. start: '2019-10-01T00:00:00',
  950. end: '2019-10-02T00:00:00',
  951. statsPeriod: '14d',
  952. environment: ['staging'],
  953. yAxis: 'count()',
  954. display: 'releases',
  955. interval: '1m',
  956. };
  957. const eventView = new EventView(state);
  958. const expected = {
  959. id: '1234',
  960. name: 'best query',
  961. field: ['count()', 'project.id'],
  962. widths: [123, 456],
  963. sort: ['-count'],
  964. query: 'event.type:error',
  965. project: [42],
  966. start: '2019-10-01T00:00:00',
  967. end: '2019-10-02T00:00:00',
  968. statsPeriod: '14d',
  969. environment: ['staging'],
  970. yAxis: 'count()',
  971. display: 'releases',
  972. interval: '1m',
  973. };
  974. expect(eventView.generateQueryStringObject()).toEqual(expected);
  975. });
  976. it('encodes fields', function () {
  977. const eventView = new EventView({
  978. fields: [{field: 'id'}, {field: 'title'}],
  979. sorts: [],
  980. });
  981. const query = eventView.generateQueryStringObject();
  982. expect(query.field).toEqual(['id', 'title']);
  983. });
  984. it('returns a copy of data preventing mutation', function () {
  985. const eventView = new EventView({
  986. fields: [{field: 'id'}, {field: 'title'}],
  987. sorts: [],
  988. });
  989. const query = eventView.generateQueryStringObject();
  990. query.field.push('newthing');
  991. // Getting the query again should return the original values.
  992. const secondQuery = eventView.generateQueryStringObject();
  993. expect(secondQuery.field).toEqual(['id', 'title']);
  994. expect(query).not.toEqual(secondQuery);
  995. });
  996. });
  997. describe('EventView.getEventsAPIPayload()', function () {
  998. it('generates the API payload', function () {
  999. const eventView = new EventView({
  1000. id: 34,
  1001. name: 'amazing query',
  1002. fields: generateFields(['id']),
  1003. sorts: generateSorts(['id']),
  1004. query: 'event.type:csp',
  1005. project: [567],
  1006. environment: ['prod'],
  1007. yAxis: 'users',
  1008. display: 'releases',
  1009. });
  1010. expect(eventView.getEventsAPIPayload({})).toEqual({
  1011. field: ['id'],
  1012. per_page: 50,
  1013. sort: '-id',
  1014. query: 'event.type:csp',
  1015. project: ['567'],
  1016. environment: ['prod'],
  1017. statsPeriod: '14d',
  1018. });
  1019. });
  1020. it('does not append query conditions in location', function () {
  1021. const eventView = new EventView({
  1022. fields: generateFields(['id']),
  1023. sorts: [],
  1024. query: 'event.type:csp',
  1025. });
  1026. const location = {
  1027. query: {
  1028. query: 'TypeError',
  1029. },
  1030. };
  1031. expect(eventView.getEventsAPIPayload(location).query).toEqual('event.type:csp');
  1032. });
  1033. it('only includes at most one sort key', function () {
  1034. const eventView = new EventView({
  1035. fields: generateFields(['count()', 'title']),
  1036. sorts: generateSorts(['title', 'count']),
  1037. query: 'event.type:csp',
  1038. });
  1039. const location = {
  1040. query: {},
  1041. };
  1042. expect(eventView.getEventsAPIPayload(location).sort).toEqual('-title');
  1043. });
  1044. it('only includes sort keys that are defined in fields', function () {
  1045. const eventView = new EventView({
  1046. fields: generateFields(['title', 'count()']),
  1047. sorts: generateSorts(['project', 'count']),
  1048. query: 'event.type:csp',
  1049. });
  1050. const location = {
  1051. query: {},
  1052. };
  1053. expect(eventView.getEventsAPIPayload(location).sort).toEqual('-count');
  1054. });
  1055. it('only includes relevant query strings', function () {
  1056. const eventView = new EventView({
  1057. fields: generateFields(['title', 'count()']),
  1058. sorts: generateSorts(['project', 'count']),
  1059. query: 'event.type:csp',
  1060. });
  1061. const location = {
  1062. query: {
  1063. start: '2020-08-12 12:13:14',
  1064. end: '2020-08-26 12:13:14',
  1065. utc: 'true',
  1066. statsPeriod: '14d',
  1067. cursor: 'some cursor',
  1068. yAxis: 'count()',
  1069. // irrelevant query strings
  1070. bestCountry: 'canada',
  1071. project: '1234',
  1072. environment: ['staging'],
  1073. },
  1074. };
  1075. expect(eventView.getEventsAPIPayload(location)).toEqual({
  1076. project: [],
  1077. environment: [],
  1078. utc: 'true',
  1079. statsPeriod: '14d',
  1080. field: ['title', 'count()'],
  1081. per_page: 50,
  1082. query: 'event.type:csp',
  1083. sort: '-count',
  1084. cursor: 'some cursor',
  1085. });
  1086. });
  1087. it('includes default coerced statsPeriod when omitted or is invalid', function () {
  1088. const eventView = new EventView({
  1089. fields: generateFields(['title', 'count()']),
  1090. sorts: generateSorts(['project', 'count']),
  1091. query: 'event.type:csp',
  1092. project: [1234],
  1093. environment: ['staging'],
  1094. });
  1095. const location = {
  1096. query: {
  1097. start: '',
  1098. end: '',
  1099. utc: 'true',
  1100. // invalid statsPeriod string
  1101. statsPeriod: 'invalid',
  1102. cursor: 'some cursor',
  1103. },
  1104. };
  1105. expect(eventView.getEventsAPIPayload(location)).toEqual({
  1106. project: ['1234'],
  1107. environment: ['staging'],
  1108. utc: 'true',
  1109. statsPeriod: '14d',
  1110. field: ['title', 'count()'],
  1111. per_page: 50,
  1112. query: 'event.type:csp',
  1113. sort: '-count',
  1114. cursor: 'some cursor',
  1115. });
  1116. const location2 = {
  1117. query: {
  1118. start: '',
  1119. end: '',
  1120. utc: 'true',
  1121. // statsPeriod is omitted here
  1122. cursor: 'some cursor',
  1123. },
  1124. };
  1125. expect(eventView.getEventsAPIPayload(location2)).toEqual({
  1126. project: ['1234'],
  1127. environment: ['staging'],
  1128. utc: 'true',
  1129. statsPeriod: '14d',
  1130. field: ['title', 'count()'],
  1131. per_page: 50,
  1132. query: 'event.type:csp',
  1133. sort: '-count',
  1134. cursor: 'some cursor',
  1135. });
  1136. });
  1137. it('includes default coerced statsPeriod when either start or end is only provided', function () {
  1138. const eventView = new EventView({
  1139. fields: generateFields(['title', 'count()']),
  1140. sorts: generateSorts(['project', 'count']),
  1141. query: 'event.type:csp',
  1142. project: [1234],
  1143. environment: ['staging'],
  1144. });
  1145. const location = {
  1146. query: {
  1147. start: '',
  1148. utc: 'true',
  1149. statsPeriod: 'invalid',
  1150. cursor: 'some cursor',
  1151. },
  1152. };
  1153. expect(eventView.getEventsAPIPayload(location)).toEqual({
  1154. project: ['1234'],
  1155. environment: ['staging'],
  1156. utc: 'true',
  1157. statsPeriod: '14d',
  1158. field: ['title', 'count()'],
  1159. per_page: 50,
  1160. query: 'event.type:csp',
  1161. sort: '-count',
  1162. cursor: 'some cursor',
  1163. });
  1164. const location2 = {
  1165. query: {
  1166. end: '',
  1167. utc: 'true',
  1168. statsPeriod: 'invalid',
  1169. cursor: 'some cursor',
  1170. },
  1171. };
  1172. expect(eventView.getEventsAPIPayload(location2)).toEqual({
  1173. project: ['1234'],
  1174. environment: ['staging'],
  1175. utc: 'true',
  1176. statsPeriod: '14d',
  1177. field: ['title', 'count()'],
  1178. per_page: 50,
  1179. query: 'event.type:csp',
  1180. sort: '-count',
  1181. cursor: 'some cursor',
  1182. });
  1183. });
  1184. it('includes start and end', function () {
  1185. const eventView = new EventView({
  1186. fields: generateFields(['title', 'count()']),
  1187. sorts: generateSorts(['count']),
  1188. query: 'event.type:csp',
  1189. start: '2019-10-01T00:00:00',
  1190. end: '2019-10-02T00:00:00',
  1191. environment: [],
  1192. project: [],
  1193. });
  1194. const location = {
  1195. query: {
  1196. // these should not be part of the API payload
  1197. statsPeriod: '55d',
  1198. period: '55d',
  1199. },
  1200. };
  1201. expect(eventView.getEventsAPIPayload(location)).toEqual({
  1202. field: ['title', 'count()'],
  1203. sort: '-count',
  1204. query: 'event.type:csp',
  1205. start: '2019-10-01T00:00:00.000',
  1206. end: '2019-10-02T00:00:00.000',
  1207. per_page: 50,
  1208. project: [],
  1209. environment: [],
  1210. });
  1211. });
  1212. it("an eventview's date selection has higher precedence than the date selection in the query string", function () {
  1213. const initialState = {
  1214. fields: generateFields(['title', 'count()']),
  1215. sorts: generateSorts(['count']),
  1216. query: 'event.type:csp',
  1217. environment: [],
  1218. project: [],
  1219. };
  1220. const output = {
  1221. field: ['title', 'count()'],
  1222. sort: '-count',
  1223. query: 'event.type:csp',
  1224. per_page: 50,
  1225. project: [],
  1226. environment: [],
  1227. };
  1228. // eventview's statsPeriod has highest precedence
  1229. let eventView = new EventView({
  1230. ...initialState,
  1231. statsPeriod: '90d',
  1232. start: '2019-10-01T00:00:00',
  1233. end: '2019-10-02T00:00:00',
  1234. });
  1235. let location = {
  1236. query: {
  1237. // these should not be part of the API payload
  1238. statsPeriod: '55d',
  1239. period: '30d',
  1240. start: '2020-10-01T00:00:00',
  1241. end: '2020-10-02T00:00:00',
  1242. },
  1243. };
  1244. expect(eventView.getEventsAPIPayload(location)).toEqual({
  1245. ...output,
  1246. statsPeriod: '90d',
  1247. });
  1248. // eventview's start/end has higher precedence than the date selection in the query string
  1249. eventView = new EventView({
  1250. ...initialState,
  1251. start: '2019-10-01T00:00:00',
  1252. end: '2019-10-02T00:00:00',
  1253. });
  1254. location = {
  1255. query: {
  1256. // these should not be part of the API payload
  1257. statsPeriod: '55d',
  1258. period: '30d',
  1259. start: '2020-10-01T00:00:00',
  1260. end: '2020-10-02T00:00:00',
  1261. },
  1262. };
  1263. expect(eventView.getEventsAPIPayload(location)).toEqual({
  1264. ...output,
  1265. start: '2019-10-01T00:00:00.000',
  1266. end: '2019-10-02T00:00:00.000',
  1267. });
  1268. // the date selection in the query string should be applied as expected
  1269. eventView = new EventView(initialState);
  1270. location = {
  1271. query: {
  1272. statsPeriod: '55d',
  1273. period: '30d',
  1274. start: '2020-10-01T00:00:00',
  1275. end: '2020-10-02T00:00:00',
  1276. },
  1277. };
  1278. expect(eventView.getEventsAPIPayload(location)).toEqual({
  1279. ...output,
  1280. statsPeriod: '55d',
  1281. });
  1282. location = {
  1283. query: {
  1284. period: '30d',
  1285. start: '2020-10-01T00:00:00',
  1286. end: '2020-10-02T00:00:00',
  1287. },
  1288. };
  1289. expect(eventView.getEventsAPIPayload(location)).toEqual({
  1290. ...output,
  1291. statsPeriod: '30d',
  1292. });
  1293. location = {
  1294. query: {
  1295. start: '2020-10-01T00:00:00',
  1296. end: '2020-10-02T00:00:00',
  1297. },
  1298. };
  1299. expect(eventView.getEventsAPIPayload(location)).toEqual({
  1300. ...output,
  1301. start: '2020-10-01T00:00:00.000',
  1302. end: '2020-10-02T00:00:00.000',
  1303. });
  1304. });
  1305. });
  1306. describe('EventView.getFacetsAPIPayload()', function () {
  1307. it('only includes relevant query strings', function () {
  1308. const eventView = new EventView({
  1309. fields: generateFields(['title', 'count()']),
  1310. sorts: generateSorts(['project', 'count']),
  1311. query: 'event.type:csp',
  1312. });
  1313. const location = {
  1314. query: {
  1315. start: '',
  1316. end: '',
  1317. utc: 'true',
  1318. statsPeriod: '14d',
  1319. // irrelevant query strings
  1320. bestCountry: 'canada',
  1321. cursor: 'some cursor',
  1322. sort: 'the world',
  1323. project: '1234',
  1324. environment: ['staging'],
  1325. display: 'releases',
  1326. },
  1327. };
  1328. expect(eventView.getFacetsAPIPayload(location)).toEqual({
  1329. project: [],
  1330. environment: [],
  1331. utc: 'true',
  1332. statsPeriod: '14d',
  1333. query: 'event.type:csp',
  1334. });
  1335. });
  1336. });
  1337. describe('EventView.toNewQuery()', function () {
  1338. const state = {
  1339. id: '1234',
  1340. name: 'best query',
  1341. fields: [
  1342. {field: 'count()', width: 123},
  1343. {field: 'project.id', width: 456},
  1344. ],
  1345. sorts: generateSorts(['count']),
  1346. query: 'event.type:error',
  1347. project: [42],
  1348. start: '2019-10-01T00:00:00',
  1349. end: '2019-10-02T00:00:00',
  1350. statsPeriod: '14d',
  1351. environment: ['staging'],
  1352. display: 'releases',
  1353. };
  1354. it('outputs the right fields', function () {
  1355. const eventView = new EventView(state);
  1356. const output = eventView.toNewQuery();
  1357. const expected = {
  1358. version: 2,
  1359. id: '1234',
  1360. name: 'best query',
  1361. fields: ['count()', 'project.id'],
  1362. widths: ['123', '456'],
  1363. orderby: '-count',
  1364. query: 'event.type:error',
  1365. projects: [42],
  1366. start: '2019-10-01T00:00:00',
  1367. end: '2019-10-02T00:00:00',
  1368. range: '14d',
  1369. environment: ['staging'],
  1370. display: 'releases',
  1371. };
  1372. expect(output).toEqual(expected);
  1373. });
  1374. it('omits query when query is an empty string', function () {
  1375. const modifiedState = {
  1376. ...state,
  1377. };
  1378. modifiedState.query = '';
  1379. const eventView = new EventView(modifiedState);
  1380. const output = eventView.toNewQuery();
  1381. const expected = {
  1382. version: 2,
  1383. id: '1234',
  1384. name: 'best query',
  1385. fields: ['count()', 'project.id'],
  1386. widths: ['123', '456'],
  1387. orderby: '-count',
  1388. projects: [42],
  1389. start: '2019-10-01T00:00:00',
  1390. end: '2019-10-02T00:00:00',
  1391. range: '14d',
  1392. environment: ['staging'],
  1393. display: 'releases',
  1394. };
  1395. expect(output).toEqual(expected);
  1396. });
  1397. it('omits query when query is not defined', function () {
  1398. const modifiedState = {
  1399. ...state,
  1400. };
  1401. delete modifiedState.query;
  1402. const eventView = new EventView(modifiedState);
  1403. const output = eventView.toNewQuery();
  1404. const expected = {
  1405. version: 2,
  1406. id: '1234',
  1407. name: 'best query',
  1408. fields: ['count()', 'project.id'],
  1409. widths: ['123', '456'],
  1410. orderby: '-count',
  1411. projects: [42],
  1412. start: '2019-10-01T00:00:00',
  1413. end: '2019-10-02T00:00:00',
  1414. range: '14d',
  1415. environment: ['staging'],
  1416. display: 'releases',
  1417. };
  1418. expect(output).toEqual(expected);
  1419. });
  1420. });
  1421. describe('EventView.isValid()', function () {
  1422. it('event view is valid when there is at least one field', function () {
  1423. const eventView = new EventView({
  1424. fields: [{field: 'count()'}, {field: 'project.id'}],
  1425. sorts: [],
  1426. project: [],
  1427. });
  1428. expect(eventView.isValid()).toBe(true);
  1429. });
  1430. it('event view is not valid when there are no fields', function () {
  1431. const eventView = new EventView({
  1432. fields: [],
  1433. sorts: [],
  1434. project: [],
  1435. });
  1436. expect(eventView.isValid()).toBe(false);
  1437. });
  1438. });
  1439. describe('EventView.getWidths()', function () {
  1440. it('returns widths', function () {
  1441. const eventView = new EventView({
  1442. fields: [
  1443. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  1444. {field: 'project.id', width: 2020},
  1445. {field: 'title', width: COL_WIDTH_UNDEFINED},
  1446. {field: 'time', width: 420},
  1447. {field: 'lcp', width: 69},
  1448. {field: 'lcp', width: COL_WIDTH_UNDEFINED},
  1449. {field: 'fcp', width: COL_WIDTH_UNDEFINED},
  1450. {field: 'cls', width: COL_WIDTH_UNDEFINED},
  1451. ],
  1452. sorts: [],
  1453. project: [],
  1454. });
  1455. expect(eventView.getWidths()).toEqual([
  1456. COL_WIDTH_UNDEFINED,
  1457. 2020,
  1458. COL_WIDTH_UNDEFINED,
  1459. 420,
  1460. 69,
  1461. ]);
  1462. });
  1463. });
  1464. describe('EventView.getFields()', function () {
  1465. it('returns fields', function () {
  1466. const eventView = new EventView({
  1467. fields: [{field: 'count()'}, {field: 'project.id'}],
  1468. sorts: [],
  1469. project: [],
  1470. });
  1471. expect(eventView.getFields()).toEqual(['count()', 'project.id']);
  1472. });
  1473. });
  1474. describe('EventView.numOfColumns()', function () {
  1475. it('returns correct number of columns', function () {
  1476. // has columns
  1477. const eventView = new EventView({
  1478. fields: [{field: 'count()'}, {field: 'project.id'}],
  1479. sorts: [],
  1480. project: [],
  1481. });
  1482. expect(eventView.numOfColumns()).toBe(2);
  1483. // has no columns
  1484. const eventView2 = new EventView({
  1485. fields: [],
  1486. sorts: [],
  1487. project: [],
  1488. });
  1489. expect(eventView2.numOfColumns()).toBe(0);
  1490. });
  1491. });
  1492. describe('EventView.getDays()', function () {
  1493. it('returns the right number of days for statsPeriod', function () {
  1494. const eventView = new EventView({
  1495. statsPeriod: '14d',
  1496. });
  1497. expect(eventView.getDays()).toBe(14);
  1498. const eventView2 = new EventView({
  1499. statsPeriod: '12h',
  1500. });
  1501. expect(eventView2.getDays()).toBe(0.5);
  1502. });
  1503. it('returns the right number of days for start/end', function () {
  1504. const eventView = new EventView({
  1505. start: '2019-10-01T00:00:00',
  1506. end: '2019-10-02T00:00:00',
  1507. });
  1508. expect(eventView.getDays()).toBe(1);
  1509. const eventView2 = new EventView({
  1510. start: '2019-10-01T00:00:00',
  1511. end: '2019-10-15T00:00:00',
  1512. });
  1513. expect(eventView2.getDays()).toBe(14);
  1514. });
  1515. });
  1516. describe('EventView.clone()', function () {
  1517. it('returns a unique instance', function () {
  1518. const state = {
  1519. id: '1234',
  1520. name: 'best query',
  1521. fields: [{field: 'count()'}, {field: 'project.id'}],
  1522. sorts: generateSorts(['count']),
  1523. query: 'event.type:error',
  1524. project: [42],
  1525. start: '2019-10-01T00:00:00',
  1526. end: '2019-10-02T00:00:00',
  1527. statsPeriod: '14d',
  1528. environment: ['staging'],
  1529. interval: '5m',
  1530. display: 'releases',
  1531. };
  1532. const eventView = new EventView(state);
  1533. const eventView2 = eventView.clone();
  1534. expect(eventView2 !== eventView).toBeTruthy();
  1535. expect(eventView).toMatchObject(state);
  1536. expect(eventView2).toMatchObject(state);
  1537. expect(eventView.isEqualTo(eventView2)).toBe(true);
  1538. expect(
  1539. eventView.additionalConditions === eventView2.additionalConditions
  1540. ).toBeFalsy();
  1541. });
  1542. });
  1543. describe('EventView.withColumns()', function () {
  1544. const state = {
  1545. id: '1234',
  1546. name: 'best query',
  1547. fields: [
  1548. {field: 'count()', width: 30},
  1549. {field: 'project.id', width: 99},
  1550. {field: 'failure_count()', width: 30},
  1551. ],
  1552. yAxis: 'failure_count()',
  1553. sorts: generateSorts(['count']),
  1554. query: 'event.type:error',
  1555. project: [42],
  1556. start: '2019-10-01T00:00:00',
  1557. end: '2019-10-02T00:00:00',
  1558. statsPeriod: '14d',
  1559. environment: ['staging'],
  1560. };
  1561. const eventView = new EventView(state);
  1562. it('adds new columns, and replaces existing ones', function () {
  1563. const newView = eventView.withColumns([
  1564. {kind: 'field', field: 'title'},
  1565. {kind: 'function', function: ['count', '']},
  1566. {kind: 'field', field: 'project.id'},
  1567. {kind: 'field', field: 'culprit'},
  1568. ]);
  1569. // Views should be different.
  1570. expect(newView.isEqualTo(eventView)).toBe(false);
  1571. expect(newView.fields).toEqual([
  1572. {field: 'title', width: COL_WIDTH_UNDEFINED},
  1573. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  1574. {field: 'project.id', width: COL_WIDTH_UNDEFINED},
  1575. {field: 'culprit', width: COL_WIDTH_UNDEFINED},
  1576. ]);
  1577. });
  1578. it('drops empty columns', function () {
  1579. const newView = eventView.withColumns([
  1580. {kind: 'field', field: 'issue'},
  1581. {kind: 'function', function: ['count', '']},
  1582. {kind: 'field', field: ''},
  1583. {kind: 'function', function: ['', '']},
  1584. {kind: 'function', function: ['', '', undefined]},
  1585. ]);
  1586. expect(newView.fields).toEqual([
  1587. {field: 'issue', width: COL_WIDTH_UNDEFINED},
  1588. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  1589. ]);
  1590. });
  1591. it('inherits widths from existing columns when names match', function () {
  1592. const newView = eventView.withColumns([
  1593. {kind: 'function', function: ['count', '']},
  1594. {kind: 'field', field: 'project.id'},
  1595. {kind: 'field', field: 'title'},
  1596. {kind: 'field', field: 'time'},
  1597. ]);
  1598. expect(newView.fields).toEqual([
  1599. {field: 'count()', width: 30},
  1600. {field: 'project.id', width: 99},
  1601. {field: 'title', width: COL_WIDTH_UNDEFINED},
  1602. {field: 'time', width: COL_WIDTH_UNDEFINED},
  1603. ]);
  1604. });
  1605. it('retains sorts when sorted field is included', function () {
  1606. const newView = eventView.withColumns([
  1607. {kind: 'field', field: 'title'},
  1608. {kind: 'function', function: ['count', '']},
  1609. ]);
  1610. expect(newView.fields).toEqual([
  1611. {field: 'title', width: COL_WIDTH_UNDEFINED},
  1612. {field: 'count()', width: COL_WIDTH_UNDEFINED},
  1613. ]);
  1614. expect(newView.sorts).toEqual([{field: 'count', kind: 'desc'}]);
  1615. });
  1616. it('updates sorts when sorted field is removed', function () {
  1617. const newView = eventView.withColumns([{kind: 'field', field: 'title'}]);
  1618. expect(newView.fields).toEqual([{field: 'title', width: COL_WIDTH_UNDEFINED}]);
  1619. // Should pick a sortable field.
  1620. expect(newView.sorts).toEqual([{field: 'title', kind: 'desc'}]);
  1621. });
  1622. it('has no sort if no sortable fields remain', function () {
  1623. const newView = eventView.withColumns([{kind: 'field', field: 'issue'}]);
  1624. expect(newView.fields).toEqual([{field: 'issue', width: COL_WIDTH_UNDEFINED}]);
  1625. expect(newView.sorts).toEqual([]);
  1626. });
  1627. it('updates yAxis if column is dropped', function () {
  1628. const newView = eventView.withColumns([
  1629. {kind: 'field', field: 'count()'},
  1630. {kind: 'field', field: 'project.id'},
  1631. ]);
  1632. expect(newView.fields).toEqual([
  1633. {field: 'count()', width: 30},
  1634. {field: 'project.id', width: 99},
  1635. ]);
  1636. expect(eventView.yAxis).toEqual('failure_count()');
  1637. expect(newView.yAxis).toEqual('count()');
  1638. });
  1639. });
  1640. describe('EventView.withNewColumn()', function () {
  1641. const state = {
  1642. id: '1234',
  1643. name: 'best query',
  1644. fields: [
  1645. {field: 'count()', width: 30},
  1646. {field: 'project.id', width: 99},
  1647. ],
  1648. sorts: generateSorts(['count']),
  1649. query: 'event.type:error',
  1650. project: [42],
  1651. start: '2019-10-01T00:00:00',
  1652. end: '2019-10-02T00:00:00',
  1653. statsPeriod: '14d',
  1654. environment: ['staging'],
  1655. };
  1656. it('adds a field', function () {
  1657. const eventView = new EventView(state);
  1658. const newColumn = {
  1659. kind: 'field',
  1660. field: 'title',
  1661. };
  1662. const eventView2 = eventView.withNewColumn(newColumn);
  1663. expect(eventView2 !== eventView).toBeTruthy();
  1664. expect(eventView).toMatchObject(state);
  1665. const nextState = {
  1666. ...state,
  1667. fields: [...state.fields, {field: 'title'}],
  1668. };
  1669. expect(eventView2).toMatchObject(nextState);
  1670. });
  1671. it('adds an aggregate function with no arguments', function () {
  1672. const eventView = new EventView(state);
  1673. const newColumn = {
  1674. kind: 'function',
  1675. function: ['count', ''],
  1676. };
  1677. const eventView2 = eventView.withNewColumn(newColumn);
  1678. expect(eventView2 !== eventView).toBeTruthy();
  1679. expect(eventView).toMatchObject(state);
  1680. const nextState = {
  1681. ...state,
  1682. fields: [...state.fields, {field: 'count()'}],
  1683. };
  1684. expect(eventView2).toMatchObject(nextState);
  1685. });
  1686. it('add an aggregate function with field', function () {
  1687. const eventView = new EventView(state);
  1688. const newColumn = {
  1689. kind: 'function',
  1690. function: ['avg', 'transaction.duration'],
  1691. };
  1692. const eventView2 = eventView.withNewColumn(newColumn);
  1693. expect(eventView2 !== eventView).toBeTruthy();
  1694. expect(eventView).toMatchObject(state);
  1695. const nextState = {
  1696. ...state,
  1697. fields: [...state.fields, {field: 'avg(transaction.duration)'}],
  1698. };
  1699. expect(eventView2).toMatchObject(nextState);
  1700. });
  1701. it('add an aggregate function with field & refinement', function () {
  1702. const eventView = new EventView(state);
  1703. const newColumn = {
  1704. kind: 'function',
  1705. function: ['percentile', 'transaction.duration', '0.5'],
  1706. };
  1707. const updated = eventView.withNewColumn(newColumn);
  1708. expect(updated.fields).toEqual([
  1709. ...state.fields,
  1710. {field: 'percentile(transaction.duration,0.5)', width: COL_WIDTH_UNDEFINED},
  1711. ]);
  1712. });
  1713. });
  1714. describe('EventView.withResizedColumn()', function () {
  1715. const state = {
  1716. id: '1234',
  1717. name: 'best query',
  1718. fields: [{field: 'count()'}, {field: 'project.id'}],
  1719. sorts: generateSorts(['count']),
  1720. query: 'event.type:error',
  1721. project: [42],
  1722. start: '2019-10-01T00:00:00',
  1723. end: '2019-10-02T00:00:00',
  1724. statsPeriod: '14d',
  1725. environment: ['staging'],
  1726. };
  1727. const view = new EventView(state);
  1728. it('updates a column that exists', function () {
  1729. const newView = view.withResizedColumn(0, 99);
  1730. expect(view.fields[0].width).toBeUndefined();
  1731. expect(newView.fields[0].width).toEqual(99);
  1732. });
  1733. it('ignores columns that do not exist', function () {
  1734. const newView = view.withResizedColumn(100, 99);
  1735. expect(view.fields).toEqual(newView.fields);
  1736. });
  1737. });
  1738. describe('EventView.withUpdatedColumn()', function () {
  1739. const state = {
  1740. id: '1234',
  1741. name: 'best query',
  1742. fields: [{field: 'count()'}, {field: 'project.id'}],
  1743. sorts: generateSorts(['count']),
  1744. query: 'event.type:error',
  1745. project: [42],
  1746. start: '2019-10-01T00:00:00',
  1747. end: '2019-10-02T00:00:00',
  1748. statsPeriod: '14d',
  1749. environment: ['staging'],
  1750. };
  1751. const meta = {
  1752. count: 'integer',
  1753. title: 'string',
  1754. };
  1755. it('update a column with no changes', function () {
  1756. const eventView = new EventView(state);
  1757. const newColumn = {
  1758. kind: 'function',
  1759. function: ['count', ''],
  1760. };
  1761. const eventView2 = eventView.withUpdatedColumn(0, newColumn, meta);
  1762. expect(eventView2 === eventView).toBeTruthy();
  1763. expect(eventView).toMatchObject(state);
  1764. });
  1765. it('update a column to a field', function () {
  1766. const eventView = new EventView(state);
  1767. const newColumn = {
  1768. kind: 'field',
  1769. field: 'title',
  1770. };
  1771. const eventView2 = eventView.withUpdatedColumn(1, newColumn, meta);
  1772. expect(eventView2 !== eventView).toBeTruthy();
  1773. expect(eventView).toMatchObject(state);
  1774. const nextState = {
  1775. ...state,
  1776. fields: [state.fields[0], {field: 'title'}],
  1777. };
  1778. expect(eventView2).toMatchObject(nextState);
  1779. });
  1780. it('update a column to an aggregate function with no arguments', function () {
  1781. const eventView = new EventView(state);
  1782. const newColumn = {
  1783. kind: 'function',
  1784. function: ['count', ''],
  1785. };
  1786. const eventView2 = eventView.withUpdatedColumn(1, newColumn, meta);
  1787. expect(eventView2 !== eventView).toBeTruthy();
  1788. expect(eventView).toMatchObject(state);
  1789. const nextState = {
  1790. ...state,
  1791. fields: [state.fields[0], {field: 'count()'}],
  1792. };
  1793. expect(eventView2).toMatchObject(nextState);
  1794. });
  1795. it('update a column to an aggregate function with field', function () {
  1796. const eventView = new EventView(state);
  1797. const newColumn = {
  1798. kind: 'function',
  1799. function: ['avg', 'transaction.duration'],
  1800. };
  1801. const eventView2 = eventView.withUpdatedColumn(1, newColumn, meta);
  1802. expect(eventView2 !== eventView).toBeTruthy();
  1803. expect(eventView).toMatchObject(state);
  1804. const nextState = {
  1805. ...state,
  1806. fields: [state.fields[0], {field: 'avg(transaction.duration)'}],
  1807. };
  1808. expect(eventView2).toMatchObject(nextState);
  1809. });
  1810. it('update a column to an aggregate function with field & refinement', function () {
  1811. const eventView = new EventView(state);
  1812. const newColumn = {
  1813. kind: 'function',
  1814. function: ['percentile', 'transaction.duration', '0.5'],
  1815. };
  1816. const newView = eventView.withUpdatedColumn(1, newColumn, meta);
  1817. expect(newView.fields).toEqual([
  1818. state.fields[0],
  1819. {field: 'percentile(transaction.duration,0.5)', width: COL_WIDTH_UNDEFINED},
  1820. ]);
  1821. });
  1822. describe('update a column that is sorted', function () {
  1823. it('the sorted column is the only sorted column', function () {
  1824. const eventView = new EventView(state);
  1825. const newColumn = {
  1826. kind: 'field',
  1827. field: 'title',
  1828. };
  1829. const eventView2 = eventView.withUpdatedColumn(0, newColumn, meta);
  1830. expect(eventView2 !== eventView).toBeTruthy();
  1831. expect(eventView).toMatchObject(state);
  1832. const nextState = {
  1833. ...state,
  1834. sorts: [{field: 'title', kind: 'desc'}],
  1835. fields: [{field: 'title'}, state.fields[1]],
  1836. };
  1837. expect(eventView2).toMatchObject(nextState);
  1838. });
  1839. it('the sorted column occurs at least twice', function () {
  1840. const modifiedState = {
  1841. ...state,
  1842. fields: [...state.fields, {field: 'count()'}],
  1843. };
  1844. const eventView = new EventView(modifiedState);
  1845. const newColumn = {
  1846. kind: 'field',
  1847. field: 'title',
  1848. };
  1849. const eventView2 = eventView.withUpdatedColumn(0, newColumn, meta);
  1850. expect(eventView2 !== eventView).toBeTruthy();
  1851. expect(eventView).toMatchObject(modifiedState);
  1852. const nextState = {
  1853. ...state,
  1854. fields: [{field: 'title'}, state.fields[1], {field: 'count()'}],
  1855. };
  1856. expect(eventView2).toMatchObject(nextState);
  1857. });
  1858. it('using no provided table meta', function () {
  1859. // table meta may not be provided in the invalid query state;
  1860. // we will still want to be able to update columns
  1861. const eventView = new EventView(state);
  1862. const expected = {
  1863. ...state,
  1864. sorts: [{field: 'title', kind: 'desc'}],
  1865. fields: [{field: 'title'}, state.fields[1]],
  1866. };
  1867. const newColumn = {
  1868. kind: 'field',
  1869. field: 'title',
  1870. };
  1871. const eventView2 = eventView.withUpdatedColumn(0, newColumn, {});
  1872. expect(eventView2).toMatchObject(expected);
  1873. const eventView3 = eventView.withUpdatedColumn(0, newColumn);
  1874. expect(eventView3).toMatchObject(expected);
  1875. const eventView4 = eventView.withUpdatedColumn(0, newColumn, null);
  1876. expect(eventView4).toMatchObject(expected);
  1877. });
  1878. });
  1879. describe('update a column to a non-sortable column', function () {
  1880. it('default to a sortable column', function () {
  1881. const modifiedState = {
  1882. ...state,
  1883. fields: [{field: 'count()'}, {field: 'title'}],
  1884. };
  1885. const eventView = new EventView(modifiedState);
  1886. // this column is expected to be non-sortable
  1887. const newColumn = {
  1888. kind: 'field',
  1889. field: 'project.id',
  1890. };
  1891. const eventView2 = eventView.withUpdatedColumn(0, newColumn, meta);
  1892. expect(eventView2 !== eventView).toBeTruthy();
  1893. expect(eventView).toMatchObject(modifiedState);
  1894. const nextState = {
  1895. ...state,
  1896. sorts: [{field: 'title', kind: 'desc'}],
  1897. fields: [{field: 'project.id'}, {field: 'title'}],
  1898. };
  1899. expect(eventView2).toMatchObject(nextState);
  1900. });
  1901. it('has no sort if there are no sortable columns', function () {
  1902. const modifiedState = {
  1903. ...state,
  1904. fields: [{field: 'count()'}],
  1905. };
  1906. const eventView = new EventView(modifiedState);
  1907. // this column is expected to be non-sortable
  1908. const newColumn = {
  1909. kind: 'field',
  1910. field: 'project.id',
  1911. };
  1912. const eventView2 = eventView.withUpdatedColumn(0, newColumn, meta);
  1913. expect(eventView2 !== eventView).toBeTruthy();
  1914. expect(eventView).toMatchObject(modifiedState);
  1915. const nextState = {
  1916. ...state,
  1917. sorts: [],
  1918. fields: [{field: 'project.id'}],
  1919. };
  1920. expect(eventView2).toMatchObject(nextState);
  1921. });
  1922. });
  1923. });
  1924. describe('EventView.withDeletedColumn()', function () {
  1925. const state = {
  1926. id: '1234',
  1927. name: 'best query',
  1928. fields: [{field: 'count()'}, {field: 'project.id'}],
  1929. sorts: generateSorts(['count']),
  1930. query: 'event.type:error',
  1931. project: [42],
  1932. start: '2019-10-01T00:00:00',
  1933. end: '2019-10-02T00:00:00',
  1934. statsPeriod: '14d',
  1935. environment: ['staging'],
  1936. };
  1937. const meta = {
  1938. count: 'integer',
  1939. title: 'string',
  1940. };
  1941. it('returns itself when attempting to delete the last remaining column', function () {
  1942. const modifiedState = {
  1943. ...state,
  1944. fields: [{field: 'count()'}],
  1945. };
  1946. const eventView = new EventView(modifiedState);
  1947. const eventView2 = eventView.withDeletedColumn(0, meta);
  1948. expect(eventView2 === eventView).toBeTruthy();
  1949. expect(eventView).toMatchObject(modifiedState);
  1950. });
  1951. describe('deletes column, and use any remaining sortable column', function () {
  1952. it('using no provided table meta', function () {
  1953. // table meta may not be provided in the invalid query state;
  1954. // we will still want to be able to delete columns
  1955. const state2 = {
  1956. ...state,
  1957. fields: [{field: 'title'}, {field: 'timestamp'}, {field: 'count()'}],
  1958. sorts: generateSorts(['timestamp']),
  1959. };
  1960. const eventView = new EventView(state2);
  1961. const expected = {
  1962. ...state,
  1963. sorts: generateSorts(['title']),
  1964. fields: [{field: 'title'}, {field: 'count()'}],
  1965. };
  1966. const eventView2 = eventView.withDeletedColumn(1, {});
  1967. expect(eventView2).toMatchObject(expected);
  1968. const eventView3 = eventView.withDeletedColumn(1);
  1969. expect(eventView3).toMatchObject(expected);
  1970. const eventView4 = eventView.withDeletedColumn(1, null);
  1971. expect(eventView4).toMatchObject(expected);
  1972. });
  1973. it('has no remaining sortable column', function () {
  1974. const eventView = new EventView(state);
  1975. const eventView2 = eventView.withDeletedColumn(0, meta);
  1976. expect(eventView2 !== eventView).toBeTruthy();
  1977. expect(eventView).toMatchObject(state);
  1978. const nextState = {
  1979. ...state,
  1980. // we expect sorts to be empty since project.id is non-sortable
  1981. sorts: [],
  1982. fields: [state.fields[1]],
  1983. };
  1984. expect(eventView2).toMatchObject(nextState);
  1985. });
  1986. it('has a remaining sortable column', function () {
  1987. const modifiedState = {
  1988. ...state,
  1989. fields: [{field: 'count()'}, {field: 'project.id'}, {field: 'title'}],
  1990. };
  1991. const eventView = new EventView(modifiedState);
  1992. const eventView2 = eventView.withDeletedColumn(0, meta);
  1993. expect(eventView2 !== eventView).toBeTruthy();
  1994. expect(eventView).toMatchObject(modifiedState);
  1995. const nextState = {
  1996. ...state,
  1997. sorts: [{field: 'title', kind: 'desc'}],
  1998. fields: [{field: 'project.id'}, {field: 'title'}],
  1999. };
  2000. expect(eventView2).toMatchObject(nextState);
  2001. });
  2002. it('sorted column occurs at least twice', function () {
  2003. const modifiedState = {
  2004. ...state,
  2005. fields: [...state.fields, state.fields[0]],
  2006. };
  2007. const eventView = new EventView(modifiedState);
  2008. const eventView2 = eventView.withDeletedColumn(0, meta);
  2009. expect(eventView2 !== eventView).toBeTruthy();
  2010. expect(eventView).toMatchObject(modifiedState);
  2011. const nextState = {
  2012. ...state,
  2013. fields: [state.fields[1], state.fields[0]],
  2014. };
  2015. expect(eventView2).toMatchObject(nextState);
  2016. });
  2017. it('ensures there is at one auto-width column on deletion', function () {
  2018. const modifiedState = {
  2019. ...state,
  2020. fields: [
  2021. {field: 'id', width: 75},
  2022. {field: 'title', width: 100},
  2023. {field: 'project', width: 80},
  2024. {field: 'environment', width: 99},
  2025. ],
  2026. };
  2027. const eventView = new EventView(modifiedState);
  2028. let updated = eventView.withDeletedColumn(0, meta);
  2029. let updatedFields = [
  2030. {field: 'title', width: -1},
  2031. {field: 'project', width: 80},
  2032. {field: 'environment', width: 99},
  2033. ];
  2034. expect(updated.fields).toEqual(updatedFields);
  2035. updated = updated.withDeletedColumn(0, meta);
  2036. updatedFields = [
  2037. {field: 'project', width: -1},
  2038. {field: 'environment', width: 99},
  2039. ];
  2040. expect(updated.fields).toEqual(updatedFields);
  2041. });
  2042. });
  2043. });
  2044. describe('EventView.getSorts()', function () {
  2045. it('returns fields', function () {
  2046. const eventView = new EventView({
  2047. fields: [{field: 'count()'}, {field: 'project.id'}],
  2048. sorts: generateSorts(['count']),
  2049. project: [],
  2050. });
  2051. expect(eventView.getSorts()).toEqual([
  2052. {
  2053. key: 'count',
  2054. order: 'desc',
  2055. },
  2056. ]);
  2057. });
  2058. });
  2059. describe('EventView.getQuery()', function () {
  2060. it('with query', function () {
  2061. const eventView = new EventView({
  2062. fields: [],
  2063. sorts: [],
  2064. project: [],
  2065. query: 'event.type:error',
  2066. });
  2067. expect(eventView.getQuery()).toEqual('event.type:error');
  2068. expect(eventView.getQuery(null)).toEqual('event.type:error');
  2069. expect(eventView.getQuery('hello')).toEqual('event.type:error hello');
  2070. expect(eventView.getQuery(['event.type:error', 'hello'])).toEqual(
  2071. 'event.type:error hello'
  2072. );
  2073. });
  2074. it('without query', function () {
  2075. const eventView = new EventView({
  2076. fields: [],
  2077. sorts: [],
  2078. project: [],
  2079. });
  2080. expect(eventView.getQuery()).toEqual('');
  2081. expect(eventView.getQuery(null)).toEqual('');
  2082. expect(eventView.getQuery('hello')).toEqual('hello');
  2083. expect(eventView.getQuery(['event.type:error', 'hello'])).toEqual(
  2084. 'event.type:error hello'
  2085. );
  2086. });
  2087. });
  2088. describe('EventView.getQueryWithAdditionalConditions', function () {
  2089. it('with overlapping conditions', function () {
  2090. const eventView = new EventView({
  2091. fields: [],
  2092. sorts: [],
  2093. project: [],
  2094. query: 'event.type:transaction foo:bar',
  2095. });
  2096. eventView.additionalConditions.setFilterValues('event.type', ['transaction']);
  2097. expect(eventView.getQueryWithAdditionalConditions()).toEqual(
  2098. 'event.type:transaction foo:bar'
  2099. );
  2100. });
  2101. });
  2102. describe('EventView.sortForField()', function () {
  2103. const state = {
  2104. id: '1234',
  2105. name: 'best query',
  2106. fields: [{field: 'count()'}, {field: 'project.id'}],
  2107. sorts: generateSorts(['count']),
  2108. query: 'event.type:error',
  2109. project: [42],
  2110. start: '2019-10-01T00:00:00',
  2111. end: '2019-10-02T00:00:00',
  2112. statsPeriod: '14d',
  2113. environment: ['staging'],
  2114. };
  2115. const eventView = new EventView(state);
  2116. const meta = {count: 'integer'};
  2117. it('returns the sort when selected field is sorted', function () {
  2118. const field = {
  2119. field: 'count()',
  2120. };
  2121. const actual = eventView.sortForField(field, meta);
  2122. expect(actual).toEqual({
  2123. field: 'count',
  2124. kind: 'desc',
  2125. });
  2126. });
  2127. it('returns undefined when selected field is not sorted', function () {
  2128. const field = {
  2129. field: 'project.id',
  2130. };
  2131. expect(eventView.sortForField(field, meta)).toBeUndefined();
  2132. });
  2133. it('returns undefined when no meta is provided', function () {
  2134. const field = {
  2135. field: 'project.id',
  2136. };
  2137. expect(eventView.sortForField(field, undefined)).toBeUndefined();
  2138. });
  2139. });
  2140. describe('EventView.sortOnField()', function () {
  2141. const state = {
  2142. id: '1234',
  2143. name: 'best query',
  2144. fields: [{field: 'count()'}, {field: 'project.id'}],
  2145. sorts: generateSorts(['count']),
  2146. query: 'event.type:error',
  2147. project: [42],
  2148. start: '2019-10-01T00:00:00',
  2149. end: '2019-10-02T00:00:00',
  2150. statsPeriod: '14d',
  2151. environment: ['staging'],
  2152. };
  2153. const meta = {count: 'integer', title: 'string'};
  2154. it('returns itself when attempting to sort on un-sortable field', function () {
  2155. const eventView = new EventView(state);
  2156. expect(eventView).toMatchObject(state);
  2157. const field = state.fields[1];
  2158. const eventView2 = eventView.sortOnField(field, meta);
  2159. expect(eventView2 === eventView).toBe(true);
  2160. });
  2161. it('reverses the sorted field', function () {
  2162. const eventView = new EventView(state);
  2163. expect(eventView).toMatchObject(state);
  2164. const field = state.fields[0];
  2165. const eventView2 = eventView.sortOnField(field, meta);
  2166. expect(eventView2 !== eventView).toBe(true);
  2167. const nextState = {
  2168. ...state,
  2169. sorts: [{field: 'count', kind: 'asc'}],
  2170. };
  2171. expect(eventView2).toMatchObject(nextState);
  2172. });
  2173. it('enforce sort order on sorted field', function () {
  2174. const eventView = new EventView(state);
  2175. expect(eventView).toMatchObject(state);
  2176. const field = state.fields[0];
  2177. const eventView2 = eventView.sortOnField(field, meta, 'asc');
  2178. expect(eventView2).toMatchObject({
  2179. ...state,
  2180. sorts: [{field: 'count', kind: 'asc'}],
  2181. });
  2182. const eventView3 = eventView.sortOnField(field, meta, 'desc');
  2183. expect(eventView3).toMatchObject({
  2184. ...state,
  2185. sorts: [{field: 'count', kind: 'desc'}],
  2186. });
  2187. });
  2188. it('sort on new field', function () {
  2189. const modifiedState = {
  2190. ...state,
  2191. fields: [...state.fields, {field: 'title'}],
  2192. };
  2193. const eventView = new EventView(modifiedState);
  2194. expect(eventView).toMatchObject(modifiedState);
  2195. const field = modifiedState.fields[2];
  2196. const eventView2 = eventView.sortOnField(field, meta);
  2197. expect(eventView2 !== eventView).toBe(true);
  2198. const nextState = {
  2199. ...modifiedState,
  2200. sorts: [{field: 'title', kind: 'desc'}],
  2201. };
  2202. expect(eventView2).toMatchObject(nextState);
  2203. // enforce asc sort order
  2204. const eventView3 = eventView.sortOnField(field, meta, 'asc');
  2205. expect(eventView3).toMatchObject({
  2206. ...modifiedState,
  2207. sorts: [{field: 'title', kind: 'asc'}],
  2208. });
  2209. // enforce desc sort order
  2210. const eventView4 = eventView.sortOnField(field, meta, 'desc');
  2211. expect(eventView4).toMatchObject({
  2212. ...modifiedState,
  2213. sorts: [{field: 'title', kind: 'desc'}],
  2214. });
  2215. });
  2216. it('sorts on a field using function format', function () {
  2217. const modifiedState = {
  2218. ...state,
  2219. fields: [...state.fields, {field: 'count()'}],
  2220. };
  2221. const eventView = new EventView(modifiedState);
  2222. expect(eventView).toMatchObject(modifiedState);
  2223. const field = modifiedState.fields[2];
  2224. let sortedEventView = eventView.sortOnField(field, meta, undefined, true);
  2225. expect(sortedEventView.sorts).toEqual([{field: 'count()', kind: 'asc'}]);
  2226. sortedEventView = sortedEventView.sortOnField(field, meta, undefined, true);
  2227. expect(sortedEventView.sorts).toEqual([{field: 'count()', kind: 'desc'}]);
  2228. });
  2229. });
  2230. describe('EventView.withSorts()', function () {
  2231. it('returns a clone', function () {
  2232. const eventView = new EventView({
  2233. fields: [{field: 'event.type'}],
  2234. });
  2235. const updated = eventView.withSorts([{kind: 'desc', field: 'event.type'}]);
  2236. expect(updated.sorts).not.toEqual(eventView.sorts);
  2237. });
  2238. it('only accepts sorting on fields in the view', function () {
  2239. const eventView = new EventView({
  2240. fields: [{field: 'event.type'}],
  2241. });
  2242. const updated = eventView.withSorts([
  2243. {kind: 'desc', field: 'event.type'},
  2244. {kind: 'asc', field: 'unknown'},
  2245. ]);
  2246. expect(updated.sorts).toEqual([{kind: 'desc', field: 'event.type'}]);
  2247. });
  2248. it('accepts aggregate field sorts', function () {
  2249. const eventView = new EventView({
  2250. fields: [{field: 'p50()'}],
  2251. });
  2252. const updated = eventView.withSorts([
  2253. {kind: 'desc', field: 'p50'},
  2254. {kind: 'asc', field: 'unknown'},
  2255. ]);
  2256. expect(updated.sorts).toEqual([{kind: 'desc', field: 'p50'}]);
  2257. });
  2258. });
  2259. describe('EventView.isEqualTo()', function () {
  2260. it('should be true when equal', function () {
  2261. const state = {
  2262. id: '1234',
  2263. name: 'best query',
  2264. fields: [{field: 'count()'}, {field: 'project.id'}],
  2265. sorts: generateSorts(['count']),
  2266. query: 'event.type:error',
  2267. project: [42],
  2268. start: '2019-10-01T00:00:00',
  2269. end: '2019-10-02T00:00:00',
  2270. statsPeriod: '14d',
  2271. environment: ['staging'],
  2272. yAxis: 'fam',
  2273. display: 'releases',
  2274. };
  2275. const eventView = new EventView(state);
  2276. const eventView2 = new EventView(state);
  2277. expect(eventView2 !== eventView).toBeTruthy();
  2278. expect(eventView).toMatchObject(state);
  2279. expect(eventView2).toMatchObject(state);
  2280. expect(eventView.isEqualTo(eventView2)).toBe(true);
  2281. // commutativity property holds
  2282. expect(eventView2.isEqualTo(eventView)).toBe(true);
  2283. });
  2284. it('should be true when datetime are equal but differ in format', function () {
  2285. const state = {
  2286. id: '1234',
  2287. name: 'best query',
  2288. fields: [{field: 'count()'}, {field: 'project.id'}],
  2289. sorts: generateSorts(['count']),
  2290. query: 'event.type:error',
  2291. project: [42],
  2292. start: '2019-10-20T21:02:51+0000',
  2293. end: '2019-10-23T19:27:04+0000',
  2294. environment: ['staging'],
  2295. };
  2296. const eventView = new EventView(state);
  2297. const eventView2 = new EventView({
  2298. ...state,
  2299. start: '2019-10-20T21:02:51Z',
  2300. end: '2019-10-23T19:27:04Z',
  2301. });
  2302. expect(eventView.isEqualTo(eventView2)).toBe(true);
  2303. });
  2304. it('should be false when not equal', function () {
  2305. const state = {
  2306. id: '1234',
  2307. name: 'best query',
  2308. fields: [{field: 'count()'}, {field: 'project.id'}],
  2309. sorts: generateSorts(['count']),
  2310. query: 'event.type:error',
  2311. project: [42],
  2312. start: '2019-10-01T00:00:00',
  2313. end: '2019-10-02T00:00:00',
  2314. statsPeriod: '14d',
  2315. environment: ['staging'],
  2316. yAxis: 'fam',
  2317. display: 'releases',
  2318. };
  2319. const differences = {
  2320. id: '12',
  2321. name: 'new query',
  2322. fields: [{field: 'project.id'}, {field: 'count()'}],
  2323. sorts: [{field: 'count', kind: 'asc'}],
  2324. query: 'event.type:transaction',
  2325. project: [24],
  2326. start: '2019-09-01T00:00:00',
  2327. end: '2020-09-01T00:00:00',
  2328. statsPeriod: '24d',
  2329. environment: [],
  2330. yAxis: 'ok boomer',
  2331. display: 'previous',
  2332. };
  2333. const eventView = new EventView(state);
  2334. for (const key in differences) {
  2335. const eventView2 = new EventView({...state, [key]: differences[key]});
  2336. expect(eventView.isEqualTo(eventView2)).toBe(false);
  2337. }
  2338. });
  2339. it('undefined display type equals default display type', function () {
  2340. const state = {
  2341. id: '1234',
  2342. name: 'best query',
  2343. fields: [{field: 'count()'}, {field: 'project.id'}],
  2344. sorts: generateSorts(['count']),
  2345. query: 'event.type:error',
  2346. project: [42],
  2347. start: '2019-10-01T00:00:00',
  2348. end: '2019-10-02T00:00:00',
  2349. statsPeriod: '14d',
  2350. environment: ['staging'],
  2351. yAxis: 'fam',
  2352. };
  2353. const eventView = new EventView(state);
  2354. const eventView2 = new EventView({...state, display: 'default'});
  2355. expect(eventView.isEqualTo(eventView2)).toBe(true);
  2356. });
  2357. });
  2358. describe('EventView.getResultsViewUrlTarget()', function () {
  2359. const state = {
  2360. id: '1234',
  2361. name: 'best query',
  2362. fields: [{field: 'count()'}, {field: 'project.id'}],
  2363. sorts: generateSorts(['count']),
  2364. query: 'event.type:error',
  2365. project: [42],
  2366. start: '2019-10-01T00:00:00',
  2367. end: '2019-10-02T00:00:00',
  2368. statsPeriod: '14d',
  2369. environment: ['staging'],
  2370. display: 'previous',
  2371. };
  2372. const organization = TestStubs.Organization();
  2373. it('generates a URL', function () {
  2374. const view = new EventView(state);
  2375. const result = view.getResultsViewUrlTarget(organization.slug);
  2376. expect(result.pathname).toEqual('/organizations/org-slug/discover/results/');
  2377. expect(result.query.query).toEqual(state.query);
  2378. expect(result.query.project).toEqual(state.project);
  2379. expect(result.query.display).toEqual(state.display);
  2380. });
  2381. });
  2382. describe('EventView.getResultsViewShortUrlTarget()', function () {
  2383. const state = {
  2384. id: '1234',
  2385. name: 'best query',
  2386. fields: [{field: 'count()'}, {field: 'project.id'}],
  2387. sorts: generateSorts(['count']),
  2388. query: 'event.type:error',
  2389. project: [42],
  2390. start: '2019-10-01T00:00:00',
  2391. end: '2019-10-02T00:00:00',
  2392. statsPeriod: '14d',
  2393. environment: ['staging'],
  2394. display: 'previous',
  2395. };
  2396. const organization = TestStubs.Organization();
  2397. it('generates a URL', function () {
  2398. const view = new EventView(state);
  2399. const result = view.getResultsViewShortUrlTarget(organization.slug);
  2400. expect(result.pathname).toEqual('/organizations/org-slug/discover/results/');
  2401. expect(result.query).not.toHaveProperty('name');
  2402. expect(result.query).not.toHaveProperty('fields');
  2403. expect(result.query).not.toHaveProperty('query');
  2404. expect(result.query.id).toEqual(state.id);
  2405. expect(result.query.statsPeriod).toEqual(state.statsPeriod);
  2406. expect(result.query.project).toEqual(state.project);
  2407. expect(result.query.environment).toEqual(state.environment);
  2408. });
  2409. });
  2410. describe('EventView.getPerformanceTransactionEventsViewUrlTarget()', function () {
  2411. const state = {
  2412. id: '1234',
  2413. name: 'best query',
  2414. fields: [{field: 'count()'}, {field: 'project.id'}],
  2415. sorts: generateSorts(['count']),
  2416. query: 'event.type:error',
  2417. project: [42],
  2418. start: '2019-10-01T00:00:00',
  2419. end: '2019-10-02T00:00:00',
  2420. statsPeriod: '14d',
  2421. environment: ['staging'],
  2422. display: 'previous',
  2423. };
  2424. const organization = TestStubs.Organization();
  2425. const showTransactions = 'p99';
  2426. const breakdown = 'http';
  2427. const webVital = 'measurements.lcp';
  2428. it('generates a URL', function () {
  2429. const view = new EventView(state);
  2430. const result = view.getPerformanceTransactionEventsViewUrlTarget(organization.slug, {
  2431. showTransactions,
  2432. breakdown,
  2433. webVital,
  2434. });
  2435. expect(result.pathname).toEqual(
  2436. '/organizations/org-slug/performance/summary/events/'
  2437. );
  2438. expect(result.query.query).toEqual(state.query);
  2439. expect(result.query.project).toEqual(state.project);
  2440. expect(result.query.sort).toEqual(['-count']);
  2441. expect(result.query.transaction).toEqual(state.name);
  2442. expect(result.query.showTransactions).toEqual(showTransactions);
  2443. expect(result.query.breakdown).toEqual(breakdown);
  2444. expect(result.query.webVital).toEqual(webVital);
  2445. });
  2446. });
  2447. describe('EventView.getPageFilters()', function () {
  2448. it('return default global selection', function () {
  2449. const eventView = new EventView({});
  2450. expect(eventView.getPageFilters()).toMatchObject({
  2451. projects: [],
  2452. environments: [],
  2453. datetime: {
  2454. start: null,
  2455. end: null,
  2456. period: null,
  2457. // event views currently do not support the utc option,
  2458. // see comment in EventView.getPageFilters
  2459. utc: true,
  2460. },
  2461. });
  2462. });
  2463. it('returns global selection query', function () {
  2464. const state2 = {
  2465. project: [42],
  2466. start: 'start',
  2467. end: 'end',
  2468. statsPeriod: '42d',
  2469. environment: ['prod'],
  2470. };
  2471. const eventView = new EventView(state2);
  2472. expect(eventView.getPageFilters()).toMatchObject({
  2473. projects: state2.project,
  2474. environments: state2.environment,
  2475. datetime: {
  2476. start: state2.start,
  2477. end: state2.end,
  2478. period: state2.statsPeriod,
  2479. // event views currently do not support the utc option,
  2480. // see comment in EventView.getPageFilters
  2481. utc: true,
  2482. },
  2483. });
  2484. });
  2485. });
  2486. describe('EventView.getPageFiltersQuery()', function () {
  2487. it('return default global selection query', function () {
  2488. const eventView = new EventView({});
  2489. expect(eventView.getPageFiltersQuery()).toMatchObject({
  2490. project: [],
  2491. start: undefined,
  2492. end: undefined,
  2493. statsPeriod: undefined,
  2494. environment: [],
  2495. // event views currently do not support the utc option,
  2496. // see comment in EventView.getPageFilters
  2497. utc: 'true',
  2498. });
  2499. });
  2500. it('returns global selection query', function () {
  2501. const state2 = {
  2502. project: [42],
  2503. start: 'start',
  2504. end: 'end',
  2505. statsPeriod: '42d',
  2506. environment: ['prod'],
  2507. };
  2508. const eventView = new EventView(state2);
  2509. expect(eventView.getPageFiltersQuery()).toMatchObject({
  2510. ...state2,
  2511. // when generating the query, it converts numbers to strings
  2512. project: ['42'],
  2513. // event views currently do not support the utc option,
  2514. // see comment in EventView.getPageFilters
  2515. utc: 'true',
  2516. });
  2517. });
  2518. });
  2519. describe('EventView.generateBlankQueryStringObject()', function () {
  2520. it('should return blank values', function () {
  2521. const eventView = new EventView({});
  2522. expect(eventView.generateBlankQueryStringObject()).toEqual({
  2523. id: undefined,
  2524. name: undefined,
  2525. fields: undefined,
  2526. sorts: undefined,
  2527. query: undefined,
  2528. project: undefined,
  2529. start: undefined,
  2530. end: undefined,
  2531. statsPeriod: undefined,
  2532. environment: undefined,
  2533. yAxis: undefined,
  2534. cursor: undefined,
  2535. });
  2536. });
  2537. });
  2538. describe('EventView.getYAxisOptions()', function () {
  2539. const state = {
  2540. fields: [],
  2541. sorts: [],
  2542. query: '',
  2543. project: [],
  2544. statsPeriod: '42d',
  2545. environment: [],
  2546. };
  2547. function generateYaxis(value) {
  2548. return {
  2549. value,
  2550. label: value,
  2551. };
  2552. }
  2553. it('should return default options', function () {
  2554. const thisEventView = new EventView(state);
  2555. expect(thisEventView.getYAxisOptions()).toEqual(CHART_AXIS_OPTIONS);
  2556. });
  2557. it('should add aggregate fields as options', function () {
  2558. let thisEventView = new EventView({
  2559. ...state,
  2560. fields: generateFields(['ignored-field', 'count_unique(issue)']),
  2561. });
  2562. expect(thisEventView.getYAxisOptions()).toEqual([
  2563. generateYaxis('count_unique(issue)'),
  2564. ...CHART_AXIS_OPTIONS,
  2565. ]);
  2566. // should de-duplicate entries
  2567. thisEventView = new EventView({
  2568. ...state,
  2569. fields: generateFields(['ignored-field', 'count()']),
  2570. });
  2571. expect(thisEventView.getYAxisOptions()).toEqual([...CHART_AXIS_OPTIONS]);
  2572. });
  2573. it('should exclude yAxis options that are not useful', function () {
  2574. const thisEventView = new EventView({
  2575. ...state,
  2576. fields: generateFields([
  2577. 'ignored-field',
  2578. 'count_unique(issue)',
  2579. 'last_seen()',
  2580. 'max(timestamp)',
  2581. ]),
  2582. });
  2583. expect(thisEventView.getYAxisOptions()).toEqual([
  2584. generateYaxis('count_unique(issue)'),
  2585. ...CHART_AXIS_OPTIONS,
  2586. ]);
  2587. });
  2588. });
  2589. describe('EventView.getYAxis()', function () {
  2590. const state = {
  2591. fields: [],
  2592. sorts: [],
  2593. query: '',
  2594. project: [],
  2595. statsPeriod: '42d',
  2596. environment: [],
  2597. };
  2598. it('should return first default yAxis', function () {
  2599. const thisEventView = new EventView(state);
  2600. expect(thisEventView.getYAxis()).toEqual('count()');
  2601. });
  2602. it('should return valid yAxis', function () {
  2603. const thisEventView = new EventView({
  2604. ...state,
  2605. fields: generateFields(['ignored-field', 'count_unique(user)', 'last_seen']),
  2606. yAxis: 'count_unique(user)',
  2607. });
  2608. expect(thisEventView.getYAxis()).toEqual('count_unique(user)');
  2609. });
  2610. it('should ignore invalid yAxis', function () {
  2611. const invalid = [
  2612. 'last_seen',
  2613. 'latest_event',
  2614. 'count_unique(issue)', // this is not one of the selected fields
  2615. ];
  2616. for (const option of invalid) {
  2617. const thisEventView = new EventView({
  2618. ...state,
  2619. fields: generateFields(['ignored-field', 'last_seen', 'latest_event']),
  2620. yAxis: option,
  2621. });
  2622. // yAxis defaults to the first entry of the default yAxis options
  2623. expect(thisEventView.getYAxis()).toEqual('count()');
  2624. }
  2625. });
  2626. });
  2627. describe('EventView.getDisplayOptions()', function () {
  2628. const state = {
  2629. fields: [],
  2630. sorts: [],
  2631. query: '',
  2632. project: [],
  2633. statsPeriod: '42d',
  2634. environment: [],
  2635. };
  2636. it('should return default options', function () {
  2637. const eventView = new EventView({
  2638. ...state,
  2639. // there needs to exist an aggregate or TOP 5 modes will be disabled
  2640. fields: [{field: 'count()'}],
  2641. });
  2642. expect(eventView.getDisplayOptions()).toEqual(DISPLAY_MODE_OPTIONS);
  2643. });
  2644. it('should disable previous when start/end are used.', function () {
  2645. const eventView = new EventView({
  2646. ...state,
  2647. end: '2020-04-13T12:13:14',
  2648. start: '2020-04-01T12:13:14',
  2649. });
  2650. const options = eventView.getDisplayOptions();
  2651. expect(options[1].value).toEqual('previous');
  2652. expect(options[1].disabled).toBeTruthy();
  2653. });
  2654. it('should disable top 5 period/daily if no aggregates present', function () {
  2655. const eventView = new EventView({
  2656. ...state,
  2657. });
  2658. const options = eventView.getDisplayOptions();
  2659. expect(options[2].value).toEqual('top5');
  2660. expect(options[2].disabled).toBeTruthy();
  2661. expect(options[4].value).toEqual('dailytop5');
  2662. expect(options[4].disabled).toBeTruthy();
  2663. });
  2664. });
  2665. describe('EventView.getDisplayMode()', function () {
  2666. const state = {
  2667. fields: [],
  2668. sorts: [],
  2669. query: '',
  2670. project: [],
  2671. statsPeriod: '42d',
  2672. environment: [],
  2673. };
  2674. it('should have default', function () {
  2675. const eventView = new EventView({
  2676. ...state,
  2677. });
  2678. const displayMode = eventView.getDisplayMode();
  2679. expect(displayMode).toEqual(DisplayModes.DEFAULT);
  2680. });
  2681. it('should return current mode when not disabled', function () {
  2682. const eventView = new EventView({
  2683. ...state,
  2684. display: DisplayModes.DAILY,
  2685. });
  2686. const displayMode = eventView.getDisplayMode();
  2687. expect(displayMode).toEqual(DisplayModes.DAILY);
  2688. });
  2689. it('should return default mode when disabled', function () {
  2690. const eventView = new EventView({
  2691. ...state,
  2692. // the existence of start and end will disable the PREVIOUS mode
  2693. end: '2020-04-13T12:13:14',
  2694. start: '2020-04-01T12:13:14',
  2695. display: DisplayModes.PREVIOUS,
  2696. });
  2697. const displayMode = eventView.getDisplayMode();
  2698. expect(displayMode).toEqual(DisplayModes.DEFAULT);
  2699. });
  2700. it('top 5 should fallback to default when disabled', function () {
  2701. const eventView = new EventView({
  2702. ...state,
  2703. // the lack of an aggregate will disable the TOP5 mode
  2704. display: DisplayModes.TOP5,
  2705. });
  2706. const displayMode = eventView.getDisplayMode();
  2707. expect(displayMode).toEqual(DisplayModes.DEFAULT);
  2708. });
  2709. it('top 5 daily should fallback to daily when disabled', function () {
  2710. const eventView = new EventView({
  2711. ...state,
  2712. // the lack of an aggregate will disable the DAILYTOP5 mode
  2713. display: DisplayModes.DAILYTOP5,
  2714. });
  2715. const displayMode = eventView.getDisplayMode();
  2716. expect(displayMode).toEqual(DisplayModes.DAILY);
  2717. });
  2718. it('daily mode should fall back to default when disabled', function () {
  2719. const eventView = new EventView({
  2720. ...state,
  2721. // the period being less than 24h will disable the DAILY mode
  2722. statsPeriod: '1h',
  2723. display: DisplayModes.DAILY,
  2724. });
  2725. const displayMode = eventView.getDisplayMode();
  2726. expect(displayMode).toEqual(DisplayModes.DEFAULT);
  2727. });
  2728. it('top 5 daily mode should fall back to default when daily is disabled', function () {
  2729. const eventView = new EventView({
  2730. ...state,
  2731. // the period being less than 24h will disable the DAILY mode
  2732. start: '2020-04-01T12:13:14',
  2733. end: '2020-04-02T12:10:14',
  2734. display: DisplayModes.TOP5DAILY,
  2735. });
  2736. const displayMode = eventView.getDisplayMode();
  2737. expect(displayMode).toEqual(DisplayModes.DEFAULT);
  2738. });
  2739. });
  2740. describe('EventView.getAggregateFields()', function () {
  2741. const state = {
  2742. fields: [
  2743. {field: 'title'},
  2744. {field: 'count()'},
  2745. {field: 'count_unique(user)'},
  2746. {field: 'apdex(300)'},
  2747. {field: 'transaction'},
  2748. ],
  2749. sorts: [],
  2750. query: '',
  2751. project: [],
  2752. statsPeriod: '42d',
  2753. environment: [],
  2754. };
  2755. it('getAggregateFields() returns only aggregates', function () {
  2756. const eventView = new EventView(state);
  2757. const expected = [
  2758. {field: 'count()'},
  2759. {field: 'count_unique(user)'},
  2760. {field: 'apdex(300)'},
  2761. ];
  2762. expect(eventView.getAggregateFields()).toEqual(expected);
  2763. });
  2764. });
  2765. describe('EventView.hasAggregateField', function () {
  2766. it('ensures an eventview has an aggregate field', function () {
  2767. let eventView = new EventView({
  2768. fields: [{field: 'foobar'}],
  2769. sorts: [],
  2770. query: '',
  2771. project: [],
  2772. environment: [],
  2773. });
  2774. expect(eventView.hasAggregateField()).toBe(false);
  2775. eventView = new EventView({
  2776. fields: [{field: 'count(foo.bar.is-Enterprise_42)'}],
  2777. sorts: [],
  2778. query: '',
  2779. project: [],
  2780. environment: [],
  2781. });
  2782. expect(eventView.hasAggregateField()).toBe(true);
  2783. });
  2784. });
  2785. describe('isAPIPayloadSimilar', function () {
  2786. const state = {
  2787. id: '1234',
  2788. name: 'best query',
  2789. fields: [{field: 'count()'}, {field: 'project.id'}],
  2790. sorts: generateSorts(['count']),
  2791. query: 'event.type:error',
  2792. project: [42],
  2793. start: '2019-10-01T00:00:00',
  2794. end: '2019-10-02T00:00:00',
  2795. statsPeriod: '14d',
  2796. environment: ['staging'],
  2797. };
  2798. const meta = {
  2799. count: 'integer',
  2800. title: 'string',
  2801. };
  2802. describe('getEventsAPIPayload', function () {
  2803. it('is not similar when relevant query string keys are present in the Location object', function () {
  2804. const thisEventView = new EventView(state);
  2805. const location = {
  2806. query: {
  2807. project: 'project',
  2808. environment: 'environment',
  2809. start: 'start',
  2810. end: 'end',
  2811. utc: 'utc',
  2812. statsPeriod: 'statsPeriod',
  2813. cursor: 'cursor',
  2814. },
  2815. };
  2816. const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
  2817. const otherLocation = {};
  2818. const otherAPIPayload = thisEventView.getEventsAPIPayload(otherLocation);
  2819. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  2820. expect(results).toBe(false);
  2821. });
  2822. it('is similar when irrelevant query string keys are present in the Location object', function () {
  2823. const thisEventView = new EventView(state);
  2824. const location = {
  2825. query: {
  2826. bestCountry: 'canada',
  2827. },
  2828. };
  2829. const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
  2830. const otherLocation = {};
  2831. const otherAPIPayload = thisEventView.getEventsAPIPayload(otherLocation);
  2832. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  2833. expect(results).toBe(true);
  2834. });
  2835. it('is not similar on sort key sorted in opposite directions', function () {
  2836. const thisEventView = new EventView(state);
  2837. const location = {};
  2838. const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
  2839. const otherEventView = thisEventView.sortOnField({field: 'count()'}, meta);
  2840. const otherLocation = {};
  2841. const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
  2842. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  2843. expect(results).toBe(false);
  2844. });
  2845. it('is not similar when a new column is added', function () {
  2846. const thisEventView = new EventView(state);
  2847. const location = {};
  2848. const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
  2849. const otherEventView = thisEventView.clone();
  2850. otherEventView.fields.push({field: 'title', width: COL_WIDTH_UNDEFINED});
  2851. const otherLocation = {};
  2852. const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
  2853. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  2854. expect(results).toBe(false);
  2855. });
  2856. it('is similar when a column is updated with no changes', function () {
  2857. const thisEventView = new EventView(state);
  2858. const location = {};
  2859. const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
  2860. const newColumn = {
  2861. kind: 'function',
  2862. function: ['count', ''],
  2863. };
  2864. const otherEventView = thisEventView.withUpdatedColumn(0, newColumn, meta);
  2865. const otherLocation = {};
  2866. const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
  2867. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  2868. expect(results).toBe(true);
  2869. });
  2870. it('is not similar when a column is updated with a replaced field', function () {
  2871. const thisEventView = new EventView(state);
  2872. const location = {};
  2873. const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
  2874. const newColumn = {
  2875. kind: 'field',
  2876. field: 'title',
  2877. };
  2878. const otherEventView = thisEventView.withUpdatedColumn(0, newColumn, meta);
  2879. const otherLocation = {};
  2880. const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
  2881. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  2882. expect(results).toBe(false);
  2883. });
  2884. it('is not similar when a column is updated with a replaced aggregation', function () {
  2885. const thisEventView = new EventView(state);
  2886. const location = {};
  2887. const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
  2888. const newColumn = {
  2889. kind: 'function',
  2890. function: ['avg', ''],
  2891. };
  2892. const otherEventView = thisEventView.withUpdatedColumn(0, newColumn, meta);
  2893. const otherLocation = {};
  2894. const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
  2895. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  2896. expect(results).toBe(false);
  2897. });
  2898. it('is similar when a column is renamed', function () {
  2899. const thisEventView = new EventView(state);
  2900. const location = {};
  2901. const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
  2902. const newColumn = {
  2903. kind: 'function',
  2904. function: ['count', ''],
  2905. };
  2906. const otherEventView = thisEventView.withUpdatedColumn(0, newColumn, meta);
  2907. const otherLocation = {};
  2908. const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
  2909. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  2910. expect(results).toBe(true);
  2911. });
  2912. it('is not similar when a column is deleted', function () {
  2913. const thisEventView = new EventView(state);
  2914. const location = {};
  2915. const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
  2916. const otherEventView = thisEventView.withDeletedColumn(0, meta);
  2917. const otherLocation = {};
  2918. const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
  2919. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  2920. expect(results).toBe(false);
  2921. });
  2922. it('is similar if column order changes', function () {
  2923. const thisEventView = new EventView(state);
  2924. const location = {};
  2925. const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
  2926. state.fields.reverse();
  2927. const otherEventView = new EventView(state);
  2928. const otherLocation = {};
  2929. const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
  2930. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  2931. expect(results).toBe(true);
  2932. });
  2933. it('is similar if equation order relatively same', function () {
  2934. const equationField = {field: 'equation|failure_count() / count()'};
  2935. const otherEquationField = {field: 'equation|failure_count() / 2'};
  2936. state.fields = [
  2937. {field: 'project.id'},
  2938. {field: 'count()'},
  2939. equationField,
  2940. otherEquationField,
  2941. ];
  2942. const thisEventView = new EventView(state);
  2943. const location = {};
  2944. const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
  2945. state.fields = [
  2946. equationField,
  2947. {field: 'project.id'},
  2948. {field: 'count()'},
  2949. otherEquationField,
  2950. ];
  2951. const otherEventView = new EventView(state);
  2952. const otherLocation = {};
  2953. const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
  2954. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  2955. expect(results).toBe(true);
  2956. });
  2957. it('is not similar if equation order changes', function () {
  2958. const equationField = {field: 'equation|failure_count() / count()'};
  2959. const otherEquationField = {field: 'equation|failure_count() / 2'};
  2960. state.fields = [
  2961. {field: 'project.id'},
  2962. {field: 'count()'},
  2963. equationField,
  2964. otherEquationField,
  2965. ];
  2966. const thisEventView = new EventView(state);
  2967. const location = {};
  2968. const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
  2969. state.fields = [
  2970. {field: 'project.id'},
  2971. {field: 'count()'},
  2972. otherEquationField,
  2973. equationField,
  2974. ];
  2975. const otherEventView = new EventView(state);
  2976. const otherLocation = {};
  2977. const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
  2978. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  2979. expect(results).toBe(false);
  2980. });
  2981. });
  2982. describe('getFacetsAPIPayload', function () {
  2983. it('only includes relevant parameters', function () {
  2984. const thisEventView = new EventView(state);
  2985. const location = {};
  2986. const results = thisEventView.getFacetsAPIPayload(location);
  2987. const expected = {
  2988. query: state.query,
  2989. project: ['42'],
  2990. statsPeriod: state.statsPeriod,
  2991. environment: state.environment,
  2992. };
  2993. expect(results).toEqual(expected);
  2994. });
  2995. it('is similar on sort key sorted in opposite directions', function () {
  2996. const thisEventView = new EventView(state);
  2997. const location = {};
  2998. const thisAPIPayload = thisEventView.getFacetsAPIPayload(location);
  2999. const newColumn = {
  3000. kind: 'function',
  3001. function: ['count', ''],
  3002. };
  3003. const otherEventView = thisEventView.withUpdatedColumn(0, newColumn, meta);
  3004. const otherLocation = {};
  3005. const otherAPIPayload = otherEventView.getFacetsAPIPayload(otherLocation);
  3006. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  3007. expect(results).toBe(true);
  3008. });
  3009. it('is similar when a columns are different', function () {
  3010. const thisEventView = new EventView(state);
  3011. const location = {};
  3012. const thisAPIPayload = thisEventView.getFacetsAPIPayload(location);
  3013. const otherEventView = thisEventView.clone();
  3014. otherEventView.fields.push({field: 'title', width: COL_WIDTH_UNDEFINED});
  3015. const otherLocation = {};
  3016. const otherAPIPayload = otherEventView.getFacetsAPIPayload(otherLocation);
  3017. const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
  3018. expect(results).toBe(true);
  3019. });
  3020. });
  3021. });
  3022. describe('pickRelevantLocationQueryStrings', function () {
  3023. it('picks relevant query strings', function () {
  3024. const location = {
  3025. query: {
  3026. project: 'project',
  3027. environment: 'environment',
  3028. start: 'start',
  3029. end: 'end',
  3030. utc: 'utc',
  3031. statsPeriod: 'statsPeriod',
  3032. cursor: 'cursor',
  3033. // irrelevant query strings
  3034. bestCountry: 'canada',
  3035. },
  3036. };
  3037. const actual = pickRelevantLocationQueryStrings(location);
  3038. const expected = {
  3039. start: 'start',
  3040. end: 'end',
  3041. utc: 'utc',
  3042. statsPeriod: 'statsPeriod',
  3043. cursor: 'cursor',
  3044. };
  3045. expect(actual).toEqual(expected);
  3046. });
  3047. });