77 * License v3.0 only", or the "Server Side Public License, v 1".
88 */
99
10- import { getVisualizeListItemLink } from './get_visualize_list_item_link' ;
10+ import { getVisualizeListItemLinkFn } from './get_visualize_list_item_link' ;
1111import type { ApplicationStart } from '@kbn/core/public' ;
1212import { createHashHistory } from 'history' ;
1313import { FilterStateStore } from '@kbn/es-query' ;
1414import { createKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public' ;
1515import { GLOBAL_STATE_STORAGE_KEY } from '../../../common/constants' ;
16+ import type { VisualizeUserContent } from '../components/visualize_listing' ;
17+
18+ const mockItem : VisualizeUserContent = {
19+ id : '9886b410-4c8b-11e8-b3d7-01146121b73d' ,
20+ updatedAt : '2025-10-09T20:35:02.807Z' ,
21+ managed : false ,
22+ references : [ ] ,
23+ type : 'visualization' ,
24+ icon : 'visBarVertical' ,
25+ savedObjectType : 'visualization' ,
26+ typeTitle : 'Vertical bar' ,
27+ title : '[Flights] Delay Buckets' ,
28+ error : '' ,
29+ editor : {
30+ editUrl : '/edit/9886b410-4c8b-11e8-b3d7-01146121b73d' ,
31+ } ,
32+ attributes : {
33+ id : '9886b410-4c8b-11e8-b3d7-01146121b73d' ,
34+ title : '[Flights] Delay Buckets' ,
35+ description : '' ,
36+ readOnly : false ,
37+ } ,
38+ } ;
1639
1740jest . mock ( '../../services' , ( ) => {
1841 return {
@@ -36,17 +59,74 @@ const kbnUrlStateStorage = createKbnUrlStateStorage({
3659kbnUrlStateStorage . set ( GLOBAL_STATE_STORAGE_KEY , { time : { from : 'now-7d' , to : 'now' } } ) ;
3760
3861describe ( 'listing item link is correct for each app' , ( ) => {
62+ const getVisualizeListItemLink = getVisualizeListItemLinkFn ( application , kbnUrlStateStorage ) ;
63+
64+ test ( 'returns undefined if readOnly' , async ( ) => {
65+ const testItem : VisualizeUserContent = {
66+ ...mockItem ,
67+ attributes : {
68+ ...mockItem . attributes ,
69+ readOnly : true ,
70+ } ,
71+ } ;
72+ const url = getVisualizeListItemLink ( testItem ) ;
73+ expect ( url ) . toBe ( undefined ) ;
74+ } ) ;
75+
76+ test ( 'returns undefined if has error' , async ( ) => {
77+ const testItem : VisualizeUserContent = {
78+ ...mockItem ,
79+ attributes : {
80+ ...mockItem . attributes ,
81+ error : 'error here' ,
82+ } ,
83+ } ;
84+ const url = getVisualizeListItemLink ( testItem ) ;
85+ expect ( url ) . toBe ( undefined ) ;
86+ } ) ;
87+
88+ test ( 'returns undefined if onEdit is in editor' , async ( ) => {
89+ const testItem : VisualizeUserContent = {
90+ ...mockItem ,
91+ editor : { onEdit : async ( ) => { } } ,
92+ } ;
93+ const url = getVisualizeListItemLink ( testItem ) ;
94+ expect ( url ) . toBe ( undefined ) ;
95+ } ) ;
96+
97+ test ( 'returns undefined if no editor' , async ( ) => {
98+ const testItem : VisualizeUserContent = {
99+ ...mockItem ,
100+ editor : undefined ,
101+ } ;
102+ const url = getVisualizeListItemLink ( testItem ) ;
103+ expect ( url ) . toBe ( undefined ) ;
104+ } ) ;
105+
39106 test ( 'creates a link to classic visualization if editApp is not defined' , async ( ) => {
40107 const editUrl = 'edit/id' ;
41- const url = getVisualizeListItemLink ( application , kbnUrlStateStorage , undefined , editUrl ) ;
42- expect ( url ) . toMatchInlineSnapshot ( `"/app/visualize#${ editUrl } ?_g=(time:(from:now-7d,to:now))"` ) ;
108+ const testItem : VisualizeUserContent = {
109+ ...mockItem ,
110+ editor : {
111+ editUrl,
112+ } ,
113+ } ;
114+ const url = getVisualizeListItemLink ( testItem ) ;
115+ expect ( url ) . toBe ( `/app/visualize#${ editUrl } ?_g=(time:(from:now-7d,to:now))` ) ;
43116 } ) ;
44117
45118 test ( 'creates a link for the app given if editApp is defined' , async ( ) => {
46119 const editUrl = '#/edit/id' ;
47120 const editApp = 'lens' ;
48- const url = getVisualizeListItemLink ( application , kbnUrlStateStorage , editApp , editUrl ) ;
49- expect ( url ) . toMatchInlineSnapshot ( `"/app/${ editApp } ${ editUrl } ?_g=(time:(from:now-7d,to:now))"` ) ;
121+ const testItem : VisualizeUserContent = {
122+ ...mockItem ,
123+ editor : {
124+ editUrl,
125+ editApp,
126+ } ,
127+ } ;
128+ const url = getVisualizeListItemLink ( testItem ) ;
129+ expect ( url ) . toBe ( `/app/${ editApp } ${ editUrl } ?_g=(time:(from:now-7d,to:now))` ) ;
50130 } ) ;
51131
52132 describe ( 'when global time changes' , ( ) => {
@@ -62,9 +142,16 @@ describe('listing item link is correct for each app', () => {
62142 test ( 'it propagates the correct time on the query' , async ( ) => {
63143 const editUrl = '#/edit/id' ;
64144 const editApp = 'lens' ;
65- const url = getVisualizeListItemLink ( application , kbnUrlStateStorage , editApp , editUrl ) ;
66- expect ( url ) . toMatchInlineSnapshot (
67- `"/app/${ editApp } ${ editUrl } ?_g=(time:(from:'2021-01-05T11:45:53.375Z',to:'2021-01-21T11:46:00.990Z'))"`
145+ const testItem : VisualizeUserContent = {
146+ ...mockItem ,
147+ editor : {
148+ editUrl,
149+ editApp,
150+ } ,
151+ } ;
152+ const url = getVisualizeListItemLink ( testItem ) ;
153+ expect ( url ) . toBe (
154+ `/app/${ editApp } ${ editUrl } ?_g=(time:(from:'2021-01-05T11:45:53.375Z',to:'2021-01-21T11:46:00.990Z'))`
68155 ) ;
69156 } ) ;
70157 } ) ;
@@ -79,10 +166,15 @@ describe('listing item link is correct for each app', () => {
79166 test ( 'it propagates the refreshInterval on the query' , async ( ) => {
80167 const editUrl = '#/edit/id' ;
81168 const editApp = 'lens' ;
82- const url = getVisualizeListItemLink ( application , kbnUrlStateStorage , editApp , editUrl ) ;
83- expect ( url ) . toMatchInlineSnapshot (
84- `"/app/${ editApp } ${ editUrl } ?_g=(refreshInterval:(pause:!f,value:300))"`
85- ) ;
169+ const testItem : VisualizeUserContent = {
170+ ...mockItem ,
171+ editor : {
172+ editUrl,
173+ editApp,
174+ } ,
175+ } ;
176+ const url = getVisualizeListItemLink ( testItem ) ;
177+ expect ( url ) . toBe ( `/app/${ editApp } ${ editUrl } ?_g=(refreshInterval:(pause:!f,value:300))` ) ;
86178 } ) ;
87179 } ) ;
88180
@@ -117,9 +209,16 @@ describe('listing item link is correct for each app', () => {
117209 test ( 'propagates the filters on the query' , async ( ) => {
118210 const editUrl = '#/edit/id' ;
119211 const editApp = 'lens' ;
120- const url = getVisualizeListItemLink ( application , kbnUrlStateStorage , editApp , editUrl ) ;
121- expect ( url ) . toMatchInlineSnapshot (
122- `"/app/${ editApp } ${ editUrl } ?_g=(filters:!((meta:(alias:!n,disabled:!f,negate:!f),query:(query:q1)),('$state':(store:globalState),meta:(alias:!n,disabled:!f,negate:!f),query:(query:q1))))"`
212+ const testItem : VisualizeUserContent = {
213+ ...mockItem ,
214+ editor : {
215+ editUrl,
216+ editApp,
217+ } ,
218+ } ;
219+ const url = getVisualizeListItemLink ( testItem ) ;
220+ expect ( url ) . toBe (
221+ `/app/${ editApp } ${ editUrl } ?_g=(filters:!((meta:(alias:!n,disabled:!f,negate:!f),query:(query:q1)),('$state':(store:globalState),meta:(alias:!n,disabled:!f,negate:!f),query:(query:q1))))`
123222 ) ;
124223 } ) ;
125224 } ) ;
0 commit comments