|
| 1 | +/* |
| 2 | + * Copyright 2025 The Kubernetes Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { Meta, StoryFn } from '@storybook/react'; |
| 18 | +import { http, HttpResponse } from 'msw'; |
| 19 | +import { MemoryRouter } from 'react-router-dom'; |
| 20 | +import { TestContext } from '../../test'; |
| 21 | +import StatefulSetDetails from './Details'; |
| 22 | + |
| 23 | +const mockStatefulSet = { |
| 24 | + apiVersion: 'apps/v1', |
| 25 | + kind: 'StatefulSet', |
| 26 | + metadata: { |
| 27 | + name: 'mock-statefulset', |
| 28 | + namespace: 'default', |
| 29 | + uid: '12345678-1234-1256-1234-123456789012', |
| 30 | + creationTimestamp: '2025-05-31T17:15:53.298Z', |
| 31 | + }, |
| 32 | + spec: { |
| 33 | + replicas: 3, |
| 34 | + selector: { |
| 35 | + matchLabels: { |
| 36 | + app: 'mock-app', |
| 37 | + }, |
| 38 | + }, |
| 39 | + updateStrategy: { |
| 40 | + type: 'RollingUpdate', |
| 41 | + }, |
| 42 | + serviceName: 'mock-service', |
| 43 | + template: { |
| 44 | + metadata: { |
| 45 | + labels: { |
| 46 | + app: 'mock-app', |
| 47 | + }, |
| 48 | + }, |
| 49 | + spec: { |
| 50 | + containers: [ |
| 51 | + { |
| 52 | + name: 'main', |
| 53 | + image: 'mock-image:latest', |
| 54 | + ports: [ |
| 55 | + { |
| 56 | + containerPort: 8080, |
| 57 | + }, |
| 58 | + ], |
| 59 | + }, |
| 60 | + ], |
| 61 | + }, |
| 62 | + }, |
| 63 | + volumeClaimTemplates: [ |
| 64 | + { |
| 65 | + metadata: { |
| 66 | + name: 'data', |
| 67 | + }, |
| 68 | + spec: { |
| 69 | + accessModes: ['ReadWriteOnce'], |
| 70 | + resources: { |
| 71 | + requests: { |
| 72 | + storage: '1Gi', |
| 73 | + }, |
| 74 | + }, |
| 75 | + }, |
| 76 | + }, |
| 77 | + ], |
| 78 | + }, |
| 79 | + status: { |
| 80 | + replicas: 3, |
| 81 | + readyReplicas: 3, |
| 82 | + currentReplicas: 3, |
| 83 | + updatedReplicas: 3, |
| 84 | + }, |
| 85 | +}; |
| 86 | + |
| 87 | +export default { |
| 88 | + title: 'StatefulSet/Details', |
| 89 | + component: StatefulSetDetails, |
| 90 | + decorators: [ |
| 91 | + Story => ( |
| 92 | + <MemoryRouter> |
| 93 | + <TestContext> |
| 94 | + <Story /> |
| 95 | + </TestContext> |
| 96 | + </MemoryRouter> |
| 97 | + ), |
| 98 | + ], |
| 99 | + parameters: { |
| 100 | + msw: { |
| 101 | + handlers: [ |
| 102 | + http.get( |
| 103 | + 'http://localhost:4466/apis/apps/v1/namespaces/default/statefulsets/mock-statefulset', |
| 104 | + () => { |
| 105 | + return HttpResponse.json(mockStatefulSet); |
| 106 | + } |
| 107 | + ), |
| 108 | + http.get('http://localhost:4466/api/v1/namespaces/default/pods', () => { |
| 109 | + return HttpResponse.json({ |
| 110 | + kind: 'PodList', |
| 111 | + items: [], |
| 112 | + }); |
| 113 | + }), |
| 114 | + http.get('http://localhost:4466/api/v1/namespaces/default/events', () => { |
| 115 | + return HttpResponse.json({ |
| 116 | + kind: 'EventList', |
| 117 | + items: [], |
| 118 | + }); |
| 119 | + }), |
| 120 | + ], |
| 121 | + }, |
| 122 | + }, |
| 123 | +} as Meta; |
| 124 | + |
| 125 | +const Template: StoryFn<typeof StatefulSetDetails> = args => <StatefulSetDetails {...args} />; |
| 126 | + |
| 127 | +export const Default = Template.bind({}); |
| 128 | +Default.args = { |
| 129 | + name: 'mock-statefulset', |
| 130 | + namespace: 'default', |
| 131 | +}; |
| 132 | + |
| 133 | +export const WithOnDeleteStrategy = Template.bind({}); |
| 134 | +WithOnDeleteStrategy.args = { |
| 135 | + name: 'mock-statefulset', |
| 136 | + namespace: 'default', |
| 137 | +}; |
| 138 | +WithOnDeleteStrategy.parameters = { |
| 139 | + msw: { |
| 140 | + handlers: [ |
| 141 | + http.get( |
| 142 | + 'http://localhost:4466/apis/apps/v1/namespaces/default/statefulsets/mock-statefulset', |
| 143 | + () => { |
| 144 | + return HttpResponse.json({ |
| 145 | + ...mockStatefulSet, |
| 146 | + spec: { |
| 147 | + ...mockStatefulSet.spec, |
| 148 | + updateStrategy: { |
| 149 | + type: 'OnDelete', |
| 150 | + }, |
| 151 | + }, |
| 152 | + }); |
| 153 | + } |
| 154 | + ), |
| 155 | + ], |
| 156 | + }, |
| 157 | +}; |
| 158 | + |
| 159 | +export const WithComplexSelector = Template.bind({}); |
| 160 | +WithComplexSelector.args = { |
| 161 | + name: 'mock-statefulset', |
| 162 | + namespace: 'default', |
| 163 | +}; |
| 164 | +WithComplexSelector.parameters = { |
| 165 | + msw: { |
| 166 | + handlers: [ |
| 167 | + http.get( |
| 168 | + 'http://localhost:4466/apis/apps/v1/namespaces/default/statefulsets/mock-statefulset', |
| 169 | + () => { |
| 170 | + return HttpResponse.json({ |
| 171 | + ...mockStatefulSet, |
| 172 | + spec: { |
| 173 | + ...mockStatefulSet.spec, |
| 174 | + selector: { |
| 175 | + matchLabels: { |
| 176 | + app: 'mock-app', |
| 177 | + tier: 'backend', |
| 178 | + environment: 'production', |
| 179 | + }, |
| 180 | + }, |
| 181 | + }, |
| 182 | + }); |
| 183 | + } |
| 184 | + ), |
| 185 | + ], |
| 186 | + }, |
| 187 | +}; |
| 188 | + |
| 189 | +export const WithMultipleContainers = Template.bind({}); |
| 190 | +WithMultipleContainers.args = { |
| 191 | + name: 'mock-statefulset', |
| 192 | + namespace: 'default', |
| 193 | +}; |
| 194 | +WithMultipleContainers.parameters = { |
| 195 | + msw: { |
| 196 | + handlers: [ |
| 197 | + http.get( |
| 198 | + 'http://localhost:4466/apis/apps/v1/namespaces/default/statefulsets/mock-statefulset', |
| 199 | + () => { |
| 200 | + return HttpResponse.json({ |
| 201 | + ...mockStatefulSet, |
| 202 | + spec: { |
| 203 | + ...mockStatefulSet.spec, |
| 204 | + template: { |
| 205 | + ...mockStatefulSet.spec.template, |
| 206 | + spec: { |
| 207 | + containers: [ |
| 208 | + { |
| 209 | + name: 'main', |
| 210 | + image: 'mock-image:latest', |
| 211 | + }, |
| 212 | + { |
| 213 | + name: 'sidecar', |
| 214 | + image: 'sidecar-image:latest', |
| 215 | + }, |
| 216 | + ], |
| 217 | + }, |
| 218 | + }, |
| 219 | + }, |
| 220 | + }); |
| 221 | + } |
| 222 | + ), |
| 223 | + ], |
| 224 | + }, |
| 225 | +}; |
0 commit comments