github.com/argoproj/argo-cd@v1.8.7/ui/src/app/applications/components/utils.test.tsx (about) 1 import * as React from 'react'; 2 import * as renderer from 'react-test-renderer'; 3 import {Application, HealthStatus, HealthStatuses, OperationPhases, ResourceResult, ResultCodes, SyncStatuses} from '../../shared/models'; 4 import {ComparisonStatusIcon, getAppOperationState, getOperationType, HealthStatusIcon, OperationPhaseIcon, OperationState, ResourceResultIcon} from './utils'; 5 6 const zero = new Date(0).toISOString(); 7 8 test('getAppOperationState.DeletionTimestamp', () => { 9 const state = getAppOperationState({metadata: {deletionTimestamp: zero}} as Application); 10 11 expect(state).toStrictEqual({phase: OperationPhases.Running, startedAt: zero}); 12 }); 13 14 test('getAppOperationState.Operation', () => { 15 const state = getAppOperationState({metadata: {}, operation: {}} as Application); 16 17 expect(state.phase).toBe(OperationPhases.Running); 18 expect(state.startedAt).toBeDefined(); 19 expect(state.operation).toStrictEqual({sync: {}}); 20 }); 21 22 test('getAppOperationState.Status', () => { 23 const state = getAppOperationState({ 24 metadata: {}, 25 status: {operationState: {phase: OperationPhases.Error, startedAt: zero}} 26 } as Application); 27 28 expect(state.phase).toBe(OperationPhases.Error); 29 }); 30 31 test('getOperationType.Delete', () => { 32 const state = getOperationType({metadata: {deletionTimestamp: zero.toString()}} as Application); 33 34 expect(state).toBe('Delete'); 35 }); 36 37 test('getOperationType.Sync.Operation', () => { 38 const state = getOperationType({metadata: {}, operation: {sync: {}}} as Application); 39 40 expect(state).toBe('Sync'); 41 }); 42 43 test('getOperationType.Sync.Status', () => { 44 const state = getOperationType({metadata: {}, status: {operationState: {operation: {sync: {}}}}} as Application); 45 46 expect(state).toBe('Sync'); 47 }); 48 49 test('getOperationType.Unknown', () => { 50 const state = getOperationType({metadata: {}, status: {}} as Application); 51 52 expect(state).toBe('Unknown'); 53 }); 54 55 test('OperationState.undefined', () => { 56 const tree = renderer.create(<OperationState app={{metadata: {}, status: {}} as Application} />).toJSON(); 57 58 expect(tree).toMatchSnapshot(); 59 }); 60 61 test('OperationState.quiet', () => { 62 const tree = renderer.create(<OperationState app={{metadata: {}, status: {operationState: {}}} as Application} quiet={true} />).toJSON(); 63 64 expect(tree).toMatchSnapshot(); 65 }); 66 67 test('OperationState.Unknown', () => { 68 const tree = renderer.create(<OperationState app={{metadata: {}, status: {operationState: {}}} as Application} />).toJSON(); 69 70 expect(tree).toMatchSnapshot(); 71 }); 72 73 test('OperationState.Deleting', () => { 74 const tree = renderer.create(<OperationState app={{metadata: {deletionTimestamp: zero}, status: {operationState: {}}} as Application} />).toJSON(); 75 76 expect(tree).toMatchSnapshot(); 77 }); 78 79 test('OperationState.Sync OK', () => { 80 const tree = renderer 81 .create(<OperationState app={{metadata: {}, status: {operationState: {operation: {sync: {}}, phase: OperationPhases.Succeeded}}} as Application} />) 82 .toJSON(); 83 84 expect(tree).toMatchSnapshot(); 85 }); 86 87 test('OperationState.Sync error', () => { 88 const tree = renderer.create(<OperationState app={{metadata: {}, status: {operationState: {operation: {sync: {}}, phase: OperationPhases.Error}}} as Application} />).toJSON(); 89 90 expect(tree).toMatchSnapshot(); 91 }); 92 93 test('OperationState.Sync failed', () => { 94 const tree = renderer.create(<OperationState app={{metadata: {}, status: {operationState: {operation: {sync: {}}, phase: OperationPhases.Failed}}} as Application} />).toJSON(); 95 96 expect(tree).toMatchSnapshot(); 97 }); 98 99 test('OperationState.Syncing', () => { 100 const tree = renderer 101 .create(<OperationState app={{metadata: {}, status: {operationState: {operation: {sync: {}}, phase: OperationPhases.Running}}} as Application} />) 102 .toJSON(); 103 104 expect(tree).toMatchSnapshot(); 105 }); 106 107 test('ComparisonStatusIcon.Synced', () => { 108 const tree = renderer.create(<ComparisonStatusIcon status={SyncStatuses.Synced} />).toJSON(); 109 110 expect(tree).toMatchSnapshot(); 111 }); 112 113 test('ComparisonStatusIcon.OutOfSync', () => { 114 const tree = renderer.create(<ComparisonStatusIcon status={SyncStatuses.OutOfSync} />).toJSON(); 115 116 expect(tree).toMatchSnapshot(); 117 }); 118 119 test('ComparisonStatusIcon.Unknown', () => { 120 const tree = renderer.create(<ComparisonStatusIcon status={SyncStatuses.Unknown} />).toJSON(); 121 122 expect(tree).toMatchSnapshot(); 123 }); 124 125 test('HealthStatusIcon.Unknown', () => { 126 const tree = renderer.create(<HealthStatusIcon state={{status: HealthStatuses.Unknown} as HealthStatus} />).toJSON(); 127 128 expect(tree).toMatchSnapshot(); 129 }); 130 test('HealthStatusIcon.Progressing', () => { 131 const tree = renderer.create(<HealthStatusIcon state={{status: HealthStatuses.Progressing} as HealthStatus} />).toJSON(); 132 133 expect(tree).toMatchSnapshot(); 134 }); 135 136 test('HealthStatusIcon.Suspended', () => { 137 const tree = renderer.create(<HealthStatusIcon state={{status: HealthStatuses.Suspended} as HealthStatus} />).toJSON(); 138 139 expect(tree).toMatchSnapshot(); 140 }); 141 142 test('HealthStatusIcon.Healthy', () => { 143 const tree = renderer.create(<HealthStatusIcon state={{status: HealthStatuses.Healthy} as HealthStatus} />).toJSON(); 144 145 expect(tree).toMatchSnapshot(); 146 }); 147 148 test('HealthStatusIcon.Degraded', () => { 149 const tree = renderer.create(<HealthStatusIcon state={{status: HealthStatuses.Degraded} as HealthStatus} />).toJSON(); 150 151 expect(tree).toMatchSnapshot(); 152 }); 153 test('HealthStatusIcon.Missing', () => { 154 const tree = renderer.create(<HealthStatusIcon state={{status: HealthStatuses.Missing} as HealthStatus} />).toJSON(); 155 156 expect(tree).toMatchSnapshot(); 157 }); 158 159 test('ResourceResultIcon.Synced', () => { 160 const tree = renderer.create(<ResourceResultIcon resource={{status: ResultCodes.Synced, message: 'my-message'} as ResourceResult} />).toJSON(); 161 162 expect(tree).toMatchSnapshot(); 163 }); 164 165 test('ResourceResultIcon.Pruned', () => { 166 const tree = renderer.create(<ResourceResultIcon resource={{status: ResultCodes.Pruned} as ResourceResult} />).toJSON(); 167 168 expect(tree).toMatchSnapshot(); 169 }); 170 171 test('ResourceResultIcon.SyncFailed', () => { 172 const tree = renderer.create(<ResourceResultIcon resource={{status: ResultCodes.SyncFailed} as ResourceResult} />).toJSON(); 173 174 expect(tree).toMatchSnapshot(); 175 }); 176 177 test('ResourceResultIcon.Hook.Running', () => { 178 const tree = renderer 179 .create( 180 <ResourceResultIcon 181 resource={ 182 { 183 hookType: 'Sync', 184 hookPhase: OperationPhases.Running, 185 message: 'my-message' 186 } as ResourceResult 187 } 188 /> 189 ) 190 .toJSON(); 191 192 expect(tree).toMatchSnapshot(); 193 }); 194 195 test('ResourceResultIcon.Hook.Failed', () => { 196 const tree = renderer.create(<ResourceResultIcon resource={{hookType: 'Sync', hookPhase: OperationPhases.Failed} as ResourceResult} />).toJSON(); 197 198 expect(tree).toMatchSnapshot(); 199 }); 200 201 test('ResourceResultIcon.Hook.Error', () => { 202 const tree = renderer.create(<ResourceResultIcon resource={{hookType: 'Sync', hookPhase: OperationPhases.Error} as ResourceResult} />).toJSON(); 203 204 expect(tree).toMatchSnapshot(); 205 }); 206 207 test('ResourceResultIcon.Hook.Succeeded', () => { 208 const tree = renderer.create(<ResourceResultIcon resource={{hookType: 'Sync', hookPhase: OperationPhases.Succeeded} as ResourceResult} />).toJSON(); 209 210 expect(tree).toMatchSnapshot(); 211 }); 212 213 test('ResourceResultIcon.Hook.Terminating', () => { 214 const tree = renderer.create(<ResourceResultIcon resource={{hookType: 'Sync', hookPhase: OperationPhases.Terminating} as ResourceResult} />).toJSON(); 215 216 expect(tree).toMatchSnapshot(); 217 });