forked from stoplightio/elements
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(elements-core): article component should not require Router (stop…
- Loading branch information
Showing
5 changed files
with
61 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
39 changes: 39 additions & 0 deletions
39
packages/elements-core/src/components/Docs/Article/Article.spec.tsx
This file contains 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,39 @@ | ||
import { screen } from '@testing-library/dom'; | ||
import { render } from '@testing-library/react'; | ||
import { flow } from 'lodash'; | ||
import * as React from 'react'; | ||
|
||
import { withPersistenceBoundary } from '../../../context/Persistence'; | ||
import { withMosaicProvider } from '../../../hoc/withMosaicProvider'; | ||
import { withRouter } from '../../../hoc/withRouter'; | ||
import type { RoutingProps } from '../../../types'; | ||
import { Article as _Article } from './index'; | ||
|
||
const Article = withMosaicProvider(withPersistenceBoundary(_Article)); | ||
|
||
const ArticleWithRouter = flow( | ||
withRouter, | ||
withPersistenceBoundary, | ||
withMosaicProvider, | ||
)((props: RoutingProps & { data: string }) => { | ||
return <_Article data={props.data} />; | ||
}); | ||
|
||
describe('Article', () => { | ||
it('should not require any router', () => { | ||
const { unmount } = render(<Article data="## Hey there" />); | ||
|
||
expect(screen.getByText(/Hey there/i)).toBeInTheDocument(); | ||
|
||
unmount(); | ||
}); | ||
|
||
it('given hash router, should have correct links', () => { | ||
location.hash = '#/test'; | ||
const { unmount } = render(<ArticleWithRouter router="hash" data="[abc](#abc)" />); | ||
|
||
expect(screen.getByText(/abc/i)).toHaveAttribute('href', '#/test#abc'); | ||
|
||
unmount(); | ||
}); | ||
}); |
This file contains 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 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 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