-
Notifications
You must be signed in to change notification settings - Fork 122
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
feat(legend): add keyboard navigation #880
Changes from 1 commit
8846dd2
3f66d55
b85af45
5342cc8
5bfd8ab
7ded2df
f783dba
16fcfa7
d0d4a2e
c4b60e1
cfd84a6
8bafadd
09c1048
69c528f
835655f
4637ccc
f7e2f27
ec97027
5b842fe
7753767
bc14508
038f30c
e5a83e4
dc373e8
cde7eb9
07eadda
c78bfce
f751a99
e2f516a
ef51a44
a2cfae8
a85b704
5e29295
35425e2
0538d65
27c4826
58a74d4
326cc37
07fd6e2
92eb0e2
ecc7797
48f01e7
fc8c562
dd19e9d
d14a03a
03ee240
c260426
3631426
64e99f8
02a2555
5bdb611
8932129
55f1628
02a06fe
a5acd93
547f69d
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 | ||
---|---|---|---|---|
|
@@ -347,26 +347,6 @@ class CommonPage { | |||
* @param options | ||||
*/ | ||||
async expectChartAtUrlToMatchScreenshot(url: string, options?: ScreenshotElementAtUrlOptions) { | ||||
await page.evaluateOnNewDocument(() => { | ||||
const style = document.createElement('style'); | ||||
style.type = 'text/css'; | ||||
style.innerHTML = ` | ||||
*, | ||||
*::after, | ||||
*::before, | ||||
.echLegendItem { | ||||
transition-delay: 0s !important; | ||||
transition-duration: 0s !important; | ||||
animation-delay: -0.0001s !important; | ||||
animation-duration: 0s !important; | ||||
animation-play-state: paused !important; | ||||
caret-color: transparent !important; | ||||
};`; | ||||
const storyRoot = document.getElementById('#story-root'); | ||||
if (storyRoot) { | ||||
storyRoot.appendChild(style); | ||||
} | ||||
}); | ||||
await this.expectElementAtUrlToMatchScreenshot(url, this.chartSelector, { | ||||
waitSelector: this.chartWaitSelector, | ||||
...options, | ||||
|
@@ -404,8 +384,8 @@ class CommonPage { | |||
options?: Omit<ScreenshotElementAtUrlOptions, 'action'>, | ||||
) { | ||||
const action = async () => { | ||||
await this.disableAnimations('http://localhost:9001/?path=/story/legend--right'); | ||||
await this.clickMouseRelativeToDOMElement({ top: 242, left: 910 }, this.chartSelector); | ||||
|
||||
// eslint-disable-next-line no-restricted-syntax | ||||
for (const actions of keyboardEvents) { | ||||
await this.pressKey(actions.actionLabel, actions.count); | ||||
|
@@ -460,6 +440,13 @@ class CommonPage { | |||
}); | ||||
} | ||||
|
||||
async disableAnimations(url: string) { | ||||
await this.loadElementFromURL(url, '#story-root'); | ||||
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. This is a good thought. It must replace the But as long as you use this in the
Suggested change
|
||||
await page.evaluate(() => { | ||||
document.querySelector('#story-root')!.classList.add('disable-animations'); | ||||
}); | ||||
} | ||||
|
||||
/** | ||||
* Wait for an element to be on the DOM | ||||
* | ||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -64,27 +64,37 @@ describe('Area series stories', () => { | |||||||||
}); | ||||||||||
}); | ||||||||||
describe('Negative log Areas', () => { | ||||||||||
it('snows negative values with log scale', async () => { | ||||||||||
it('shows negative values with log scale', async () => { | ||||||||||
await common.expectChartAtUrlToMatchScreenshot( | ||||||||||
'http://localhost:9001/?path=/story/area-chart--with-negative-values&knob-Y scale=log', | ||||||||||
); | ||||||||||
}); | ||||||||||
it('snows only positive domain mixed polarity domain', async () => { | ||||||||||
it('shows only positive domain mixed polarity domain', async () => { | ||||||||||
await common.expectChartAtUrlToMatchScreenshot( | ||||||||||
'http://localhost:9001/?path=/story/area-chart--with-negative-and-positive&knob-Y scale=log', | ||||||||||
); | ||||||||||
}); | ||||||||||
|
||||||||||
it('snows only positive values when hiding negative one', async () => { | ||||||||||
const action = async () => await page.click('.echLegendItem:nth-child(2) .echLegendItem__label'); | ||||||||||
it('shows only positive values when hiding negative one', async () => { | ||||||||||
const action = async () => { | ||||||||||
await common.disableAnimations( | ||||||||||
'http://localhost:9001/?path=/story/area-chart--with-negative-and-positive&knob-Y scale=log', | ||||||||||
); | ||||||||||
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 need to repeat the URL navigation again. The
Suggested change
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. 🎉 Good point - please see 5bdb611 |
||||||||||
await page.click('.echLegendItem:nth-child(2) .echLegendItem__label'); | ||||||||||
}; | ||||||||||
await common.expectChartAtUrlToMatchScreenshot( | ||||||||||
'http://localhost:9001/?path=/story/area-chart--with-negative-and-positive&knob-Y scale=log', | ||||||||||
{ action }, | ||||||||||
); | ||||||||||
}); | ||||||||||
|
||||||||||
it('snows only negative values when hiding positive one', async () => { | ||||||||||
const action = async () => await page.click('.echLegendItem:nth-child(1) .echLegendItem__label'); | ||||||||||
it('shows only negative values when hiding positive one', async () => { | ||||||||||
const action = async () => { | ||||||||||
await common.disableAnimations( | ||||||||||
'http://localhost:9001/?path=/story/area-chart--with-negative-and-positive&knob-Y scale=log', | ||||||||||
); | ||||||||||
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. Same as above. Lmk if this doesn't work.
Suggested change
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. It works! Thank you! Please see 5bdb611 |
||||||||||
await page.click('.echLegendItem:nth-child(1) .echLegendItem__label'); | ||||||||||
}; | ||||||||||
await common.expectChartAtUrlToMatchScreenshot( | ||||||||||
'http://localhost:9001/?path=/story/area-chart--with-negative-and-positive&knob-Y scale=log', | ||||||||||
{ action }, | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,9 @@ describe('Legend stories', () => { | |
}); | ||
}); | ||
describe('keyboard navigation', () => { | ||
beforeEach(async () => { | ||
await common.disableAnimations('http://localhost:9001/?path=/story/legend--right'); | ||
}); | ||
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. Is this needed? 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. Good call - totally not needed - removed in 5bdb611 |
||
// eslint-disable-next-line jest/expect-expect | ||
it('should navigate to legend item with tab', async () => { | ||
await common.expectChartWithKeyboardEventsAtUrlToMatchScreenshot( | ||
|
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.
This should be a generic method, why are there specific
top
andleft
values? Is the purpose of this to just click the element to the tap?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.
Yep! Just to make sure that storybook tabbing doesn't go down all the individual stories in the pane before reaching the iframe