-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a20712
commit 418dd23
Showing
5 changed files
with
165 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@rocket.chat/fuselage': patch | ||
--- | ||
|
||
fix(fuselage): `CodeSnippet` inheriting `code` css styles |
73 changes: 26 additions & 47 deletions
73
packages/fuselage/src/components/CodeSnippet/CodeSnippet.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 |
---|---|---|
@@ -1,54 +1,33 @@ | ||
import { composeStories } from '@storybook/react'; | ||
import { screen } from '@testing-library/react'; | ||
import { axe, toHaveNoViolations } from 'jest-axe'; | ||
|
||
import { render } from '../../testing'; | ||
|
||
import * as stories from './CodeSnippet.stories'; | ||
|
||
const { Default, CopyButton, CustomButtonName, LoadingCode, DisabledButton } = | ||
composeStories(stories); | ||
|
||
describe('[CodeSnippet Component]', () => { | ||
it('renders without crashing', () => { | ||
render(<Default />); | ||
}); | ||
|
||
it('should display children', () => { | ||
render(<Default>Children</Default>); | ||
screen.getByText('Children'); | ||
}); | ||
|
||
describe('Button behavior', () => { | ||
let onClickSpy: ReturnType<typeof jest.fn>; | ||
beforeEach(() => { | ||
onClickSpy = jest.fn(); | ||
render(<CopyButton onClick={onClickSpy} />); | ||
}); | ||
|
||
it('should display button, when component receives onClick property', () => { | ||
screen.getByRole('button'); | ||
}); | ||
|
||
it('should call onClick function when button is clicked', () => { | ||
const button = screen.getByRole('button'); | ||
button.click(); | ||
expect(onClickSpy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('should change button name, when buttonText property is passed', () => { | ||
render(<CustomButtonName buttonText='custom-name' />); | ||
screen.getByText('custom-name'); | ||
}); | ||
|
||
it('should display skeleton, when there is no children', () => { | ||
const { container } = render(<LoadingCode />); | ||
expect(container.querySelector('.rcx-skeleton')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should should render a disabled button, when buttonDisabled prop is passed', () => { | ||
render(<DisabledButton />); | ||
const button = screen.getByRole('button'); | ||
expect(button).toBeDisabled(); | ||
}); | ||
expect.extend(toHaveNoViolations); | ||
|
||
const testCases = Object.values(composeStories(stories)).map((Story) => [ | ||
Story.storyName || 'Story', | ||
Story, | ||
]); | ||
|
||
describe('[CodeSnippet Rendering]', () => { | ||
test.each(testCases)( | ||
`renders %s without crashing`, | ||
async (_storyname, Story) => { | ||
const tree = render(<Story />); | ||
expect(tree.baseElement).toMatchSnapshot(); | ||
}, | ||
); | ||
|
||
test.each(testCases)( | ||
'%s should have no a11y violations', | ||
async (_storyname, Story) => { | ||
const { container } = render(<Story />); | ||
|
||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}, | ||
); | ||
}); |
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
128 changes: 128 additions & 0 deletions
128
packages/fuselage/src/components/CodeSnippet/__snapshots__/CodeSnippet.spec.tsx.snap
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,128 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`[CodeSnippet Rendering] renders CopyButton without crashing 1`] = ` | ||
<body> | ||
<div> | ||
<pre | ||
class="rcx-box rcx-box--full rcx-code-snippet" | ||
> | ||
<div | ||
class="rcx-box rcx-box--full rcx-code-snippet__codebox" | ||
role="code" | ||
> | ||
curl -L https://go.rocket.chat/i/docker-compose.yml -O | ||
</div> | ||
<div | ||
class="rcx-box rcx-box--full" | ||
> | ||
<button | ||
class="rcx-box rcx-box--full rcx-button--small rcx-button--primary rcx-button" | ||
type="button" | ||
> | ||
<span | ||
class="rcx-button--content" | ||
> | ||
Copy | ||
</span> | ||
</button> | ||
</div> | ||
</pre> | ||
</div> | ||
</body> | ||
`; | ||
|
||
exports[`[CodeSnippet Rendering] renders CustomButtonName without crashing 1`] = ` | ||
<body> | ||
<div> | ||
<pre | ||
class="rcx-box rcx-box--full rcx-code-snippet" | ||
> | ||
<div | ||
class="rcx-box rcx-box--full rcx-code-snippet__codebox" | ||
role="code" | ||
> | ||
curl -L https://go.rocket.chat/i/docker-compose.yml -O | ||
</div> | ||
<div | ||
class="rcx-box rcx-box--full" | ||
> | ||
<button | ||
class="rcx-box rcx-box--full rcx-button--small rcx-button--primary rcx-button" | ||
type="button" | ||
> | ||
<span | ||
class="rcx-button--content" | ||
> | ||
Custom name | ||
</span> | ||
</button> | ||
</div> | ||
</pre> | ||
</div> | ||
</body> | ||
`; | ||
|
||
exports[`[CodeSnippet Rendering] renders Default without crashing 1`] = ` | ||
<body> | ||
<div> | ||
<pre | ||
class="rcx-box rcx-box--full rcx-code-snippet" | ||
> | ||
<div | ||
class="rcx-box rcx-box--full rcx-code-snippet__codebox" | ||
role="code" | ||
> | ||
curl -L https://go.rocket.chat/i/docker-compose.yml -O | ||
</div> | ||
</pre> | ||
</div> | ||
</body> | ||
`; | ||
|
||
exports[`[CodeSnippet Rendering] renders DisabledButton without crashing 1`] = ` | ||
<body> | ||
<div> | ||
<pre | ||
class="rcx-box rcx-box--full rcx-code-snippet" | ||
> | ||
<div | ||
class="rcx-box rcx-box--full rcx-code-snippet__codebox" | ||
role="code" | ||
> | ||
curl -L https://go.rocket.chat/i/docker-compose.yml -O | ||
</div> | ||
<div | ||
class="rcx-box rcx-box--full" | ||
> | ||
<button | ||
class="rcx-box rcx-box--full rcx-button--small rcx-button--primary rcx-button" | ||
disabled="" | ||
type="button" | ||
> | ||
<span | ||
class="rcx-button--content" | ||
> | ||
Disabled Button | ||
</span> | ||
</button> | ||
</div> | ||
</pre> | ||
</div> | ||
</body> | ||
`; | ||
|
||
exports[`[CodeSnippet Rendering] renders LoadingCode without crashing 1`] = ` | ||
<body> | ||
<div> | ||
<pre | ||
class="rcx-box rcx-box--full rcx-code-snippet" | ||
> | ||
<span | ||
aria-busy="true" | ||
aria-hidden="true" | ||
class="rcx-skeleton rcx-skeleton--text rcx-css-1qcz93u" | ||
/> | ||
</pre> | ||
</div> | ||
</body> | ||
`; |