-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add interaction tests for pagelayout sticky #2241
Changes from 1 commit
a571916
e9ba585
2de9c8e
f67bd61
8b11197
ef49be1
41609da
8a92caf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import {Meta} from '@storybook/react' | ||
import {StickyPane} from './PageLayout.stories' | ||
import {within} from '@storybook/testing-library' | ||
import {StickyPane, CustomStickyHeader} from './PageLayout.stories' | ||
import {within, fireEvent} from '@storybook/testing-library' | ||
import {expect} from '@storybook/jest' | ||
import {setTimeout} from 'timers/promises' | ||
|
||
const meta: Meta = { | ||
title: 'Layout/PageLayout/interactions', | ||
|
@@ -389,5 +390,41 @@ NonStickyPane.play = async ({canvasElement}: {canvasElement: HTMLElement}) => { | |
const paragraphRect = paragraph0.getBoundingClientRect() | ||
expect(isInViewPort(paragraphRect)).toBe(false) | ||
} | ||
|
||
CustomStickyHeader.argTypes = { | ||
sticky: { | ||
type: 'boolean', | ||
defaultValue: true | ||
}, | ||
stickyTop: { | ||
type: 'string', | ||
defaultValue: '8rem' | ||
}, | ||
numParagraphsInPane: { | ||
type: 'number', | ||
defaultValue: 10 | ||
}, | ||
numParagraphsInContent: { | ||
type: 'number', | ||
defaultValue: 30 | ||
} | ||
} | ||
|
||
CustomStickyHeader.play = async ({canvasElement}: {canvasElement: HTMLElement}) => { | ||
const canvas = within(canvasElement) | ||
const contentToScroll = await canvas.getByTestId('content3') | ||
contentToScroll.scrollIntoView() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to scroll twice? The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No it doesn't work :( This is what I mean here Maybe I am missing something? Because the fireEvent.scroll didn't work I included contentToScroll. I'll give another go today and let you know if I make it work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah! I had the same experience. It would have been so much better if fireEvent scroll worked in this case.Maybe we aren't using the scrollcontainer effectively? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried it again but no luck 😢 I agree, I think it is about the scroll container. I tried the outer box, the page layout content as scroll containers but none of them are scrollable. (el.scrollHeight-el.clientHight is 0) and I tried giving auto overflow but that doesn't seem to work either. I'll remove this fireEvent for now and maybe down the track, it will be possible to do with user events from SB. |
||
|
||
// fireEvent alternative? | ||
const storyWindow = await canvas.getByTestId('story-window') | ||
await fireEvent.scroll(storyWindow, {top: 600}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They don't yet have a descriptive name feature. However, storybook 7.0.0 is going to support sections within interaction tests I believe! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh cool! I'll remove this then, and we can try later when available. |
||
|
||
const stickyPaneFirstParagraph = await canvas.getByTestId('paragraph0') | ||
const paragraphBoundaries = stickyPaneFirstParagraph.getBoundingClientRect() | ||
const stickyHeader = await canvas.getByTestId('sticky-header') | ||
const stickyHeaderBoundaries = stickyHeader.getBoundingClientRect() | ||
expect(isInViewPort(paragraphBoundaries)).toBe(true) | ||
expect(isInViewPort(stickyHeaderBoundaries)).toBe(true) | ||
} | ||
export default meta | ||
export {StickyPane, NonStickyPane} | ||
export {StickyPane, NonStickyPane, CustomStickyHeader} |
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.
removed it in the next commit