@ -1,4 +1,4 @@
import { DashboardSearchHit , DashboardSearchItemType } from '../../../search/types' ;
import { DashboardSearchItem , DashboardSearchItemType } from '../../../search/types' ;
import { DashboardLink } from '../../state/DashboardModel' ;
import { resolveLinks , searchForTags } from './DashboardLinksDashboard' ;
@ -39,7 +39,7 @@ describe('searchForTags', () => {
} ) ;
describe ( 'resolveLinks' , ( ) = > {
const setupTestContext = ( dashboardId : number , searchHitId : number ) = > {
const setupTestContext = ( dashboardUID : string , searchHitId : string ) = > {
const link : DashboardLink = {
targetBlank : false ,
keepTime : false ,
@ -52,9 +52,9 @@ describe('resolveLinks', () => {
type : 'dashboards' ,
url : '/d/6ieouugGk/DashLinks' ,
} ;
const searchHits : DashboardSearchHit [ ] = [
const searchHits : DashboardSearchItem [ ] = [
{
id : searchHitId ,
u id : searchHitId ,
title : 'DashLinks' ,
url : '/d/6ieouugGk/DashLinks' ,
isStarred : false ,
@ -70,14 +70,18 @@ describe('resolveLinks', () => {
const sanitize = jest . fn ( ( args ) = > args ) ;
const sanitizeUrl = jest . fn ( ( args ) = > args ) ;
return { dashboardId , link , searchHits , linkSrv , sanitize , sanitizeUrl } ;
return { dashboardUID , link , searchHits , linkSrv , sanitize , sanitizeUrl } ;
} ;
describe ( 'when called' , ( ) = > {
it ( 'should filter out the calling dashboardId ' , ( ) = > {
const { dashboardId , link , searchHits , linkSrv , sanitize , sanitizeUrl } = setupTestContext ( 1 , 1 ) ;
it ( 'should filter out the calling dashboardUID ' , ( ) = > {
const { dashboardUID , link , searchHits , linkSrv , sanitize , sanitizeUrl } = setupTestContext ( '1' , '1' ) ;
const results = resolveLinks ( dashboardId , link , searchHits , { getLinkSrv : ( ) = > linkSrv , sanitize , sanitizeUrl } ) ;
const results = resolveLinks ( dashboardUID , link , searchHits , {
getLinkSrv : ( ) = > linkSrv ,
sanitize ,
sanitizeUrl ,
} ) ;
expect ( results . length ) . toEqual ( 0 ) ;
expect ( linkSrv . getLinkUrl ) . toHaveBeenCalledTimes ( 0 ) ;
@ -86,9 +90,13 @@ describe('resolveLinks', () => {
} ) ;
it ( 'should resolve link url' , ( ) = > {
const { dashboardId , link , searchHits , linkSrv , sanitize , sanitizeUrl } = setupTestContext ( 1 , 2 ) ;
const { dashboardUID , link , searchHits , linkSrv , sanitize , sanitizeUrl } = setupTestContext ( '1' , '2' ) ;
const results = resolveLinks ( dashboardId , link , searchHits , { getLinkSrv : ( ) = > linkSrv , sanitize , sanitizeUrl } ) ;
const results = resolveLinks ( dashboardUID , link , searchHits , {
getLinkSrv : ( ) = > linkSrv ,
sanitize ,
sanitizeUrl ,
} ) ;
expect ( results . length ) . toEqual ( 1 ) ;
expect ( linkSrv . getLinkUrl ) . toHaveBeenCalledTimes ( 1 ) ;
@ -96,9 +104,13 @@ describe('resolveLinks', () => {
} ) ;
it ( 'should sanitize title' , ( ) = > {
const { dashboardId , link , searchHits , linkSrv , sanitize , sanitizeUrl } = setupTestContext ( 1 , 2 ) ;
const { dashboardUID , link , searchHits , linkSrv , sanitize , sanitizeUrl } = setupTestContext ( '1' , '2' ) ;
const results = resolveLinks ( dashboardId , link , searchHits , { getLinkSrv : ( ) = > linkSrv , sanitize , sanitizeUrl } ) ;
const results = resolveLinks ( dashboardUID , link , searchHits , {
getLinkSrv : ( ) = > linkSrv ,
sanitize ,
sanitizeUrl ,
} ) ;
expect ( results . length ) . toEqual ( 1 ) ;
expect ( sanitize ) . toHaveBeenCalledTimes ( 1 ) ;
@ -106,9 +118,13 @@ describe('resolveLinks', () => {
} ) ;
it ( 'should sanitize url' , ( ) = > {
const { dashboardId , link , searchHits , linkSrv , sanitize , sanitizeUrl } = setupTestContext ( 1 , 2 ) ;
const { dashboardUID , link , searchHits , linkSrv , sanitize , sanitizeUrl } = setupTestContext ( '1' , '2' ) ;
const results = resolveLinks ( dashboardId , link , searchHits , { getLinkSrv : ( ) = > linkSrv , sanitize , sanitizeUrl } ) ;
const results = resolveLinks ( dashboardUID , link , searchHits , {
getLinkSrv : ( ) = > linkSrv ,
sanitize ,
sanitizeUrl ,
} ) ;
expect ( results . length ) . toEqual ( 1 ) ;
expect ( sanitizeUrl ) . toHaveBeenCalledTimes ( 1 ) ;