12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569 |
- import {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
- import EventView, {
- isAPIPayloadSimilar,
- pickRelevantLocationQueryStrings,
- } from 'sentry/utils/discover/eventView';
- import {
- CHART_AXIS_OPTIONS,
- DISPLAY_MODE_OPTIONS,
- DisplayModes,
- } from 'sentry/utils/discover/types';
- const generateFields = fields =>
- fields.map(field => ({
- field,
- }));
- const generateSorts = sorts =>
- sorts.map(sortName => ({
- field: sortName,
- kind: 'desc',
- }));
- describe('EventView constructor', function () {
- it('instantiates default values', function () {
- const eventView = new EventView({});
- expect(eventView).toMatchObject({
- id: undefined,
- name: undefined,
- fields: [],
- sorts: [],
- query: '',
- project: [],
- start: undefined,
- end: undefined,
- statsPeriod: undefined,
- environment: [],
- yAxis: undefined,
- display: undefined,
- });
- });
- });
- describe('EventView.fromLocation()', function () {
- it('maps query strings', function () {
- const location = {
- query: {
- id: '42',
- name: 'best query',
- field: ['count()', 'id'],
- widths: ['123', '456'],
- sort: ['title', '-count'],
- query: 'event.type:transaction',
- project: [123],
- team: ['myteams', '1', '2'],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- yAxis: 'p95',
- display: 'previous',
- },
- };
- const eventView = EventView.fromLocation(location);
- expect(eventView).toMatchObject({
- id: '42',
- name: 'best query',
- fields: [
- {field: 'count()', width: 123},
- {field: 'id', width: 456},
- ],
- sorts: generateSorts(['count']),
- query: 'event.type:transaction',
- project: [123],
- team: ['myteams', 1, 2],
- start: undefined,
- end: undefined,
- statsPeriod: '14d',
- environment: ['staging'],
- yAxis: 'p95',
- display: 'previous',
- });
- });
- it('includes first valid statsPeriod', function () {
- const location = {
- query: {
- id: '42',
- name: 'best query',
- field: ['count()', 'id'],
- widths: ['123', '456'],
- sort: ['title', '-count'],
- query: 'event.type:transaction',
- project: [123],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: ['invalid', '28d'],
- environment: ['staging'],
- },
- };
- const eventView = EventView.fromLocation(location);
- expect(eventView).toMatchObject({
- id: '42',
- name: 'best query',
- fields: [
- {field: 'count()', width: 123},
- {field: 'id', width: 456},
- ],
- sorts: generateSorts(['count']),
- query: 'event.type:transaction',
- project: [123],
- start: undefined,
- end: undefined,
- statsPeriod: '28d',
- environment: ['staging'],
- });
- });
- it('includes start and end', function () {
- const location = {
- query: {
- id: '42',
- name: 'best query',
- field: ['count()', 'id'],
- widths: ['123', '456'],
- sort: ['title', '-count'],
- query: 'event.type:transaction',
- project: [123],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- environment: ['staging'],
- },
- };
- const eventView = EventView.fromLocation(location);
- expect(eventView).toMatchObject({
- id: '42',
- name: 'best query',
- fields: [
- {field: 'count()', width: 123},
- {field: 'id', width: 456},
- ],
- sorts: generateSorts(['count']),
- query: 'event.type:transaction',
- project: [123],
- start: '2019-10-01T00:00:00.000',
- end: '2019-10-02T00:00:00.000',
- environment: ['staging'],
- });
- });
- it('generates event view when there are no query strings', function () {
- const location = {
- query: {},
- };
- const eventView = EventView.fromLocation(location);
- expect(eventView).toMatchObject({
- id: void 0,
- name: void 0,
- fields: [],
- sorts: [],
- query: '',
- project: [],
- start: void 0,
- end: void 0,
- statsPeriod: '14d',
- environment: [],
- yAxis: void 0,
- });
- });
- });
- describe('EventView.fromSavedQuery()', function () {
- it('maps basic properties of saved query', function () {
- const saved = {
- id: '42',
- name: 'best query',
- fields: ['count()', 'id'],
- query: 'event.type:transaction',
- projects: [123],
- teams: ['myteams', 1],
- range: '14d',
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- orderby: '-id',
- environment: ['staging'],
- display: 'previous',
- };
- const eventView = EventView.fromSavedQuery(saved);
- expect(eventView).toMatchObject({
- id: saved.id,
- name: saved.name,
- fields: [
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'id', width: COL_WIDTH_UNDEFINED},
- ],
- sorts: [{field: 'id', kind: 'desc'}],
- query: 'event.type:transaction',
- project: [123],
- team: ['myteams', 1],
- start: undefined,
- end: undefined,
- // statsPeriod has precedence
- statsPeriod: '14d',
- environment: ['staging'],
- yAxis: undefined,
- display: 'previous',
- });
- const eventView2 = EventView.fromSavedQuery({
- ...saved,
- range: undefined,
- });
- expect(eventView2).toMatchObject({
- id: saved.id,
- name: saved.name,
- fields: [
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'id', width: COL_WIDTH_UNDEFINED},
- ],
- sorts: [{field: 'id', kind: 'desc'}],
- query: 'event.type:transaction',
- project: [123],
- team: ['myteams', 1],
- start: '2019-10-01T00:00:00.000',
- end: '2019-10-02T00:00:00.000',
- statsPeriod: undefined,
- environment: ['staging'],
- });
- });
- it('maps saved query with no conditions', function () {
- const saved = {
- orderby: '-count',
- name: 'foo bar',
- fields: ['release', 'count()'],
- widths: [111, 222],
- dateCreated: '2019-10-30T06:13:17.632078Z',
- environment: ['dev', 'production'],
- version: 2,
- createdBy: '1',
- dateUpdated: '2019-10-30T06:13:17.632096Z',
- id: '5',
- projects: [1],
- yAxis: 'count()',
- };
- const eventView = EventView.fromSavedQuery(saved);
- const expected = {
- id: '5',
- name: 'foo bar',
- fields: [
- {field: 'release', width: 111},
- {field: 'count()', width: 222},
- ],
- sorts: generateSorts(['count']),
- query: '',
- project: [1],
- environment: ['dev', 'production'],
- yAxis: 'count()',
- };
- expect(eventView).toMatchObject(expected);
- });
- it('maps properties from v2 saved query', function () {
- const saved = {
- name: 'best query',
- fields: ['count()', 'title'],
- range: '14d',
- start: '',
- end: '',
- };
- const eventView = EventView.fromSavedQuery(saved);
- expect(eventView.fields).toEqual([
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'title', width: COL_WIDTH_UNDEFINED},
- ]);
- expect(eventView.name).toEqual(saved.name);
- expect(eventView.statsPeriod).toEqual('14d');
- expect(eventView.start).toEqual(undefined);
- expect(eventView.end).toEqual(undefined);
- });
- it('saved queries are equal when start and end datetime differ in format', function () {
- const saved = {
- orderby: '-count_timestamp',
- end: '2019-10-23T19:27:04+0000',
- name: 'release query',
- fields: ['release', 'count(timestamp)'],
- dateCreated: '2019-10-30T05:10:23.718937Z',
- environment: ['dev', 'production'],
- start: '2019-10-20T21:02:51+0000',
- version: 2,
- createdBy: '1',
- dateUpdated: '2019-10-30T07:25:58.291917Z',
- id: '3',
- projects: [1],
- };
- const eventView = EventView.fromSavedQuery(saved);
- const eventView2 = EventView.fromSavedQuery({
- ...saved,
- start: '2019-10-20T21:02:51Z',
- end: '2019-10-23T19:27:04Z',
- });
- expect(eventView.isEqualTo(eventView2)).toBe(true);
- const eventView3 = EventView.fromSavedQuery({
- ...saved,
- start: '2019-10-20T21:02:51Z',
- });
- expect(eventView.isEqualTo(eventView3)).toBe(true);
- const eventView4 = EventView.fromSavedQuery({
- ...saved,
- end: '2019-10-23T19:27:04Z',
- });
- expect(eventView.isEqualTo(eventView4)).toBe(true);
- });
- it('saved queries are not equal when datetime selection are invalid', function () {
- const saved = {
- orderby: '-count_timestamp',
- end: '2019-10-23T19:27:04+0000',
- name: 'release query',
- fields: ['release', 'count(timestamp)'],
- dateCreated: '2019-10-30T05:10:23.718937Z',
- environment: ['dev', 'production'],
- start: '2019-10-20T21:02:51+0000',
- version: 2,
- createdBy: '1',
- dateUpdated: '2019-10-30T07:25:58.291917Z',
- id: '3',
- projects: [1],
- };
- const eventView = EventView.fromSavedQuery(saved);
- const eventView2 = EventView.fromSavedQuery({
- ...saved,
- start: '',
- });
- expect(eventView.isEqualTo(eventView2)).toBe(false);
- const eventView3 = EventView.fromSavedQuery({
- ...saved,
- end: '',
- });
- expect(eventView.isEqualTo(eventView3)).toBe(false);
- // this is expected since datetime (start and end) are normalized
- expect(eventView2.isEqualTo(eventView3)).toBe(true);
- });
- it('saved queries with undefined yAxis are defaulted to count() when comparing with isEqualTo', function () {
- const saved = {
- orderby: '-count_timestamp',
- end: '2019-10-23T19:27:04+0000',
- name: 'release query',
- fields: ['release', 'count(timestamp)'],
- dateCreated: '2019-10-30T05:10:23.718937Z',
- environment: ['dev', 'production'],
- start: '2019-10-20T21:02:51+0000',
- version: 2,
- createdBy: '1',
- dateUpdated: '2019-10-30T07:25:58.291917Z',
- id: '3',
- projects: [1],
- };
- const eventView = EventView.fromSavedQuery(saved);
- const eventView2 = EventView.fromSavedQuery({
- ...saved,
- yAxis: 'count()',
- });
- expect(eventView.isEqualTo(eventView2)).toBe(true);
- });
- it('uses the first yAxis from the SavedQuery', function () {
- const saved = {
- id: '42',
- name: 'best query',
- fields: ['count()', 'id'],
- query: 'event.type:transaction',
- projects: [123],
- teams: ['myteams', 1],
- range: '14d',
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- orderby: '-id',
- environment: ['staging'],
- display: 'previous',
- yAxis: ['count()'],
- };
- const eventView = EventView.fromSavedQuery(saved);
- expect(eventView).toMatchObject({
- id: saved.id,
- name: saved.name,
- fields: [
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'id', width: COL_WIDTH_UNDEFINED},
- ],
- sorts: [{field: 'id', kind: 'desc'}],
- query: 'event.type:transaction',
- project: [123],
- team: ['myteams', 1],
- start: undefined,
- end: undefined,
- statsPeriod: '14d',
- environment: ['staging'],
- yAxis: 'count()',
- display: 'previous',
- });
- });
- it('preserves utc with start/end', function () {
- const saved = {
- name: 'best query',
- query: 'event.type:transaction',
- fields: ['count()', 'title'],
- start: '2019-10-20T21:02:51+0000',
- end: '2019-10-23T19:27:04+0000',
- utc: 'true',
- };
- const eventView = EventView.fromSavedQuery(saved);
- expect(eventView).toMatchObject({
- id: saved.id,
- name: saved.name,
- fields: [
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'title', width: COL_WIDTH_UNDEFINED},
- ],
- query: 'event.type:transaction',
- start: '2019-10-20T21:02:51.000',
- end: '2019-10-23T19:27:04.000',
- utc: 'true',
- });
- });
- });
- describe('EventView.fromNewQueryWithLocation()', function () {
- const prebuiltQuery = {
- id: undefined,
- name: 'All Events',
- query: '',
- projects: [],
- fields: ['title', 'event.type', 'project', 'user', 'timestamp'],
- orderby: '-timestamp',
- version: 2,
- };
- it('maps basic properties of a prebuilt query', function () {
- const location = {
- query: {
- statsPeriod: '99d',
- },
- };
- const eventView = EventView.fromNewQueryWithLocation(prebuiltQuery, location);
- expect(eventView).toMatchObject({
- id: undefined,
- name: 'All Events',
- fields: [
- {field: 'title'},
- {field: 'event.type'},
- {field: 'project'},
- {field: 'user'},
- {field: 'timestamp'},
- ],
- sorts: [{field: 'timestamp', kind: 'desc'}],
- query: '',
- project: [],
- start: undefined,
- end: undefined,
- // statsPeriod has precedence
- statsPeriod: '99d',
- environment: [],
- yAxis: undefined,
- });
- });
- it('merges global selection values', function () {
- const location = {
- query: {
- statsPeriod: '99d',
- project: ['456'],
- environment: ['prod'],
- },
- };
- const eventView = EventView.fromNewQueryWithLocation(prebuiltQuery, location);
- expect(eventView).toMatchObject({
- id: undefined,
- name: 'All Events',
- fields: [
- {field: 'title'},
- {field: 'event.type'},
- {field: 'project'},
- {field: 'user'},
- {field: 'timestamp'},
- ],
- sorts: [{field: 'timestamp', kind: 'desc'}],
- query: '',
- project: [456],
- start: undefined,
- end: undefined,
- statsPeriod: '99d',
- environment: ['prod'],
- yAxis: undefined,
- });
- });
- it('new query takes precedence over global selection values', function () {
- const location = {
- query: {
- statsPeriod: '99d',
- project: ['456'],
- environment: ['prod'],
- },
- };
- const prebuiltQuery2 = {
- ...prebuiltQuery,
- range: '42d',
- projects: [987],
- environment: ['staging'],
- };
- const eventView = EventView.fromNewQueryWithLocation(prebuiltQuery2, location);
- expect(eventView).toMatchObject({
- id: undefined,
- name: 'All Events',
- fields: [
- {field: 'title'},
- {field: 'event.type'},
- {field: 'project'},
- {field: 'user'},
- {field: 'timestamp'},
- ],
- sorts: [{field: 'timestamp', kind: 'desc'}],
- query: '',
- project: [987],
- start: undefined,
- end: undefined,
- statsPeriod: '42d',
- environment: ['staging'],
- yAxis: undefined,
- });
- // also test start and end
- const location2 = {
- query: {
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- project: ['456'],
- environment: ['prod'],
- },
- };
- const prebuiltQuery3 = {
- ...prebuiltQuery,
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- projects: [987],
- environment: ['staging'],
- };
- const eventView2 = EventView.fromNewQueryWithLocation(prebuiltQuery3, location2);
- expect(eventView2).toMatchObject({
- id: undefined,
- name: 'All Events',
- fields: [
- {field: 'title'},
- {field: 'event.type'},
- {field: 'project'},
- {field: 'user'},
- {field: 'timestamp'},
- ],
- sorts: [{field: 'timestamp', kind: 'desc'}],
- query: '',
- project: [987],
- start: '2019-10-01T00:00:00.000',
- end: '2019-10-02T00:00:00.000',
- statsPeriod: undefined,
- environment: ['staging'],
- yAxis: undefined,
- });
- });
- });
- describe('EventView.fromSavedQueryOrLocation()', function () {
- it('maps basic properties of saved query', function () {
- const saved = {
- id: '42',
- name: 'best query',
- fields: ['count()', 'id'],
- query: 'event.type:transaction',
- projects: [123],
- range: '14d',
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- orderby: '-id',
- environment: ['staging'],
- display: 'previous',
- };
- const location = {
- query: {
- statsPeriod: '14d',
- project: ['123'],
- team: ['myteams', '1', '2'],
- environment: ['staging'],
- },
- };
- const eventView = EventView.fromSavedQueryOrLocation(saved, location);
- expect(eventView).toMatchObject({
- id: saved.id,
- name: saved.name,
- fields: [
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'id', width: COL_WIDTH_UNDEFINED},
- ],
- sorts: [{field: 'id', kind: 'desc'}],
- query: 'event.type:transaction',
- project: [123],
- team: ['myteams', 1, 2],
- start: undefined,
- end: undefined,
- // statsPeriod has precedence
- statsPeriod: '14d',
- environment: ['staging'],
- yAxis: undefined,
- display: 'previous',
- });
- const savedQuery2 = {...saved, range: undefined};
- const location2 = {
- query: {
- project: ['123'],
- environment: ['staging'],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- },
- };
- const eventView2 = EventView.fromSavedQueryOrLocation(savedQuery2, location2);
- expect(eventView2).toMatchObject({
- id: saved.id,
- name: saved.name,
- fields: [
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'id', width: COL_WIDTH_UNDEFINED},
- ],
- sorts: [{field: 'id', kind: 'desc'}],
- query: 'event.type:transaction',
- project: [123],
- start: '2019-10-01T00:00:00.000',
- end: '2019-10-02T00:00:00.000',
- statsPeriod: undefined,
- environment: ['staging'],
- });
- });
- it('overrides saved query params with location params', function () {
- const saved = {
- id: '42',
- name: 'best query',
- fields: ['count()', 'id'],
- query: 'event.type:transaction',
- projects: [123],
- range: '14d',
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- orderby: '-id',
- environment: ['staging'],
- display: 'previous',
- };
- const location = {
- query: {
- id: '42',
- statsPeriod: '7d',
- project: ['3'],
- },
- };
- const eventView = EventView.fromSavedQueryOrLocation(saved, location);
- expect(eventView).toMatchObject({
- id: saved.id,
- name: saved.name,
- fields: [
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'id', width: COL_WIDTH_UNDEFINED},
- ],
- sorts: [{field: 'id', kind: 'desc'}],
- query: 'event.type:transaction',
- project: [3],
- start: undefined,
- end: undefined,
- // statsPeriod has precedence
- statsPeriod: '7d',
- environment: [],
- yAxis: undefined,
- display: 'previous',
- });
- });
- it('maps saved query with no conditions', function () {
- const saved = {
- orderby: '-count',
- name: 'foo bar',
- fields: ['release', 'count()'],
- widths: [111, 222],
- dateCreated: '2019-10-30T06:13:17.632078Z',
- query: '',
- environment: [],
- version: 2,
- createdBy: '1',
- dateUpdated: '2019-10-30T06:13:17.632096Z',
- id: '5',
- yAxis: 'count()',
- };
- const location = {
- query: {
- id: '5',
- project: [1],
- },
- };
- const eventView = EventView.fromSavedQueryOrLocation(saved, location);
- const expected = {
- id: '5',
- name: 'foo bar',
- fields: [
- {field: 'release', width: 111},
- {field: 'count()', width: 222},
- ],
- sorts: generateSorts(['count']),
- query: '',
- project: [1],
- yAxis: 'count()',
- };
- expect(eventView).toMatchObject(expected);
- });
- it('maps query with cleared conditions', function () {
- const saved = {
- id: '42',
- name: 'best query',
- fields: ['count()', 'id'],
- query: 'event.type:transaction',
- projects: [123],
- range: '14d',
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- orderby: '-id',
- environment: ['staging'],
- display: 'previous',
- };
- const location = {
- query: {
- id: '42',
- statsPeriod: '7d',
- },
- };
- const eventView = EventView.fromSavedQueryOrLocation(saved, location);
- expect(eventView).toMatchObject({
- id: saved.id,
- name: saved.name,
- fields: [
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'id', width: COL_WIDTH_UNDEFINED},
- ],
- sorts: [{field: 'id', kind: 'desc'}],
- query: 'event.type:transaction',
- start: undefined,
- end: undefined,
- // statsPeriod has precedence
- statsPeriod: '7d',
- environment: [],
- yAxis: undefined,
- display: 'previous',
- });
- const location2 = {
- query: {
- id: '42',
- statsPeriod: '7d',
- query: '',
- },
- };
- const eventView2 = EventView.fromSavedQueryOrLocation(saved, location2);
- expect(eventView2).toMatchObject({
- id: saved.id,
- name: saved.name,
- fields: [
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'id', width: COL_WIDTH_UNDEFINED},
- ],
- sorts: [{field: 'id', kind: 'desc'}],
- query: '',
- start: undefined,
- end: undefined,
- // statsPeriod has precedence
- statsPeriod: '7d',
- environment: [],
- yAxis: undefined,
- display: 'previous',
- });
- });
- it('event views are equal when start and end datetime differ in format', function () {
- const saved = {
- orderby: '-count_timestamp',
- end: '2019-10-23T19:27:04+0000',
- name: 'release query',
- fields: ['release', 'count(timestamp)'],
- dateCreated: '2019-10-30T05:10:23.718937Z',
- environment: ['dev', 'production'],
- start: '2019-10-20T21:02:51+0000',
- version: 2,
- createdBy: '1',
- dateUpdated: '2019-10-30T07:25:58.291917Z',
- id: '3',
- };
- const location = {
- query: {
- id: '3',
- start: '2019-10-20T21:02:51+0000',
- end: '2019-10-23T19:27:04+0000',
- },
- };
- const eventView = EventView.fromSavedQueryOrLocation(saved, location);
- const location2 = {
- query: {
- id: '3',
- start: '2019-10-20T21:02:51Z',
- end: '2019-10-23T19:27:04Z',
- },
- };
- const eventView2 = EventView.fromSavedQueryOrLocation(saved, location2);
- expect(eventView.isEqualTo(eventView2)).toBe(true);
- const location3 = {
- query: {
- id: '3',
- start: '2019-10-20T21:02:51Z',
- end: '2019-10-23T19:27:04+0000',
- },
- };
- const eventView3 = EventView.fromSavedQueryOrLocation(saved, location3);
- expect(eventView.isEqualTo(eventView3)).toBe(true);
- const location4 = {
- query: {
- id: '3',
- start: '2019-10-20T21:02:51+0000',
- end: '2019-10-23T19:27:04Z',
- },
- };
- const eventView4 = EventView.fromSavedQueryOrLocation(saved, location4);
- expect(eventView.isEqualTo(eventView4)).toBe(true);
- });
- it('event views are not equal when datetime selection are invalid', function () {
- const saved = {
- orderby: '-count_timestamp',
- end: '2019-10-23T19:27:04+0000',
- name: 'release query',
- fields: ['release', 'count(timestamp)'],
- dateCreated: '2019-10-30T05:10:23.718937Z',
- environment: ['dev', 'production'],
- start: '2019-10-20T21:02:51+0000',
- version: 2,
- createdBy: '1',
- dateUpdated: '2019-10-30T07:25:58.291917Z',
- id: '3',
- projects: [1],
- };
- const location = {
- query: {
- id: '3',
- end: '2019-10-23T19:27:04+0000',
- start: '2019-10-20T21:02:51+0000',
- },
- };
- const eventView = EventView.fromSavedQueryOrLocation(saved, location);
- const location2 = {
- query: {
- id: '3',
- end: '2019-10-23T19:27:04+0000',
- start: '',
- },
- };
- const eventView2 = EventView.fromSavedQueryOrLocation(saved, location2);
- expect(eventView.isEqualTo(eventView2)).toBe(false);
- const location3 = {
- query: {
- id: '3',
- end: '',
- start: '2019-10-20T21:02:51+0000',
- },
- };
- const eventView3 = EventView.fromSavedQueryOrLocation(saved, location3);
- expect(eventView.isEqualTo(eventView3)).toBe(false);
- // this is expected since datetime (start and end) are normalized
- expect(eventView2.isEqualTo(eventView3)).toBe(true);
- });
- it('uses the first yAxis from the SavedQuery', function () {
- const saved = {
- id: '42',
- name: 'best query',
- fields: ['count()', 'id'],
- query: 'event.type:transaction',
- projects: [123],
- range: '14d',
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- orderby: '-id',
- environment: ['staging'],
- display: 'previous',
- yAxis: ['count()', 'failure_count()'],
- };
- const location = {
- query: {
- statsPeriod: '14d',
- project: ['123'],
- team: ['myteams', '1', '2'],
- environment: ['staging'],
- },
- };
- const eventView = EventView.fromSavedQueryOrLocation(saved, location);
- expect(eventView).toMatchObject({
- id: saved.id,
- name: saved.name,
- fields: [
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'id', width: COL_WIDTH_UNDEFINED},
- ],
- sorts: [{field: 'id', kind: 'desc'}],
- query: 'event.type:transaction',
- project: [123],
- team: ['myteams', 1, 2],
- start: undefined,
- end: undefined,
- statsPeriod: '14d',
- environment: ['staging'],
- yAxis: 'count()',
- display: 'previous',
- });
- });
- it('filters out invalid teams', function () {
- const eventView = EventView.fromSavedQueryOrLocation(undefined, {
- query: {
- statsPeriod: '14d',
- project: ['123'],
- team: ['myteams', '1', 'unassigned'],
- environment: ['staging'],
- },
- });
- expect(eventView.team).toEqual(['myteams', 1]);
- });
- });
- describe('EventView.generateQueryStringObject()', function () {
- it('skips empty values', function () {
- const eventView = new EventView({
- fields: generateFields(['id', 'title']),
- sorts: [],
- project: [],
- environment: '',
- statsPeriod: '',
- start: null,
- end: undefined,
- yAxis: undefined,
- display: 'previous',
- });
- const expected = {
- id: undefined,
- name: undefined,
- field: ['id', 'title'],
- widths: [],
- sort: [],
- query: '',
- project: [],
- environment: [],
- display: 'previous',
- yAxis: 'count()',
- };
- expect(eventView.generateQueryStringObject()).toEqual(expected);
- });
- it('generates query string object', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [
- {field: 'count()', width: 123},
- {field: 'project.id', width: 456},
- ],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- yAxis: 'count()',
- display: 'releases',
- interval: '1m',
- };
- const eventView = new EventView(state);
- const expected = {
- id: '1234',
- name: 'best query',
- field: ['count()', 'project.id'],
- widths: [123, 456],
- sort: ['-count'],
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- yAxis: 'count()',
- display: 'releases',
- interval: '1m',
- };
- expect(eventView.generateQueryStringObject()).toEqual(expected);
- });
- it('encodes fields', function () {
- const eventView = new EventView({
- fields: [{field: 'id'}, {field: 'title'}],
- sorts: [],
- });
- const query = eventView.generateQueryStringObject();
- expect(query.field).toEqual(['id', 'title']);
- });
- it('returns a copy of data preventing mutation', function () {
- const eventView = new EventView({
- fields: [{field: 'id'}, {field: 'title'}],
- sorts: [],
- });
- const query = eventView.generateQueryStringObject();
- query.field.push('newthing');
- // Getting the query again should return the original values.
- const secondQuery = eventView.generateQueryStringObject();
- expect(secondQuery.field).toEqual(['id', 'title']);
- expect(query).not.toEqual(secondQuery);
- });
- });
- describe('EventView.getEventsAPIPayload()', function () {
- it('generates the API payload', function () {
- const eventView = new EventView({
- id: 34,
- name: 'amazing query',
- fields: generateFields(['id']),
- sorts: generateSorts(['id']),
- query: 'event.type:csp',
- project: [567],
- environment: ['prod'],
- yAxis: 'users',
- display: 'releases',
- });
- expect(eventView.getEventsAPIPayload({})).toEqual({
- field: ['id'],
- per_page: 50,
- sort: '-id',
- query: 'event.type:csp',
- project: ['567'],
- environment: ['prod'],
- statsPeriod: '14d',
- });
- });
- it('does not append query conditions in location', function () {
- const eventView = new EventView({
- fields: generateFields(['id']),
- sorts: [],
- query: 'event.type:csp',
- });
- const location = {
- query: {
- query: 'TypeError',
- },
- };
- expect(eventView.getEventsAPIPayload(location).query).toEqual('event.type:csp');
- });
- it('only includes at most one sort key', function () {
- const eventView = new EventView({
- fields: generateFields(['count()', 'title']),
- sorts: generateSorts(['title', 'count']),
- query: 'event.type:csp',
- });
- const location = {
- query: {},
- };
- expect(eventView.getEventsAPIPayload(location).sort).toEqual('-title');
- });
- it('only includes sort keys that are defined in fields', function () {
- const eventView = new EventView({
- fields: generateFields(['title', 'count()']),
- sorts: generateSorts(['project', 'count']),
- query: 'event.type:csp',
- });
- const location = {
- query: {},
- };
- expect(eventView.getEventsAPIPayload(location).sort).toEqual('-count');
- });
- it('only includes relevant query strings', function () {
- const eventView = new EventView({
- fields: generateFields(['title', 'count()']),
- sorts: generateSorts(['project', 'count']),
- query: 'event.type:csp',
- });
- const location = {
- query: {
- start: '2020-08-12 12:13:14',
- end: '2020-08-26 12:13:14',
- utc: 'true',
- statsPeriod: '14d',
- cursor: 'some cursor',
- yAxis: 'count()',
- // irrelevant query strings
- bestCountry: 'canada',
- project: '1234',
- environment: ['staging'],
- },
- };
- expect(eventView.getEventsAPIPayload(location)).toEqual({
- project: [],
- environment: [],
- utc: 'true',
- statsPeriod: '14d',
- field: ['title', 'count()'],
- per_page: 50,
- query: 'event.type:csp',
- sort: '-count',
- cursor: 'some cursor',
- });
- });
- it('includes default coerced statsPeriod when omitted or is invalid', function () {
- const eventView = new EventView({
- fields: generateFields(['title', 'count()']),
- sorts: generateSorts(['project', 'count']),
- query: 'event.type:csp',
- project: [1234],
- environment: ['staging'],
- });
- const location = {
- query: {
- start: '',
- end: '',
- utc: 'true',
- // invalid statsPeriod string
- statsPeriod: 'invalid',
- cursor: 'some cursor',
- },
- };
- expect(eventView.getEventsAPIPayload(location)).toEqual({
- project: ['1234'],
- environment: ['staging'],
- utc: 'true',
- statsPeriod: '14d',
- field: ['title', 'count()'],
- per_page: 50,
- query: 'event.type:csp',
- sort: '-count',
- cursor: 'some cursor',
- });
- const location2 = {
- query: {
- start: '',
- end: '',
- utc: 'true',
- // statsPeriod is omitted here
- cursor: 'some cursor',
- },
- };
- expect(eventView.getEventsAPIPayload(location2)).toEqual({
- project: ['1234'],
- environment: ['staging'],
- utc: 'true',
- statsPeriod: '14d',
- field: ['title', 'count()'],
- per_page: 50,
- query: 'event.type:csp',
- sort: '-count',
- cursor: 'some cursor',
- });
- });
- it('includes default coerced statsPeriod when either start or end is only provided', function () {
- const eventView = new EventView({
- fields: generateFields(['title', 'count()']),
- sorts: generateSorts(['project', 'count']),
- query: 'event.type:csp',
- project: [1234],
- environment: ['staging'],
- });
- const location = {
- query: {
- start: '',
- utc: 'true',
- statsPeriod: 'invalid',
- cursor: 'some cursor',
- },
- };
- expect(eventView.getEventsAPIPayload(location)).toEqual({
- project: ['1234'],
- environment: ['staging'],
- utc: 'true',
- statsPeriod: '14d',
- field: ['title', 'count()'],
- per_page: 50,
- query: 'event.type:csp',
- sort: '-count',
- cursor: 'some cursor',
- });
- const location2 = {
- query: {
- end: '',
- utc: 'true',
- statsPeriod: 'invalid',
- cursor: 'some cursor',
- },
- };
- expect(eventView.getEventsAPIPayload(location2)).toEqual({
- project: ['1234'],
- environment: ['staging'],
- utc: 'true',
- statsPeriod: '14d',
- field: ['title', 'count()'],
- per_page: 50,
- query: 'event.type:csp',
- sort: '-count',
- cursor: 'some cursor',
- });
- });
- it('includes start and end', function () {
- const eventView = new EventView({
- fields: generateFields(['title', 'count()']),
- sorts: generateSorts(['count']),
- query: 'event.type:csp',
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- environment: [],
- project: [],
- });
- const location = {
- query: {
- // these should not be part of the API payload
- statsPeriod: '55d',
- period: '55d',
- },
- };
- expect(eventView.getEventsAPIPayload(location)).toEqual({
- field: ['title', 'count()'],
- sort: '-count',
- query: 'event.type:csp',
- start: '2019-10-01T00:00:00.000',
- end: '2019-10-02T00:00:00.000',
- per_page: 50,
- project: [],
- environment: [],
- });
- });
- it("an eventview's date selection has higher precedence than the date selection in the query string", function () {
- const initialState = {
- fields: generateFields(['title', 'count()']),
- sorts: generateSorts(['count']),
- query: 'event.type:csp',
- environment: [],
- project: [],
- };
- const output = {
- field: ['title', 'count()'],
- sort: '-count',
- query: 'event.type:csp',
- per_page: 50,
- project: [],
- environment: [],
- };
- // eventview's statsPeriod has highest precedence
- let eventView = new EventView({
- ...initialState,
- statsPeriod: '90d',
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- });
- let location = {
- query: {
- // these should not be part of the API payload
- statsPeriod: '55d',
- period: '30d',
- start: '2020-10-01T00:00:00',
- end: '2020-10-02T00:00:00',
- },
- };
- expect(eventView.getEventsAPIPayload(location)).toEqual({
- ...output,
- statsPeriod: '90d',
- });
- // eventview's start/end has higher precedence than the date selection in the query string
- eventView = new EventView({
- ...initialState,
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- });
- location = {
- query: {
- // these should not be part of the API payload
- statsPeriod: '55d',
- period: '30d',
- start: '2020-10-01T00:00:00',
- end: '2020-10-02T00:00:00',
- },
- };
- expect(eventView.getEventsAPIPayload(location)).toEqual({
- ...output,
- start: '2019-10-01T00:00:00.000',
- end: '2019-10-02T00:00:00.000',
- });
- // the date selection in the query string should be applied as expected
- eventView = new EventView(initialState);
- location = {
- query: {
- statsPeriod: '55d',
- period: '30d',
- start: '2020-10-01T00:00:00',
- end: '2020-10-02T00:00:00',
- },
- };
- expect(eventView.getEventsAPIPayload(location)).toEqual({
- ...output,
- statsPeriod: '55d',
- });
- location = {
- query: {
- period: '30d',
- start: '2020-10-01T00:00:00',
- end: '2020-10-02T00:00:00',
- },
- };
- expect(eventView.getEventsAPIPayload(location)).toEqual({
- ...output,
- statsPeriod: '30d',
- });
- location = {
- query: {
- start: '2020-10-01T00:00:00',
- end: '2020-10-02T00:00:00',
- },
- };
- expect(eventView.getEventsAPIPayload(location)).toEqual({
- ...output,
- start: '2020-10-01T00:00:00.000',
- end: '2020-10-02T00:00:00.000',
- });
- });
- });
- describe('EventView.getFacetsAPIPayload()', function () {
- it('only includes relevant query strings', function () {
- const eventView = new EventView({
- fields: generateFields(['title', 'count()']),
- sorts: generateSorts(['project', 'count']),
- query: 'event.type:csp',
- });
- const location = {
- query: {
- start: '',
- end: '',
- utc: 'true',
- statsPeriod: '14d',
- // irrelevant query strings
- bestCountry: 'canada',
- cursor: 'some cursor',
- sort: 'the world',
- project: '1234',
- environment: ['staging'],
- display: 'releases',
- },
- };
- expect(eventView.getFacetsAPIPayload(location)).toEqual({
- project: [],
- environment: [],
- utc: 'true',
- statsPeriod: '14d',
- query: 'event.type:csp',
- });
- });
- });
- describe('EventView.toNewQuery()', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [
- {field: 'count()', width: 123},
- {field: 'project.id', width: 456},
- ],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- display: 'releases',
- };
- it('outputs the right fields', function () {
- const eventView = new EventView(state);
- const output = eventView.toNewQuery();
- const expected = {
- version: 2,
- id: '1234',
- name: 'best query',
- fields: ['count()', 'project.id'],
- widths: ['123', '456'],
- orderby: '-count',
- query: 'event.type:error',
- projects: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- range: '14d',
- environment: ['staging'],
- display: 'releases',
- };
- expect(output).toEqual(expected);
- });
- it('omits query when query is an empty string', function () {
- const modifiedState = {
- ...state,
- };
- modifiedState.query = '';
- const eventView = new EventView(modifiedState);
- const output = eventView.toNewQuery();
- const expected = {
- version: 2,
- id: '1234',
- name: 'best query',
- fields: ['count()', 'project.id'],
- widths: ['123', '456'],
- orderby: '-count',
- projects: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- range: '14d',
- environment: ['staging'],
- display: 'releases',
- };
- expect(output).toEqual(expected);
- });
- it('omits query when query is not defined', function () {
- const modifiedState = {
- ...state,
- };
- delete modifiedState.query;
- const eventView = new EventView(modifiedState);
- const output = eventView.toNewQuery();
- const expected = {
- version: 2,
- id: '1234',
- name: 'best query',
- fields: ['count()', 'project.id'],
- widths: ['123', '456'],
- orderby: '-count',
- projects: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- range: '14d',
- environment: ['staging'],
- display: 'releases',
- };
- expect(output).toEqual(expected);
- });
- });
- describe('EventView.isValid()', function () {
- it('event view is valid when there is at least one field', function () {
- const eventView = new EventView({
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: [],
- project: [],
- });
- expect(eventView.isValid()).toBe(true);
- });
- it('event view is not valid when there are no fields', function () {
- const eventView = new EventView({
- fields: [],
- sorts: [],
- project: [],
- });
- expect(eventView.isValid()).toBe(false);
- });
- });
- describe('EventView.getWidths()', function () {
- it('returns widths', function () {
- const eventView = new EventView({
- fields: [
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'project.id', width: 2020},
- {field: 'title', width: COL_WIDTH_UNDEFINED},
- {field: 'time', width: 420},
- {field: 'lcp', width: 69},
- {field: 'lcp', width: COL_WIDTH_UNDEFINED},
- {field: 'fcp', width: COL_WIDTH_UNDEFINED},
- {field: 'cls', width: COL_WIDTH_UNDEFINED},
- ],
- sorts: [],
- project: [],
- });
- expect(eventView.getWidths()).toEqual([
- COL_WIDTH_UNDEFINED,
- 2020,
- COL_WIDTH_UNDEFINED,
- 420,
- 69,
- ]);
- });
- });
- describe('EventView.getFields()', function () {
- it('returns fields', function () {
- const eventView = new EventView({
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: [],
- project: [],
- });
- expect(eventView.getFields()).toEqual(['count()', 'project.id']);
- });
- });
- describe('EventView.numOfColumns()', function () {
- it('returns correct number of columns', function () {
- // has columns
- const eventView = new EventView({
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: [],
- project: [],
- });
- expect(eventView.numOfColumns()).toBe(2);
- // has no columns
- const eventView2 = new EventView({
- fields: [],
- sorts: [],
- project: [],
- });
- expect(eventView2.numOfColumns()).toBe(0);
- });
- });
- describe('EventView.getDays()', function () {
- it('returns the right number of days for statsPeriod', function () {
- const eventView = new EventView({
- statsPeriod: '14d',
- });
- expect(eventView.getDays()).toBe(14);
- const eventView2 = new EventView({
- statsPeriod: '12h',
- });
- expect(eventView2.getDays()).toBe(0.5);
- });
- it('returns the right number of days for start/end', function () {
- const eventView = new EventView({
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- });
- expect(eventView.getDays()).toBe(1);
- const eventView2 = new EventView({
- start: '2019-10-01T00:00:00',
- end: '2019-10-15T00:00:00',
- });
- expect(eventView2.getDays()).toBe(14);
- });
- });
- describe('EventView.clone()', function () {
- it('returns a unique instance', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- interval: '5m',
- display: 'releases',
- };
- const eventView = new EventView(state);
- const eventView2 = eventView.clone();
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(state);
- expect(eventView2).toMatchObject(state);
- expect(eventView.isEqualTo(eventView2)).toBe(true);
- expect(
- eventView.additionalConditions === eventView2.additionalConditions
- ).toBeFalsy();
- });
- });
- describe('EventView.withColumns()', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [
- {field: 'count()', width: 30},
- {field: 'project.id', width: 99},
- {field: 'failure_count()', width: 30},
- ],
- yAxis: 'failure_count()',
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- };
- const eventView = new EventView(state);
- it('adds new columns, and replaces existing ones', function () {
- const newView = eventView.withColumns([
- {kind: 'field', field: 'title'},
- {kind: 'function', function: ['count', '']},
- {kind: 'field', field: 'project.id'},
- {kind: 'field', field: 'culprit'},
- ]);
- // Views should be different.
- expect(newView.isEqualTo(eventView)).toBe(false);
- expect(newView.fields).toEqual([
- {field: 'title', width: COL_WIDTH_UNDEFINED},
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- {field: 'project.id', width: COL_WIDTH_UNDEFINED},
- {field: 'culprit', width: COL_WIDTH_UNDEFINED},
- ]);
- });
- it('drops empty columns', function () {
- const newView = eventView.withColumns([
- {kind: 'field', field: 'issue'},
- {kind: 'function', function: ['count', '']},
- {kind: 'field', field: ''},
- {kind: 'function', function: ['', '']},
- {kind: 'function', function: ['', '', undefined]},
- ]);
- expect(newView.fields).toEqual([
- {field: 'issue', width: COL_WIDTH_UNDEFINED},
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- ]);
- });
- it('inherits widths from existing columns when names match', function () {
- const newView = eventView.withColumns([
- {kind: 'function', function: ['count', '']},
- {kind: 'field', field: 'project.id'},
- {kind: 'field', field: 'title'},
- {kind: 'field', field: 'time'},
- ]);
- expect(newView.fields).toEqual([
- {field: 'count()', width: 30},
- {field: 'project.id', width: 99},
- {field: 'title', width: COL_WIDTH_UNDEFINED},
- {field: 'time', width: COL_WIDTH_UNDEFINED},
- ]);
- });
- it('retains sorts when sorted field is included', function () {
- const newView = eventView.withColumns([
- {kind: 'field', field: 'title'},
- {kind: 'function', function: ['count', '']},
- ]);
- expect(newView.fields).toEqual([
- {field: 'title', width: COL_WIDTH_UNDEFINED},
- {field: 'count()', width: COL_WIDTH_UNDEFINED},
- ]);
- expect(newView.sorts).toEqual([{field: 'count', kind: 'desc'}]);
- });
- it('updates sorts when sorted field is removed', function () {
- const newView = eventView.withColumns([{kind: 'field', field: 'title'}]);
- expect(newView.fields).toEqual([{field: 'title', width: COL_WIDTH_UNDEFINED}]);
- // Should pick a sortable field.
- expect(newView.sorts).toEqual([{field: 'title', kind: 'desc'}]);
- });
- it('has no sort if no sortable fields remain', function () {
- const newView = eventView.withColumns([{kind: 'field', field: 'issue'}]);
- expect(newView.fields).toEqual([{field: 'issue', width: COL_WIDTH_UNDEFINED}]);
- expect(newView.sorts).toEqual([]);
- });
- it('updates yAxis if column is dropped', function () {
- const newView = eventView.withColumns([
- {kind: 'field', field: 'count()'},
- {kind: 'field', field: 'project.id'},
- ]);
- expect(newView.fields).toEqual([
- {field: 'count()', width: 30},
- {field: 'project.id', width: 99},
- ]);
- expect(eventView.yAxis).toEqual('failure_count()');
- expect(newView.yAxis).toEqual('count()');
- });
- });
- describe('EventView.withNewColumn()', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [
- {field: 'count()', width: 30},
- {field: 'project.id', width: 99},
- ],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- };
- it('adds a field', function () {
- const eventView = new EventView(state);
- const newColumn = {
- kind: 'field',
- field: 'title',
- };
- const eventView2 = eventView.withNewColumn(newColumn);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(state);
- const nextState = {
- ...state,
- fields: [...state.fields, {field: 'title'}],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('adds an aggregate function with no arguments', function () {
- const eventView = new EventView(state);
- const newColumn = {
- kind: 'function',
- function: ['count', ''],
- };
- const eventView2 = eventView.withNewColumn(newColumn);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(state);
- const nextState = {
- ...state,
- fields: [...state.fields, {field: 'count()'}],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('add an aggregate function with field', function () {
- const eventView = new EventView(state);
- const newColumn = {
- kind: 'function',
- function: ['avg', 'transaction.duration'],
- };
- const eventView2 = eventView.withNewColumn(newColumn);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(state);
- const nextState = {
- ...state,
- fields: [...state.fields, {field: 'avg(transaction.duration)'}],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('add an aggregate function with field & refinement', function () {
- const eventView = new EventView(state);
- const newColumn = {
- kind: 'function',
- function: ['percentile', 'transaction.duration', '0.5'],
- };
- const updated = eventView.withNewColumn(newColumn);
- expect(updated.fields).toEqual([
- ...state.fields,
- {field: 'percentile(transaction.duration,0.5)', width: COL_WIDTH_UNDEFINED},
- ]);
- });
- });
- describe('EventView.withResizedColumn()', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- };
- const view = new EventView(state);
- it('updates a column that exists', function () {
- const newView = view.withResizedColumn(0, 99);
- expect(view.fields[0].width).toBeUndefined();
- expect(newView.fields[0].width).toEqual(99);
- });
- it('ignores columns that do not exist', function () {
- const newView = view.withResizedColumn(100, 99);
- expect(view.fields).toEqual(newView.fields);
- });
- });
- describe('EventView.withUpdatedColumn()', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- };
- const meta = {
- count: 'integer',
- title: 'string',
- };
- it('update a column with no changes', function () {
- const eventView = new EventView(state);
- const newColumn = {
- kind: 'function',
- function: ['count', ''],
- };
- const eventView2 = eventView.withUpdatedColumn(0, newColumn, meta);
- expect(eventView2 === eventView).toBeTruthy();
- expect(eventView).toMatchObject(state);
- });
- it('update a column to a field', function () {
- const eventView = new EventView(state);
- const newColumn = {
- kind: 'field',
- field: 'title',
- };
- const eventView2 = eventView.withUpdatedColumn(1, newColumn, meta);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(state);
- const nextState = {
- ...state,
- fields: [state.fields[0], {field: 'title'}],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('update a column to an aggregate function with no arguments', function () {
- const eventView = new EventView(state);
- const newColumn = {
- kind: 'function',
- function: ['count', ''],
- };
- const eventView2 = eventView.withUpdatedColumn(1, newColumn, meta);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(state);
- const nextState = {
- ...state,
- fields: [state.fields[0], {field: 'count()'}],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('update a column to an aggregate function with field', function () {
- const eventView = new EventView(state);
- const newColumn = {
- kind: 'function',
- function: ['avg', 'transaction.duration'],
- };
- const eventView2 = eventView.withUpdatedColumn(1, newColumn, meta);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(state);
- const nextState = {
- ...state,
- fields: [state.fields[0], {field: 'avg(transaction.duration)'}],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('update a column to an aggregate function with field & refinement', function () {
- const eventView = new EventView(state);
- const newColumn = {
- kind: 'function',
- function: ['percentile', 'transaction.duration', '0.5'],
- };
- const newView = eventView.withUpdatedColumn(1, newColumn, meta);
- expect(newView.fields).toEqual([
- state.fields[0],
- {field: 'percentile(transaction.duration,0.5)', width: COL_WIDTH_UNDEFINED},
- ]);
- });
- describe('update a column that is sorted', function () {
- it('the sorted column is the only sorted column', function () {
- const eventView = new EventView(state);
- const newColumn = {
- kind: 'field',
- field: 'title',
- };
- const eventView2 = eventView.withUpdatedColumn(0, newColumn, meta);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(state);
- const nextState = {
- ...state,
- sorts: [{field: 'title', kind: 'desc'}],
- fields: [{field: 'title'}, state.fields[1]],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('the sorted column occurs at least twice', function () {
- const modifiedState = {
- ...state,
- fields: [...state.fields, {field: 'count()'}],
- };
- const eventView = new EventView(modifiedState);
- const newColumn = {
- kind: 'field',
- field: 'title',
- };
- const eventView2 = eventView.withUpdatedColumn(0, newColumn, meta);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(modifiedState);
- const nextState = {
- ...state,
- fields: [{field: 'title'}, state.fields[1], {field: 'count()'}],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('using no provided table meta', function () {
- // table meta may not be provided in the invalid query state;
- // we will still want to be able to update columns
- const eventView = new EventView(state);
- const expected = {
- ...state,
- sorts: [{field: 'title', kind: 'desc'}],
- fields: [{field: 'title'}, state.fields[1]],
- };
- const newColumn = {
- kind: 'field',
- field: 'title',
- };
- const eventView2 = eventView.withUpdatedColumn(0, newColumn, {});
- expect(eventView2).toMatchObject(expected);
- const eventView3 = eventView.withUpdatedColumn(0, newColumn);
- expect(eventView3).toMatchObject(expected);
- const eventView4 = eventView.withUpdatedColumn(0, newColumn, null);
- expect(eventView4).toMatchObject(expected);
- });
- });
- describe('update a column to a non-sortable column', function () {
- it('default to a sortable column', function () {
- const modifiedState = {
- ...state,
- fields: [{field: 'count()'}, {field: 'title'}],
- };
- const eventView = new EventView(modifiedState);
- // this column is expected to be non-sortable
- const newColumn = {
- kind: 'field',
- field: 'project.id',
- };
- const eventView2 = eventView.withUpdatedColumn(0, newColumn, meta);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(modifiedState);
- const nextState = {
- ...state,
- sorts: [{field: 'title', kind: 'desc'}],
- fields: [{field: 'project.id'}, {field: 'title'}],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('has no sort if there are no sortable columns', function () {
- const modifiedState = {
- ...state,
- fields: [{field: 'count()'}],
- };
- const eventView = new EventView(modifiedState);
- // this column is expected to be non-sortable
- const newColumn = {
- kind: 'field',
- field: 'project.id',
- };
- const eventView2 = eventView.withUpdatedColumn(0, newColumn, meta);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(modifiedState);
- const nextState = {
- ...state,
- sorts: [],
- fields: [{field: 'project.id'}],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- });
- });
- describe('EventView.withDeletedColumn()', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- };
- const meta = {
- count: 'integer',
- title: 'string',
- };
- it('returns itself when attempting to delete the last remaining column', function () {
- const modifiedState = {
- ...state,
- fields: [{field: 'count()'}],
- };
- const eventView = new EventView(modifiedState);
- const eventView2 = eventView.withDeletedColumn(0, meta);
- expect(eventView2 === eventView).toBeTruthy();
- expect(eventView).toMatchObject(modifiedState);
- });
- describe('deletes column, and use any remaining sortable column', function () {
- it('using no provided table meta', function () {
- // table meta may not be provided in the invalid query state;
- // we will still want to be able to delete columns
- const state2 = {
- ...state,
- fields: [{field: 'title'}, {field: 'timestamp'}, {field: 'count()'}],
- sorts: generateSorts(['timestamp']),
- };
- const eventView = new EventView(state2);
- const expected = {
- ...state,
- sorts: generateSorts(['title']),
- fields: [{field: 'title'}, {field: 'count()'}],
- };
- const eventView2 = eventView.withDeletedColumn(1, {});
- expect(eventView2).toMatchObject(expected);
- const eventView3 = eventView.withDeletedColumn(1);
- expect(eventView3).toMatchObject(expected);
- const eventView4 = eventView.withDeletedColumn(1, null);
- expect(eventView4).toMatchObject(expected);
- });
- it('has no remaining sortable column', function () {
- const eventView = new EventView(state);
- const eventView2 = eventView.withDeletedColumn(0, meta);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(state);
- const nextState = {
- ...state,
- // we expect sorts to be empty since project.id is non-sortable
- sorts: [],
- fields: [state.fields[1]],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('has a remaining sortable column', function () {
- const modifiedState = {
- ...state,
- fields: [{field: 'count()'}, {field: 'project.id'}, {field: 'title'}],
- };
- const eventView = new EventView(modifiedState);
- const eventView2 = eventView.withDeletedColumn(0, meta);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(modifiedState);
- const nextState = {
- ...state,
- sorts: [{field: 'title', kind: 'desc'}],
- fields: [{field: 'project.id'}, {field: 'title'}],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('sorted column occurs at least twice', function () {
- const modifiedState = {
- ...state,
- fields: [...state.fields, state.fields[0]],
- };
- const eventView = new EventView(modifiedState);
- const eventView2 = eventView.withDeletedColumn(0, meta);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(modifiedState);
- const nextState = {
- ...state,
- fields: [state.fields[1], state.fields[0]],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('ensures there is at one auto-width column on deletion', function () {
- const modifiedState = {
- ...state,
- fields: [
- {field: 'id', width: 75},
- {field: 'title', width: 100},
- {field: 'project', width: 80},
- {field: 'environment', width: 99},
- ],
- };
- const eventView = new EventView(modifiedState);
- let updated = eventView.withDeletedColumn(0, meta);
- let updatedFields = [
- {field: 'title', width: -1},
- {field: 'project', width: 80},
- {field: 'environment', width: 99},
- ];
- expect(updated.fields).toEqual(updatedFields);
- updated = updated.withDeletedColumn(0, meta);
- updatedFields = [
- {field: 'project', width: -1},
- {field: 'environment', width: 99},
- ];
- expect(updated.fields).toEqual(updatedFields);
- });
- });
- });
- describe('EventView.getSorts()', function () {
- it('returns fields', function () {
- const eventView = new EventView({
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- project: [],
- });
- expect(eventView.getSorts()).toEqual([
- {
- key: 'count',
- order: 'desc',
- },
- ]);
- });
- });
- describe('EventView.getQuery()', function () {
- it('with query', function () {
- const eventView = new EventView({
- fields: [],
- sorts: [],
- project: [],
- query: 'event.type:error',
- });
- expect(eventView.getQuery()).toEqual('event.type:error');
- expect(eventView.getQuery(null)).toEqual('event.type:error');
- expect(eventView.getQuery('hello')).toEqual('event.type:error hello');
- expect(eventView.getQuery(['event.type:error', 'hello'])).toEqual(
- 'event.type:error hello'
- );
- });
- it('without query', function () {
- const eventView = new EventView({
- fields: [],
- sorts: [],
- project: [],
- });
- expect(eventView.getQuery()).toEqual('');
- expect(eventView.getQuery(null)).toEqual('');
- expect(eventView.getQuery('hello')).toEqual('hello');
- expect(eventView.getQuery(['event.type:error', 'hello'])).toEqual(
- 'event.type:error hello'
- );
- });
- });
- describe('EventView.getQueryWithAdditionalConditions', function () {
- it('with overlapping conditions', function () {
- const eventView = new EventView({
- fields: [],
- sorts: [],
- project: [],
- query: 'event.type:transaction foo:bar',
- });
- eventView.additionalConditions.setFilterValues('event.type', ['transaction']);
- expect(eventView.getQueryWithAdditionalConditions()).toEqual(
- 'event.type:transaction foo:bar'
- );
- });
- });
- describe('EventView.sortForField()', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- };
- const eventView = new EventView(state);
- const meta = {count: 'integer'};
- it('returns the sort when selected field is sorted', function () {
- const field = {
- field: 'count()',
- };
- const actual = eventView.sortForField(field, meta);
- expect(actual).toEqual({
- field: 'count',
- kind: 'desc',
- });
- });
- it('returns undefined when selected field is not sorted', function () {
- const field = {
- field: 'project.id',
- };
- expect(eventView.sortForField(field, meta)).toBeUndefined();
- });
- it('returns undefined when no meta is provided', function () {
- const field = {
- field: 'project.id',
- };
- expect(eventView.sortForField(field, undefined)).toBeUndefined();
- });
- });
- describe('EventView.sortOnField()', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- };
- const meta = {count: 'integer', title: 'string'};
- it('returns itself when attempting to sort on un-sortable field', function () {
- const eventView = new EventView(state);
- expect(eventView).toMatchObject(state);
- const field = state.fields[1];
- const eventView2 = eventView.sortOnField(field, meta);
- expect(eventView2 === eventView).toBe(true);
- });
- it('reverses the sorted field', function () {
- const eventView = new EventView(state);
- expect(eventView).toMatchObject(state);
- const field = state.fields[0];
- const eventView2 = eventView.sortOnField(field, meta);
- expect(eventView2 !== eventView).toBe(true);
- const nextState = {
- ...state,
- sorts: [{field: 'count', kind: 'asc'}],
- };
- expect(eventView2).toMatchObject(nextState);
- });
- it('enforce sort order on sorted field', function () {
- const eventView = new EventView(state);
- expect(eventView).toMatchObject(state);
- const field = state.fields[0];
- const eventView2 = eventView.sortOnField(field, meta, 'asc');
- expect(eventView2).toMatchObject({
- ...state,
- sorts: [{field: 'count', kind: 'asc'}],
- });
- const eventView3 = eventView.sortOnField(field, meta, 'desc');
- expect(eventView3).toMatchObject({
- ...state,
- sorts: [{field: 'count', kind: 'desc'}],
- });
- });
- it('sort on new field', function () {
- const modifiedState = {
- ...state,
- fields: [...state.fields, {field: 'title'}],
- };
- const eventView = new EventView(modifiedState);
- expect(eventView).toMatchObject(modifiedState);
- const field = modifiedState.fields[2];
- const eventView2 = eventView.sortOnField(field, meta);
- expect(eventView2 !== eventView).toBe(true);
- const nextState = {
- ...modifiedState,
- sorts: [{field: 'title', kind: 'desc'}],
- };
- expect(eventView2).toMatchObject(nextState);
- // enforce asc sort order
- const eventView3 = eventView.sortOnField(field, meta, 'asc');
- expect(eventView3).toMatchObject({
- ...modifiedState,
- sorts: [{field: 'title', kind: 'asc'}],
- });
- // enforce desc sort order
- const eventView4 = eventView.sortOnField(field, meta, 'desc');
- expect(eventView4).toMatchObject({
- ...modifiedState,
- sorts: [{field: 'title', kind: 'desc'}],
- });
- });
- it('sorts on a field using function format', function () {
- const modifiedState = {
- ...state,
- fields: [...state.fields, {field: 'count()'}],
- };
- const eventView = new EventView(modifiedState);
- expect(eventView).toMatchObject(modifiedState);
- const field = modifiedState.fields[2];
- let sortedEventView = eventView.sortOnField(field, meta, undefined, true);
- expect(sortedEventView.sorts).toEqual([{field: 'count()', kind: 'asc'}]);
- sortedEventView = sortedEventView.sortOnField(field, meta, undefined, true);
- expect(sortedEventView.sorts).toEqual([{field: 'count()', kind: 'desc'}]);
- });
- });
- describe('EventView.withSorts()', function () {
- it('returns a clone', function () {
- const eventView = new EventView({
- fields: [{field: 'event.type'}],
- });
- const updated = eventView.withSorts([{kind: 'desc', field: 'event.type'}]);
- expect(updated.sorts).not.toEqual(eventView.sorts);
- });
- it('only accepts sorting on fields in the view', function () {
- const eventView = new EventView({
- fields: [{field: 'event.type'}],
- });
- const updated = eventView.withSorts([
- {kind: 'desc', field: 'event.type'},
- {kind: 'asc', field: 'unknown'},
- ]);
- expect(updated.sorts).toEqual([{kind: 'desc', field: 'event.type'}]);
- });
- it('accepts aggregate field sorts', function () {
- const eventView = new EventView({
- fields: [{field: 'p50()'}],
- });
- const updated = eventView.withSorts([
- {kind: 'desc', field: 'p50'},
- {kind: 'asc', field: 'unknown'},
- ]);
- expect(updated.sorts).toEqual([{kind: 'desc', field: 'p50'}]);
- });
- });
- describe('EventView.isEqualTo()', function () {
- it('should be true when equal', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- yAxis: 'fam',
- display: 'releases',
- };
- const eventView = new EventView(state);
- const eventView2 = new EventView(state);
- expect(eventView2 !== eventView).toBeTruthy();
- expect(eventView).toMatchObject(state);
- expect(eventView2).toMatchObject(state);
- expect(eventView.isEqualTo(eventView2)).toBe(true);
- // commutativity property holds
- expect(eventView2.isEqualTo(eventView)).toBe(true);
- });
- it('should be true when datetime are equal but differ in format', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-20T21:02:51+0000',
- end: '2019-10-23T19:27:04+0000',
- environment: ['staging'],
- };
- const eventView = new EventView(state);
- const eventView2 = new EventView({
- ...state,
- start: '2019-10-20T21:02:51Z',
- end: '2019-10-23T19:27:04Z',
- });
- expect(eventView.isEqualTo(eventView2)).toBe(true);
- });
- it('should be false when not equal', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- yAxis: 'fam',
- display: 'releases',
- };
- const differences = {
- id: '12',
- name: 'new query',
- fields: [{field: 'project.id'}, {field: 'count()'}],
- sorts: [{field: 'count', kind: 'asc'}],
- query: 'event.type:transaction',
- project: [24],
- start: '2019-09-01T00:00:00',
- end: '2020-09-01T00:00:00',
- statsPeriod: '24d',
- environment: [],
- yAxis: 'ok boomer',
- display: 'previous',
- };
- const eventView = new EventView(state);
- for (const key in differences) {
- const eventView2 = new EventView({...state, [key]: differences[key]});
- expect(eventView.isEqualTo(eventView2)).toBe(false);
- }
- });
- it('undefined display type equals default display type', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- yAxis: 'fam',
- };
- const eventView = new EventView(state);
- const eventView2 = new EventView({...state, display: 'default'});
- expect(eventView.isEqualTo(eventView2)).toBe(true);
- });
- });
- describe('EventView.getResultsViewUrlTarget()', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- display: 'previous',
- };
- const organization = TestStubs.Organization();
- it('generates a URL', function () {
- const view = new EventView(state);
- const result = view.getResultsViewUrlTarget(organization.slug);
- expect(result.pathname).toEqual('/organizations/org-slug/discover/results/');
- expect(result.query.query).toEqual(state.query);
- expect(result.query.project).toEqual(state.project);
- expect(result.query.display).toEqual(state.display);
- });
- });
- describe('EventView.getResultsViewShortUrlTarget()', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- display: 'previous',
- };
- const organization = TestStubs.Organization();
- it('generates a URL', function () {
- const view = new EventView(state);
- const result = view.getResultsViewShortUrlTarget(organization.slug);
- expect(result.pathname).toEqual('/organizations/org-slug/discover/results/');
- expect(result.query).not.toHaveProperty('name');
- expect(result.query).not.toHaveProperty('fields');
- expect(result.query).not.toHaveProperty('query');
- expect(result.query.id).toEqual(state.id);
- expect(result.query.statsPeriod).toEqual(state.statsPeriod);
- expect(result.query.project).toEqual(state.project);
- expect(result.query.environment).toEqual(state.environment);
- });
- });
- describe('EventView.getPerformanceTransactionEventsViewUrlTarget()', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- display: 'previous',
- };
- const organization = TestStubs.Organization();
- const showTransactions = 'p99';
- const breakdown = 'http';
- const webVital = 'measurements.lcp';
- it('generates a URL', function () {
- const view = new EventView(state);
- const result = view.getPerformanceTransactionEventsViewUrlTarget(organization.slug, {
- showTransactions,
- breakdown,
- webVital,
- });
- expect(result.pathname).toEqual(
- '/organizations/org-slug/performance/summary/events/'
- );
- expect(result.query.query).toEqual(state.query);
- expect(result.query.project).toEqual(state.project);
- expect(result.query.sort).toEqual(['-count']);
- expect(result.query.transaction).toEqual(state.name);
- expect(result.query.showTransactions).toEqual(showTransactions);
- expect(result.query.breakdown).toEqual(breakdown);
- expect(result.query.webVital).toEqual(webVital);
- });
- });
- describe('EventView.getPageFilters()', function () {
- it('return default global selection', function () {
- const eventView = new EventView({});
- expect(eventView.getPageFilters()).toMatchObject({
- projects: [],
- environments: [],
- datetime: {
- start: null,
- end: null,
- period: null,
- // event views currently do not support the utc option,
- // see comment in EventView.getPageFilters
- utc: true,
- },
- });
- });
- it('returns global selection query', function () {
- const state2 = {
- project: [42],
- start: 'start',
- end: 'end',
- statsPeriod: '42d',
- environment: ['prod'],
- };
- const eventView = new EventView(state2);
- expect(eventView.getPageFilters()).toMatchObject({
- projects: state2.project,
- environments: state2.environment,
- datetime: {
- start: state2.start,
- end: state2.end,
- period: state2.statsPeriod,
- // event views currently do not support the utc option,
- // see comment in EventView.getPageFilters
- utc: true,
- },
- });
- });
- });
- describe('EventView.getPageFiltersQuery()', function () {
- it('return default global selection query', function () {
- const eventView = new EventView({});
- expect(eventView.getPageFiltersQuery()).toMatchObject({
- project: [],
- start: undefined,
- end: undefined,
- statsPeriod: undefined,
- environment: [],
- // event views currently do not support the utc option,
- // see comment in EventView.getPageFilters
- utc: 'true',
- });
- });
- it('returns global selection query', function () {
- const state2 = {
- project: [42],
- start: 'start',
- end: 'end',
- statsPeriod: '42d',
- environment: ['prod'],
- };
- const eventView = new EventView(state2);
- expect(eventView.getPageFiltersQuery()).toMatchObject({
- ...state2,
- // when generating the query, it converts numbers to strings
- project: ['42'],
- // event views currently do not support the utc option,
- // see comment in EventView.getPageFilters
- utc: 'true',
- });
- });
- });
- describe('EventView.generateBlankQueryStringObject()', function () {
- it('should return blank values', function () {
- const eventView = new EventView({});
- expect(eventView.generateBlankQueryStringObject()).toEqual({
- id: undefined,
- name: undefined,
- fields: undefined,
- sorts: undefined,
- query: undefined,
- project: undefined,
- start: undefined,
- end: undefined,
- statsPeriod: undefined,
- environment: undefined,
- yAxis: undefined,
- cursor: undefined,
- });
- });
- });
- describe('EventView.getYAxisOptions()', function () {
- const state = {
- fields: [],
- sorts: [],
- query: '',
- project: [],
- statsPeriod: '42d',
- environment: [],
- };
- function generateYaxis(value) {
- return {
- value,
- label: value,
- };
- }
- it('should return default options', function () {
- const thisEventView = new EventView(state);
- expect(thisEventView.getYAxisOptions()).toEqual(CHART_AXIS_OPTIONS);
- });
- it('should add aggregate fields as options', function () {
- let thisEventView = new EventView({
- ...state,
- fields: generateFields(['ignored-field', 'count_unique(issue)']),
- });
- expect(thisEventView.getYAxisOptions()).toEqual([
- generateYaxis('count_unique(issue)'),
- ...CHART_AXIS_OPTIONS,
- ]);
- // should de-duplicate entries
- thisEventView = new EventView({
- ...state,
- fields: generateFields(['ignored-field', 'count()']),
- });
- expect(thisEventView.getYAxisOptions()).toEqual([...CHART_AXIS_OPTIONS]);
- });
- it('should exclude yAxis options that are not useful', function () {
- const thisEventView = new EventView({
- ...state,
- fields: generateFields([
- 'ignored-field',
- 'count_unique(issue)',
- 'last_seen()',
- 'max(timestamp)',
- ]),
- });
- expect(thisEventView.getYAxisOptions()).toEqual([
- generateYaxis('count_unique(issue)'),
- ...CHART_AXIS_OPTIONS,
- ]);
- });
- });
- describe('EventView.getYAxis()', function () {
- const state = {
- fields: [],
- sorts: [],
- query: '',
- project: [],
- statsPeriod: '42d',
- environment: [],
- };
- it('should return first default yAxis', function () {
- const thisEventView = new EventView(state);
- expect(thisEventView.getYAxis()).toEqual('count()');
- });
- it('should return valid yAxis', function () {
- const thisEventView = new EventView({
- ...state,
- fields: generateFields(['ignored-field', 'count_unique(user)', 'last_seen']),
- yAxis: 'count_unique(user)',
- });
- expect(thisEventView.getYAxis()).toEqual('count_unique(user)');
- });
- it('should ignore invalid yAxis', function () {
- const invalid = [
- 'last_seen',
- 'latest_event',
- 'count_unique(issue)', // this is not one of the selected fields
- ];
- for (const option of invalid) {
- const thisEventView = new EventView({
- ...state,
- fields: generateFields(['ignored-field', 'last_seen', 'latest_event']),
- yAxis: option,
- });
- // yAxis defaults to the first entry of the default yAxis options
- expect(thisEventView.getYAxis()).toEqual('count()');
- }
- });
- });
- describe('EventView.getDisplayOptions()', function () {
- const state = {
- fields: [],
- sorts: [],
- query: '',
- project: [],
- statsPeriod: '42d',
- environment: [],
- };
- it('should return default options', function () {
- const eventView = new EventView({
- ...state,
- // there needs to exist an aggregate or TOP 5 modes will be disabled
- fields: [{field: 'count()'}],
- });
- expect(eventView.getDisplayOptions()).toEqual(DISPLAY_MODE_OPTIONS);
- });
- it('should disable previous when start/end are used.', function () {
- const eventView = new EventView({
- ...state,
- end: '2020-04-13T12:13:14',
- start: '2020-04-01T12:13:14',
- });
- const options = eventView.getDisplayOptions();
- expect(options[1].value).toEqual('previous');
- expect(options[1].disabled).toBeTruthy();
- });
- it('should disable top 5 period/daily if no aggregates present', function () {
- const eventView = new EventView({
- ...state,
- });
- const options = eventView.getDisplayOptions();
- expect(options[2].value).toEqual('top5');
- expect(options[2].disabled).toBeTruthy();
- expect(options[4].value).toEqual('dailytop5');
- expect(options[4].disabled).toBeTruthy();
- });
- });
- describe('EventView.getDisplayMode()', function () {
- const state = {
- fields: [],
- sorts: [],
- query: '',
- project: [],
- statsPeriod: '42d',
- environment: [],
- };
- it('should have default', function () {
- const eventView = new EventView({
- ...state,
- });
- const displayMode = eventView.getDisplayMode();
- expect(displayMode).toEqual(DisplayModes.DEFAULT);
- });
- it('should return current mode when not disabled', function () {
- const eventView = new EventView({
- ...state,
- display: DisplayModes.DAILY,
- });
- const displayMode = eventView.getDisplayMode();
- expect(displayMode).toEqual(DisplayModes.DAILY);
- });
- it('should return default mode when disabled', function () {
- const eventView = new EventView({
- ...state,
- // the existence of start and end will disable the PREVIOUS mode
- end: '2020-04-13T12:13:14',
- start: '2020-04-01T12:13:14',
- display: DisplayModes.PREVIOUS,
- });
- const displayMode = eventView.getDisplayMode();
- expect(displayMode).toEqual(DisplayModes.DEFAULT);
- });
- it('top 5 should fallback to default when disabled', function () {
- const eventView = new EventView({
- ...state,
- // the lack of an aggregate will disable the TOP5 mode
- display: DisplayModes.TOP5,
- });
- const displayMode = eventView.getDisplayMode();
- expect(displayMode).toEqual(DisplayModes.DEFAULT);
- });
- it('top 5 daily should fallback to daily when disabled', function () {
- const eventView = new EventView({
- ...state,
- // the lack of an aggregate will disable the DAILYTOP5 mode
- display: DisplayModes.DAILYTOP5,
- });
- const displayMode = eventView.getDisplayMode();
- expect(displayMode).toEqual(DisplayModes.DAILY);
- });
- it('daily mode should fall back to default when disabled', function () {
- const eventView = new EventView({
- ...state,
- // the period being less than 24h will disable the DAILY mode
- statsPeriod: '1h',
- display: DisplayModes.DAILY,
- });
- const displayMode = eventView.getDisplayMode();
- expect(displayMode).toEqual(DisplayModes.DEFAULT);
- });
- it('top 5 daily mode should fall back to default when daily is disabled', function () {
- const eventView = new EventView({
- ...state,
- // the period being less than 24h will disable the DAILY mode
- start: '2020-04-01T12:13:14',
- end: '2020-04-02T12:10:14',
- display: DisplayModes.TOP5DAILY,
- });
- const displayMode = eventView.getDisplayMode();
- expect(displayMode).toEqual(DisplayModes.DEFAULT);
- });
- });
- describe('EventView.getAggregateFields()', function () {
- const state = {
- fields: [
- {field: 'title'},
- {field: 'count()'},
- {field: 'count_unique(user)'},
- {field: 'apdex(300)'},
- {field: 'transaction'},
- ],
- sorts: [],
- query: '',
- project: [],
- statsPeriod: '42d',
- environment: [],
- };
- it('getAggregateFields() returns only aggregates', function () {
- const eventView = new EventView(state);
- const expected = [
- {field: 'count()'},
- {field: 'count_unique(user)'},
- {field: 'apdex(300)'},
- ];
- expect(eventView.getAggregateFields()).toEqual(expected);
- });
- });
- describe('EventView.hasAggregateField', function () {
- it('ensures an eventview has an aggregate field', function () {
- let eventView = new EventView({
- fields: [{field: 'foobar'}],
- sorts: [],
- query: '',
- project: [],
- environment: [],
- });
- expect(eventView.hasAggregateField()).toBe(false);
- eventView = new EventView({
- fields: [{field: 'count(foo.bar.is-Enterprise_42)'}],
- sorts: [],
- query: '',
- project: [],
- environment: [],
- });
- expect(eventView.hasAggregateField()).toBe(true);
- });
- });
- describe('isAPIPayloadSimilar', function () {
- const state = {
- id: '1234',
- name: 'best query',
- fields: [{field: 'count()'}, {field: 'project.id'}],
- sorts: generateSorts(['count']),
- query: 'event.type:error',
- project: [42],
- start: '2019-10-01T00:00:00',
- end: '2019-10-02T00:00:00',
- statsPeriod: '14d',
- environment: ['staging'],
- };
- const meta = {
- count: 'integer',
- title: 'string',
- };
- describe('getEventsAPIPayload', function () {
- it('is not similar when relevant query string keys are present in the Location object', function () {
- const thisEventView = new EventView(state);
- const location = {
- query: {
- project: 'project',
- environment: 'environment',
- start: 'start',
- end: 'end',
- utc: 'utc',
- statsPeriod: 'statsPeriod',
- cursor: 'cursor',
- },
- };
- const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
- const otherLocation = {};
- const otherAPIPayload = thisEventView.getEventsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(false);
- });
- it('is similar when irrelevant query string keys are present in the Location object', function () {
- const thisEventView = new EventView(state);
- const location = {
- query: {
- bestCountry: 'canada',
- },
- };
- const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
- const otherLocation = {};
- const otherAPIPayload = thisEventView.getEventsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(true);
- });
- it('is not similar on sort key sorted in opposite directions', function () {
- const thisEventView = new EventView(state);
- const location = {};
- const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
- const otherEventView = thisEventView.sortOnField({field: 'count()'}, meta);
- const otherLocation = {};
- const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(false);
- });
- it('is not similar when a new column is added', function () {
- const thisEventView = new EventView(state);
- const location = {};
- const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
- const otherEventView = thisEventView.clone();
- otherEventView.fields.push({field: 'title', width: COL_WIDTH_UNDEFINED});
- const otherLocation = {};
- const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(false);
- });
- it('is similar when a column is updated with no changes', function () {
- const thisEventView = new EventView(state);
- const location = {};
- const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
- const newColumn = {
- kind: 'function',
- function: ['count', ''],
- };
- const otherEventView = thisEventView.withUpdatedColumn(0, newColumn, meta);
- const otherLocation = {};
- const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(true);
- });
- it('is not similar when a column is updated with a replaced field', function () {
- const thisEventView = new EventView(state);
- const location = {};
- const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
- const newColumn = {
- kind: 'field',
- field: 'title',
- };
- const otherEventView = thisEventView.withUpdatedColumn(0, newColumn, meta);
- const otherLocation = {};
- const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(false);
- });
- it('is not similar when a column is updated with a replaced aggregation', function () {
- const thisEventView = new EventView(state);
- const location = {};
- const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
- const newColumn = {
- kind: 'function',
- function: ['avg', ''],
- };
- const otherEventView = thisEventView.withUpdatedColumn(0, newColumn, meta);
- const otherLocation = {};
- const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(false);
- });
- it('is similar when a column is renamed', function () {
- const thisEventView = new EventView(state);
- const location = {};
- const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
- const newColumn = {
- kind: 'function',
- function: ['count', ''],
- };
- const otherEventView = thisEventView.withUpdatedColumn(0, newColumn, meta);
- const otherLocation = {};
- const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(true);
- });
- it('is not similar when a column is deleted', function () {
- const thisEventView = new EventView(state);
- const location = {};
- const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
- const otherEventView = thisEventView.withDeletedColumn(0, meta);
- const otherLocation = {};
- const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(false);
- });
- it('is similar if column order changes', function () {
- const thisEventView = new EventView(state);
- const location = {};
- const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
- state.fields.reverse();
- const otherEventView = new EventView(state);
- const otherLocation = {};
- const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(true);
- });
- it('is similar if equation order relatively same', function () {
- const equationField = {field: 'equation|failure_count() / count()'};
- const otherEquationField = {field: 'equation|failure_count() / 2'};
- state.fields = [
- {field: 'project.id'},
- {field: 'count()'},
- equationField,
- otherEquationField,
- ];
- const thisEventView = new EventView(state);
- const location = {};
- const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
- state.fields = [
- equationField,
- {field: 'project.id'},
- {field: 'count()'},
- otherEquationField,
- ];
- const otherEventView = new EventView(state);
- const otherLocation = {};
- const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(true);
- });
- it('is not similar if equation order changes', function () {
- const equationField = {field: 'equation|failure_count() / count()'};
- const otherEquationField = {field: 'equation|failure_count() / 2'};
- state.fields = [
- {field: 'project.id'},
- {field: 'count()'},
- equationField,
- otherEquationField,
- ];
- const thisEventView = new EventView(state);
- const location = {};
- const thisAPIPayload = thisEventView.getEventsAPIPayload(location);
- state.fields = [
- {field: 'project.id'},
- {field: 'count()'},
- otherEquationField,
- equationField,
- ];
- const otherEventView = new EventView(state);
- const otherLocation = {};
- const otherAPIPayload = otherEventView.getEventsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(false);
- });
- });
- describe('getFacetsAPIPayload', function () {
- it('only includes relevant parameters', function () {
- const thisEventView = new EventView(state);
- const location = {};
- const results = thisEventView.getFacetsAPIPayload(location);
- const expected = {
- query: state.query,
- project: ['42'],
- statsPeriod: state.statsPeriod,
- environment: state.environment,
- };
- expect(results).toEqual(expected);
- });
- it('is similar on sort key sorted in opposite directions', function () {
- const thisEventView = new EventView(state);
- const location = {};
- const thisAPIPayload = thisEventView.getFacetsAPIPayload(location);
- const newColumn = {
- kind: 'function',
- function: ['count', ''],
- };
- const otherEventView = thisEventView.withUpdatedColumn(0, newColumn, meta);
- const otherLocation = {};
- const otherAPIPayload = otherEventView.getFacetsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(true);
- });
- it('is similar when a columns are different', function () {
- const thisEventView = new EventView(state);
- const location = {};
- const thisAPIPayload = thisEventView.getFacetsAPIPayload(location);
- const otherEventView = thisEventView.clone();
- otherEventView.fields.push({field: 'title', width: COL_WIDTH_UNDEFINED});
- const otherLocation = {};
- const otherAPIPayload = otherEventView.getFacetsAPIPayload(otherLocation);
- const results = isAPIPayloadSimilar(thisAPIPayload, otherAPIPayload);
- expect(results).toBe(true);
- });
- });
- });
- describe('pickRelevantLocationQueryStrings', function () {
- it('picks relevant query strings', function () {
- const location = {
- query: {
- project: 'project',
- environment: 'environment',
- start: 'start',
- end: 'end',
- utc: 'utc',
- statsPeriod: 'statsPeriod',
- cursor: 'cursor',
- // irrelevant query strings
- bestCountry: 'canada',
- },
- };
- const actual = pickRelevantLocationQueryStrings(location);
- const expected = {
- start: 'start',
- end: 'end',
- utc: 'utc',
- statsPeriod: 'statsPeriod',
- cursor: 'cursor',
- };
- expect(actual).toEqual(expected);
- });
- });
|