This repository was archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Storybook: Enable interactive stories #30294
Draft
umpox
wants to merge
1
commit into
tr/fix-commits-popovr
Choose a base branch
from
tr/interactive-stories
base: tr/fix-commits-popovr
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+795
−709
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
client/web/src/repo/RevisionsPopover/RevisionsPopover.actions.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as DOMTestingLibrary from '@testing-library/dom' | ||
import * as DOMQueries from '@testing-library/dom/types/queries' | ||
import * as ReactTestingLibrary from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
import { waitForNextApolloResponse } from '@sourcegraph/shared/src/testing/apollo' | ||
|
||
/** We either have the render if using React, or the HTML element if using the DOM */ | ||
type HTMLContainer = HTMLElement | ||
|
||
interface UserActionMap { | ||
selectBranchTab: () => Promise<void> | ||
selectTagTab: () => Promise<void> | ||
selectCommitTab: () => Promise<void> | ||
focusGitReference: () => void | ||
} | ||
|
||
export const revisionPopoverUserActions = (renderResult: HTMLContainer): UserActionMap => { | ||
const boundFunctions: | ||
| DOMTestingLibrary.BoundFunctions<typeof DOMQueries> | ||
| ReactTestingLibrary.BoundFunctions<typeof DOMQueries> = DOMTestingLibrary.within<typeof DOMQueries>( | ||
renderResult | ||
) | ||
|
||
return { | ||
selectBranchTab: async () => { | ||
const branchTab = boundFunctions.getByText('Branches') | ||
userEvent.click(branchTab) | ||
await waitForNextApolloResponse() | ||
}, | ||
selectTagTab: async () => { | ||
const tagsTab = boundFunctions.getByText('Tags') | ||
userEvent.click(tagsTab) | ||
await waitForNextApolloResponse() | ||
}, | ||
selectCommitTab: async () => { | ||
const commitsTab = boundFunctions.getByText('Commits') | ||
userEvent.click(commitsTab) | ||
await waitForNextApolloResponse() | ||
}, | ||
focusGitReference: () => { | ||
const gitReference = boundFunctions.getAllByTestId('git-ref-node')[0] | ||
gitReference.focus() | ||
}, | ||
} | ||
} |
81 changes: 38 additions & 43 deletions
81
client/web/src/repo/RevisionsPopover/RevisionsPopover.story.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,50 @@ | ||
import { Meta } from '@storybook/react' | ||
import React, { useMemo } from 'react' | ||
import { ComponentMeta, ComponentStory } from '@storybook/react' | ||
import React from 'react' | ||
|
||
import { WebStory } from '@sourcegraph/web/src/components/WebStory' | ||
import { WebStory } from '../../components/WebStory' | ||
|
||
import { RevisionsPopover } from './RevisionsPopover' | ||
import { revisionPopoverUserActions } from './RevisionsPopover.actions' | ||
import { MOCK_PROPS, MOCK_REQUESTS } from './RevisionsPopover.mocks' | ||
|
||
import { LAST_TAB_STORAGE_KEY } from '.' | ||
|
||
const Story: Meta = { | ||
const config: ComponentMeta<typeof RevisionsPopover> = { | ||
/* 👇 The title prop is optional. | ||
* See https://storybook.js.org/docs/react/configure/overview#configure-story-loading | ||
* to learn how to generate automatic titles | ||
*/ | ||
title: 'web/RevisionsPopover', | ||
|
||
decorators: [ | ||
story => ( | ||
<WebStory | ||
mocks={MOCK_REQUESTS} | ||
initialEntries={[{ pathname: `/${MOCK_PROPS.repoName}` }]} | ||
// Can't utilise loose mocking here as the commit/branch requests use the same operations just with different variables | ||
useStrictMocking={true} | ||
> | ||
{() => <div className="container mt-3">{story()}</div>} | ||
</WebStory> | ||
), | ||
], | ||
|
||
parameters: { | ||
component: RevisionsPopover, | ||
design: { | ||
type: 'figma', | ||
name: 'Figma', | ||
url: | ||
'https://www.figma.com/file/NIsN34NH7lPu04olBzddTw/Design-Refresh-Systemization-source-of-truth?node-id=954%3A2161', | ||
}, | ||
}, | ||
component: RevisionsPopover, | ||
} | ||
|
||
export default Story | ||
|
||
interface RevisionsPopoverStoryProps { | ||
initialTabIndex: number | ||
export default config | ||
|
||
const Template: ComponentStory<typeof RevisionsPopover> = templateProps => ( | ||
<WebStory | ||
mocks={MOCK_REQUESTS} | ||
initialEntries={[{ pathname: `/${MOCK_PROPS.repoName}` }]} | ||
// Can't utilise loose mocking here as the commit/branch requests use the same operations just with different variables | ||
useStrictMocking={true} | ||
> | ||
{webStoryProps => <RevisionsPopover {...webStoryProps} {...templateProps} {...MOCK_PROPS} />} | ||
</WebStory> | ||
) | ||
|
||
export const RevisionsPopoverBranches = Template.bind({}) | ||
RevisionsPopoverBranches.play = async ({ canvasElement }) => { | ||
const { selectBranchTab, focusGitReference } = revisionPopoverUserActions(canvasElement) | ||
await selectBranchTab() | ||
focusGitReference() | ||
} | ||
|
||
const RevisionsPopoverStory: React.FunctionComponent<RevisionsPopoverStoryProps> = ({ initialTabIndex }) => { | ||
// Ensure we have prepared the correct tab index before we render | ||
useMemo(() => { | ||
localStorage.setItem(LAST_TAB_STORAGE_KEY, initialTabIndex.toString()) | ||
}, [initialTabIndex]) | ||
|
||
return <RevisionsPopover {...MOCK_PROPS} /> | ||
export const RevisionsPopoverTags = Template.bind({}) | ||
RevisionsPopoverTags.play = async ({ canvasElement }) => { | ||
const { selectTagTab, focusGitReference } = revisionPopoverUserActions(canvasElement) | ||
await selectTagTab() | ||
focusGitReference() | ||
} | ||
|
||
export const RevisionsPopoverBranches = () => <RevisionsPopoverStory initialTabIndex={0} /> | ||
export const RevisionsPopoverTags = () => <RevisionsPopoverStory initialTabIndex={1} /> | ||
export const RevisionsPopoverCommits = () => <RevisionsPopoverStory initialTabIndex={2} /> | ||
export const RevisionsPopoverCommits = Template.bind({}) | ||
RevisionsPopoverCommits.play = async ({ canvasElement }) => { | ||
const { selectCommitTab } = revisionPopoverUserActions(canvasElement) | ||
await selectCommitTab() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just bumped into it here: https://github.com/sourcegraph/sourcegraph/blob/4d0f8e1fcd7cd556a24a95b327000bf9835f789d/client/web/src/nav/Feedback/FeedbackPrompt.story.tsx#L35-L40
Looking forward to merging this PR!