Skip to content
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

test: several fixes for the design-system test framework #16502

Merged
merged 7 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import type { Story } from '@storybook/react'

import { createStory, createStorybookConfig } from '../../stories/util'

Expand All @@ -10,7 +9,7 @@ export default createStorybookConfig({
title: 'Components/CollapsibleGroup',
})

export const CollapsibleGroup: Story = createStory(() => {
export const CollapsibleGroup = createStory(() => {
return (
<div>
<CollapsibleGroupComponent title="Expand me">
Expand All @@ -27,7 +26,7 @@ export const CollapsibleGroup: Story = createStory(() => {
)
})

export const Icons: Story = createStory(() => {
export const Icons = createStory(() => {
return (
<div>
<CollapsibleGroupComponent title="Expand me" icons={{ expanded: 'chevron-down', collapsed: 'chevron-right' }}>
Expand Down
6 changes: 3 additions & 3 deletions npm/design-system/src/components/fileTree/FileTree.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('FileTree', () => {

cy.get('[data-cy=virtualized-tree]').focus()

cy.get('.treeChild').eq(0).then(assertSelectedBorder)
cy.contains('.treeChild', '/').then(assertSelectedBorder)
})

it('should preserve focus state', () => {
Expand All @@ -98,7 +98,7 @@ describe('FileTree', () => {

cy.get('[data-cy=virtualized-tree]').focus()

cy.get('.treeChild').eq(2).then(assertSelectedBorder)
cy.contains('.treeChild', 'foo.spec.js').then(assertSelectedBorder)
})

it('should scroll to item on keyboard input', () => {
Expand All @@ -120,7 +120,7 @@ describe('FileTree', () => {

cy.get('[data-cy=virtualized-tree]').focus().type('{downarrow}').type('{downarrow}')

cy.get('.treeChild').eq(4).should('be.visible')
cy.contains('.treeChild', 'File 3').should('be.visible')
})
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable react/jsx-no-bind */
import { Story } from '@storybook/react'
import React from 'react'
import { Button } from '../../core/button/Button'

Expand Down Expand Up @@ -67,7 +66,7 @@ const tree: TreeParent = {
],
}

export const VirtualizedTree: Story = createStory(() => {
export const VirtualizedTree = createStory(() => {
return (
<div>
<Button color="white" aria-label='Before focus'>Before focus</Button>
Expand Down
2 changes: 1 addition & 1 deletion npm/design-system/src/stories/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const createStorybookConfig = (config: Meta): Meta => config
/**
* Compact way of declaring a new story
*/
export const createStory = <T>(template: Story<T>, args?: Partial<T>) => {
export const createStory = <T = any>(template: Story<T>, args?: Partial<T>): Story<T> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the default of any necessary? Can't you just omit that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find out how to.

If I do omit that, TypeScript makes it an unknown which will in turn give me unknown again when inferring the type for the Cypress mount() function... and will error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No matter what I try, I can't seem to get this working :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I figured out why it's being weird. I disabled TypeScript on the specs in the tsconfig, which means TS wasn't trying very hard to properly show the types. Removing the exclude clause has everything work correctly without these type changes (although you might want to change the default value of T to {}:

createStory = <T = {}>(...) => {...}

const story = template.bind({})

story.args = args
Expand Down