1
1
import { action } from '@storybook/addon-actions' ;
2
2
import { Meta , StoryObj } from '@storybook/react' ;
3
+ import { expect , within } from '@storybook/test' ;
4
+
3
5
import { ReactFlowProvider } from '@xyflow/react' ;
4
6
import '@xyflow/react/dist/style.css' ;
5
7
import React from 'react' ;
6
- import { allStatusScenario , denseScenario } from './.storybook/scenarii' ;
7
- import Map , { RankDirection } from './ApplicationMap' ;
8
+
9
+ import '../styles/index.scss' ;
10
+ import { HealthStatus , RankDirection , isApplication } from '../types' ;
11
+ import { allStatusScenario , denseScenario as complexTopology } from './.storybook/scenarii' ;
12
+ import Map from './ApplicationMap' ;
8
13
9
14
const meta : Meta < typeof Map > = {
10
- title : 'ApplicationMap/ Map' ,
15
+ title : 'Components/Application Map/ApplicationMap ' ,
11
16
component : Map ,
12
17
tags : [ 'autodocs' ] ,
13
18
decorators : [
14
19
( Story : any ) => (
15
20
< div className = "argocd-application-map__container" >
16
21
< ReactFlowProvider >
17
- < div style = { { width : '100vw' , height : '60vh' , background : '#f8f9fa' } } >
18
- < Story />
19
- </ div >
22
+ < Story />
20
23
</ ReactFlowProvider >
21
24
</ div >
22
25
) ,
@@ -29,9 +32,7 @@ export const Basic: Story = {
29
32
args : {
30
33
graph : allStatusScenario ,
31
34
rankdir : RankDirection . LR ,
32
- selectedNodes : [ ] ,
33
- selectedEdges : [ ] ,
34
- onEdgeClick : action ( 'onEdgeClick' ) ,
35
+ selectedApplications : [ ] ,
35
36
onPaneClick : action ( 'onPaneClick' ) ,
36
37
onApplicationClick : action ( 'onApplicationClick' ) ,
37
38
onApplicationSetClick : action ( 'onApplicationSetClick' ) ,
@@ -40,11 +41,42 @@ export const Basic: Story = {
40
41
41
42
export const ComplexTopology : Story = {
42
43
args : {
43
- graph : denseScenario ,
44
+ graph : complexTopology ,
44
45
rankdir : RankDirection . LR ,
45
- selectedNodes : [ ] ,
46
- selectedEdges : [ ] ,
47
- onEdgeClick : action ( 'onEdgeClick' ) ,
46
+ selectedApplications : [ ] ,
48
47
onPaneClick : action ( 'onPaneClick' ) ,
48
+ onApplicationClick : action ( 'onApplicationClick' ) ,
49
+ onApplicationSetClick : action ( 'onApplicationSetClick' ) ,
50
+ } ,
51
+ play : async ( { canvasElement } ) => {
52
+ const canvas = within ( canvasElement ) ;
53
+
54
+ const root_app_1 = await canvas . findByTestId ( 'rf__node-Application/default/root-app1' ) ;
55
+ expect ( root_app_1 . children [ 0 ] ) . toHaveClass ( 'argocd-application-map__node--default' ) ;
56
+
57
+ const root_app_2 = await canvas . findByTestId ( 'rf__node-Application/default/root-app2' ) ;
58
+ expect ( root_app_2 . children [ 0 ] ) . toHaveClass ( 'argocd-application-map__node--default' ) ;
59
+ } ,
60
+ } ;
61
+
62
+ export const ComplexTopologyWithSelection : Story = {
63
+ args : {
64
+ graph : complexTopology ,
65
+ rankdir : RankDirection . LR ,
66
+ selectedApplications : complexTopology . filterNodes (
67
+ ( _ , attributes ) => isApplication ( attributes . data ) && attributes . data . status . health === HealthStatus . Degraded
68
+ ) ,
69
+ onPaneClick : action ( 'onPaneClick' ) ,
70
+ onApplicationClick : action ( 'onApplicationClick' ) ,
71
+ onApplicationSetClick : action ( 'onApplicationSetClick' ) ,
72
+ } ,
73
+ play : async ( { canvasElement } ) => {
74
+ const canvas = within ( canvasElement ) ;
75
+
76
+ const root_app_1 = await canvas . findByTestId ( 'rf__node-Application/default/root-app1' ) ;
77
+ expect ( root_app_1 . children [ 0 ] ) . toHaveClass ( 'argocd-application-map__node--unselected' ) ;
78
+
79
+ const root_app_2 = await canvas . findByTestId ( 'rf__node-Application/default/root-app2' ) ;
80
+ expect ( root_app_2 . children [ 0 ] ) . toHaveClass ( 'argocd-application-map__node--selected' ) ;
49
81
} ,
50
82
} ;
0 commit comments