Skip to content

Commit

Permalink
Fix broken setup stories (#3896)
Browse files Browse the repository at this point in the history
  • Loading branch information
julieg18 authored May 16, 2023
1 parent 89140c5 commit 1faf018
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion webview/src/setup/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
updateNeedsGitCommit
} from '../state/experimentsSlice'

const feedStore = (
export const feedStore = (
data: MessageToWebview<SetupData>,
dispatch: SetupDispatch
) => {
Expand Down
24 changes: 22 additions & 2 deletions webview/src/stories/Setup.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { StoryFn, Meta } from '@storybook/react'
import React from 'react'
import { Provider, useDispatch } from 'react-redux'
import { configureStore } from '@reduxjs/toolkit'
import { MessageToWebviewType } from 'dvc/src/webview/contract'
import { SetupData, SetupSection } from 'dvc/src/setup/webview/contract'
import { DISABLE_CHROMATIC_SNAPSHOTS } from './util'
import { App } from '../setup/components/App'
import { App, feedStore } from '../setup/components/App'
import { setupReducers } from '../setup/store'

const DEFAULT_DATA: SetupData = {
canGitInitialize: false,
Expand Down Expand Up @@ -34,6 +37,17 @@ const getUpdatedArgs = (data: Partial<SetupData>): { data: SetupData } => ({
}
})

const MockedState: React.FC<{ data: SetupData; children: React.ReactNode }> = ({
children,
data
}) => {
const dispatch = useDispatch()
const message = { data, type: MessageToWebviewType.SET_DATA }
feedStore(message, dispatch)

return <>{children}</>
}

export default {
args: {},
component: App,
Expand All @@ -42,7 +56,13 @@ export default {
} as Meta

const Template: StoryFn = ({ data }) => {
const app = <App />
const app = (
<Provider store={configureStore({ reducer: setupReducers })}>
<MockedState data={data}>
<App />
</MockedState>
</Provider>
)
window.postMessage(
{
data,
Expand Down

0 comments on commit 1faf018

Please sign in to comment.