Skip to content

Commit eb07de2

Browse files
authored
Merge pull request #3580 from sniok/msw-issues-fixes
frontend: Fix several issues with storybook tests
2 parents a3ea2a3 + 88ff05a commit eb07de2

16 files changed

+744
-523
lines changed

frontend/src/components/common/ObjectEventList.stories.tsx

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -116,35 +116,42 @@ export default {
116116
],
117117
parameters: {
118118
msw: {
119-
handlers: [
120-
http.get('/api/v1/namespaces/:namespace/events', ({ params, request }) => {
121-
const url = new URL(request.url);
122-
const fieldSelector = url.searchParams.get('fieldSelector');
123-
const reqNamespace = params.namespace;
119+
handlers: {
120+
story: [
121+
http.get(
122+
'http://localhost:4466/api/v1/namespaces/:namespace/events',
123+
({ params, request }) => {
124+
const url = new URL(request.url);
125+
const fieldSelector = url.searchParams.get('fieldSelector');
126+
const reqNamespace = params.namespace;
124127

125-
if (
126-
reqNamespace === mockOwnerObject.metadata.namespace &&
127-
fieldSelector &&
128-
fieldSelector.includes(`involvedObject.kind=${mockOwnerObject.kind}`) &&
129-
fieldSelector.includes(`involvedObject.name=${mockOwnerObject.metadata.name}`)
130-
) {
131-
return HttpResponse.json({
132-
kind: 'EventList',
133-
items: mockEvents,
134-
metadata: {},
135-
});
136-
}
137-
if (
138-
reqNamespace === mockOwnerObjectNoEvents.metadata.namespace &&
139-
fieldSelector &&
140-
fieldSelector.includes(`involvedObject.kind=${mockOwnerObjectNoEvents.kind}`) &&
141-
fieldSelector.includes(`involvedObject.name=${mockOwnerObjectNoEvents.metadata.name}`)
142-
) {
143-
return HttpResponse.json({ kind: 'EventList', items: [], metadata: {} });
144-
}
145-
return HttpResponse.json({ kind: 'EventList', items: [], metadata: {} });
146-
}),
147-
],
128+
if (
129+
reqNamespace === mockOwnerObject.metadata.namespace &&
130+
fieldSelector &&
131+
fieldSelector.includes(`involvedObject.kind=${mockOwnerObject.kind}`) &&
132+
fieldSelector.includes(`involvedObject.name=${mockOwnerObject.metadata.name}`)
133+
) {
134+
return HttpResponse.json({
135+
kind: 'EventList',
136+
items: mockEvents,
137+
metadata: {},
138+
});
139+
}
140+
if (
141+
reqNamespace === mockOwnerObjectNoEvents.metadata.namespace &&
142+
fieldSelector &&
143+
fieldSelector.includes(`involvedObject.kind=${mockOwnerObjectNoEvents.kind}`) &&
144+
fieldSelector.includes(
145+
`involvedObject.name=${mockOwnerObjectNoEvents.metadata.name}`
146+
)
147+
) {
148+
return HttpResponse.json({ kind: 'EventList', items: [], metadata: {} });
149+
}
150+
return HttpResponse.json({ kind: 'EventList', items: [], metadata: {} });
151+
}
152+
),
153+
],
154+
},
148155
},
149156
},
150157
argTypes: {
@@ -184,19 +191,24 @@ ErrorFetching.args = {
184191
};
185192
ErrorFetching.parameters = {
186193
msw: {
187-
handlers: [
188-
http.get('/api/v1/namespaces/errors/events', ({ request }) => {
189-
const url = new URL(request.url);
190-
const fieldSelector = url.searchParams.get('fieldSelector');
191-
if (fieldSelector && fieldSelector.includes('involvedObject.name=error-secret')) {
192-
return HttpResponse.json(
193-
{ message: 'Simulated server error fetching events' },
194-
{ status: 500 }
195-
);
196-
}
197-
return HttpResponse.json({ kind: 'EventList', items: [], metadata: {} });
198-
}),
199-
],
194+
handlers: {
195+
story: [
196+
http.get('http://localhost:4466/api/v1/namespaces/default/events', () => {
197+
return HttpResponse.json({ kind: 'EventList', items: [], metadata: {} });
198+
}),
199+
http.get('http://localhost:4466/api/v1/namespaces/errors/events', ({ request }) => {
200+
const url = new URL(request.url);
201+
const fieldSelector = url.searchParams.get('fieldSelector');
202+
if (fieldSelector && fieldSelector.includes('involvedObject.name=error-secret')) {
203+
return HttpResponse.json(
204+
{ message: 'Simulated server error fetching events' },
205+
{ status: 500 }
206+
);
207+
}
208+
return HttpResponse.json({ kind: 'EventList', items: [], metadata: {} });
209+
}),
210+
],
211+
},
200212
},
201213
};
202214
ErrorFetching.storyName = 'Error Fetching Events';

frontend/src/components/common/Resource/DocsViewer.stories.tsx

Lines changed: 60 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,74 +25,76 @@ export default {
2525
argTypes: {},
2626
parameters: {
2727
msw: {
28-
handlers: [
29-
http.get('http://localhost:4466/openapi/v2', () =>
30-
HttpResponse.json({
31-
swagger: '2.0',
32-
info: { title: 'Test API', version: '1.0.0' },
33-
paths: {},
34-
definitions: {
35-
'io.k8s.api.core.v1.Pod': {
36-
'x-kubernetes-group-version-kind': [{ group: '', version: 'v1', kind: 'Pod' }],
37-
properties: {
38-
apiVersion: {
39-
type: 'string',
40-
description: `
28+
handlers: {
29+
story: [
30+
http.get('http://localhost:4466/openapi/v2', () =>
31+
HttpResponse.json({
32+
swagger: '2.0',
33+
info: { title: 'Test API', version: '1.0.0' },
34+
paths: {},
35+
definitions: {
36+
'io.k8s.api.core.v1.Pod': {
37+
'x-kubernetes-group-version-kind': [{ group: '', version: 'v1', kind: 'Pod' }],
38+
properties: {
39+
apiVersion: {
40+
type: 'string',
41+
description: `
4142
APIVersion defines the versioned schema of this representation of an object.
4243
Servers should convert recognized schemas to the latest internal value,
4344
and may reject unrecognized values.
4445
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
4546
`,
46-
},
47-
kind: {
48-
type: 'string',
49-
description: `
47+
},
48+
kind: {
49+
type: 'string',
50+
description: `
5051
Kind is a string value representing the REST resource this object represents.
5152
Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase.
5253
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds',
5354
`,
54-
},
55-
metadata: {
56-
type: 'object',
57-
description: `Standard object's metadata.
55+
},
56+
metadata: {
57+
type: 'object',
58+
description: `Standard object's metadata.
5859
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata`,
59-
properties: {
60-
annotations: {
61-
type: 'object',
62-
description: `Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata.
60+
properties: {
61+
annotations: {
62+
type: 'object',
63+
description: `Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata.
6364
They are not queryable and should be preserved when modifying objects.
6465
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations`,
65-
},
66-
creationTimestamp: {
67-
type: 'string',
68-
description:
69-
'CreationTimestamp is a timestamp representing the server time when this object was created',
70-
},
71-
deletionTimestamp: {
72-
type: 'string',
73-
description:
74-
'DeletionTimestamp is RFC 3339 date and time at which this resource will be deleted.',
66+
},
67+
creationTimestamp: {
68+
type: 'string',
69+
description:
70+
'CreationTimestamp is a timestamp representing the server time when this object was created',
71+
},
72+
deletionTimestamp: {
73+
type: 'string',
74+
description:
75+
'DeletionTimestamp is RFC 3339 date and time at which this resource will be deleted.',
76+
},
7577
},
7678
},
77-
},
78-
spec: {
79-
type: 'object',
80-
description: `Specification of the desired behavior of the pod.
79+
spec: {
80+
type: 'object',
81+
description: `Specification of the desired behavior of the pod.
8182
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status`,
82-
properties: {
83-
containers: {
84-
type: 'array',
85-
description: `List of containers belonging to the pod. Containers cannot currently be added or removed.
83+
properties: {
84+
containers: {
85+
type: 'array',
86+
description: `List of containers belonging to the pod. Containers cannot currently be added or removed.
8687
There must be at least one container in a Pod. Cannot be updated.`,
88+
},
8789
},
8890
},
8991
},
9092
},
9193
},
92-
},
93-
})
94-
),
95-
],
94+
})
95+
),
96+
],
97+
},
9698
},
9799
},
98100
decorators: [
@@ -127,14 +129,16 @@ ErrorDocumentation.args = {
127129
};
128130
ErrorDocumentation.parameters = {
129131
msw: {
130-
handlers: [
131-
http.get(
132-
'http://localhost:4466/openapi/v2',
133-
() =>
134-
new HttpResponse(null, {
135-
status: 500,
136-
})
137-
),
138-
],
132+
handlers: {
133+
story: [
134+
http.get(
135+
'http://localhost:4466/openapi/v2',
136+
() =>
137+
new HttpResponse(null, {
138+
status: 500,
139+
})
140+
),
141+
],
142+
},
139143
},
140144
};

0 commit comments

Comments
 (0)