5
5
* 2.0.
6
6
*/
7
7
8
- import React from 'react' ;
9
- import { LinkPreview } from '../CreateEditCustomLinkFlyout/link_preview' ;
8
+ import { composeStories } from '@storybook/testing-react' ;
10
9
import {
11
10
render ,
12
11
getNodeText ,
13
12
getByTestId ,
14
13
act ,
15
14
waitFor ,
16
15
} from '@testing-library/react' ;
17
- import {
18
- getCallApmApiSpy ,
19
- CallApmApiSpy ,
20
- } from '../../../../../../services/rest/callApmApiSpy' ;
16
+ import React from 'react' ;
17
+ import * as stories from './link_preview.stories' ;
18
+
19
+ const { Example } = composeStories ( stories ) ;
21
20
22
21
export const removeExternalLinkText = ( str : string ) =>
23
22
str . replace ( / \( o p e n s i n a n e w t a b o r w i n d o w \) / g, '' ) ;
24
23
25
24
describe ( 'LinkPreview' , ( ) => {
26
- let callApmApiSpy : CallApmApiSpy ;
27
- beforeAll ( ( ) => {
28
- callApmApiSpy = getCallApmApiSpy ( ) . mockResolvedValue ( {
29
- transaction : { id : 'foo' } ,
30
- } ) ;
31
- } ) ;
32
- afterAll ( ( ) => {
33
- jest . clearAllMocks ( ) ;
34
- } ) ;
35
25
const getElementValue = ( container : HTMLElement , id : string ) =>
36
26
getNodeText (
37
27
( ( getByTestId ( container , id ) as HTMLDivElement )
@@ -41,7 +31,7 @@ describe('LinkPreview', () => {
41
31
it ( 'shows label and url default values' , ( ) => {
42
32
act ( ( ) => {
43
33
const { container } = render (
44
- < LinkPreview label = "" url = "" filters = { [ { key : '' , value : '' } ] } />
34
+ < Example label = "" url = "" filters = { [ { key : '' , value : '' } ] } />
45
35
) ;
46
36
expect ( getElementValue ( container , 'preview-label' ) ) . toEqual ( 'Elastic.co' ) ;
47
37
expect ( getElementValue ( container , 'preview-url' ) ) . toEqual (
@@ -53,7 +43,7 @@ describe('LinkPreview', () => {
53
43
it ( 'shows label and url values' , ( ) => {
54
44
act ( ( ) => {
55
45
const { container } = render (
56
- < LinkPreview
46
+ < Example
57
47
label = "foo"
58
48
url = "https://baz.co"
59
49
filters = { [ { key : '' , value : '' } ] }
@@ -71,7 +61,7 @@ describe('LinkPreview', () => {
71
61
it ( "shows warning when couldn't replace context variables" , ( ) => {
72
62
act ( ( ) => {
73
63
const { container } = render (
74
- < LinkPreview
64
+ < Example
75
65
label = "foo"
76
66
url = "https://baz.co?service.name={{invalid}"
77
67
filters = { [ { key : '' , value : '' } ] }
@@ -86,20 +76,23 @@ describe('LinkPreview', () => {
86
76
expect ( getByTestId ( container , 'preview-warning' ) ) . toBeInTheDocument ( ) ;
87
77
} ) ;
88
78
} ) ;
79
+
89
80
it ( 'replaces url with transaction id' , async ( ) => {
90
81
const { container } = render (
91
- < LinkPreview
82
+ < Example
92
83
label = "foo"
93
84
url = "https://baz.co?transaction={{transaction.id}}"
94
85
filters = { [ { key : '' , value : '' } ] }
95
86
/>
96
87
) ;
97
- await waitFor ( ( ) => expect ( callApmApiSpy ) . toHaveBeenCalled ( ) ) ;
98
- expect ( getElementValue ( container , 'preview-label' ) ) . toEqual ( 'foo' ) ;
99
- expect (
100
- removeExternalLinkText (
101
- ( getByTestId ( container , 'preview-link' ) as HTMLAnchorElement ) . text
102
- )
103
- ) . toEqual ( 'https://baz.co?transaction=foo' ) ;
88
+
89
+ await waitFor ( ( ) => {
90
+ expect ( getElementValue ( container , 'preview-label' ) ) . toEqual ( 'foo' ) ;
91
+ expect (
92
+ removeExternalLinkText (
93
+ ( getByTestId ( container , 'preview-link' ) as HTMLAnchorElement ) . text
94
+ )
95
+ ) . toEqual ( 'https://baz.co?transaction=0' ) ;
96
+ } ) ;
104
97
} ) ;
105
98
} ) ;
0 commit comments