|
| 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 React from 'react'; |
| 20 | +import { I18nextProvider } from 'react-i18next'; |
| 21 | +import { Provider } from 'react-redux'; |
| 22 | +import i18n from '../../i18n/config'; |
| 23 | +import store from '../../redux/stores/store'; |
| 24 | +import AppContainer from './AppContainer'; |
| 25 | + |
| 26 | +const withEnv = (Story: React.ComponentType) => { |
| 27 | + const prev = (window as any).desktopApi; |
| 28 | + (window as any).desktopApi = { |
| 29 | + send: () => {}, |
| 30 | + receive: () => {}, |
| 31 | + }; |
| 32 | + |
| 33 | + React.useEffect(() => { |
| 34 | + return () => { |
| 35 | + if (prev === undefined) { |
| 36 | + delete (window as any).desktopApi; |
| 37 | + } else { |
| 38 | + (window as any).desktopApi = prev; |
| 39 | + } |
| 40 | + }; |
| 41 | + }, []); |
| 42 | + |
| 43 | + return ( |
| 44 | + <Provider store={store}> |
| 45 | + <I18nextProvider i18n={i18n}> |
| 46 | + <Story /> |
| 47 | + </I18nextProvider> |
| 48 | + </Provider> |
| 49 | + ); |
| 50 | +}; |
| 51 | + |
| 52 | +export default { |
| 53 | + title: 'App/AppContainer', |
| 54 | + component: AppContainer, |
| 55 | + decorators: [withEnv], |
| 56 | + parameters: { |
| 57 | + layout: 'fullscreen', |
| 58 | + storyshots: { disable: true }, |
| 59 | + docs: { |
| 60 | + description: { |
| 61 | + component: |
| 62 | + 'The root container for the Headlamp application. It sets up routing, global providers, and the main layout. This story primarily verifies that it renders its children correctly.', |
| 63 | + }, |
| 64 | + }, |
| 65 | + msw: { |
| 66 | + handlers: [ |
| 67 | + http.get('*/plugins', () => HttpResponse.json([])), |
| 68 | + http.get('*/config', () => HttpResponse.json({})), |
| 69 | + ], |
| 70 | + }, |
| 71 | + }, |
| 72 | +} as Meta<typeof AppContainer>; |
| 73 | + |
| 74 | +const Template: StoryFn = args => <AppContainer {...args} />; |
| 75 | + |
| 76 | +export const Default = Template.bind({}); |
0 commit comments