-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(CodeBlock): update tests (#9546)
* chore: update codeblock tests * chore(CodeBlock): update to use getByText * PR feedback from Eric and Titani
- Loading branch information
Showing
6 changed files
with
115 additions
and
71 deletions.
There are no files selected for viewing
41 changes: 23 additions & 18 deletions
41
packages/react-core/src/components/CodeBlock/__tests__/CodeBlock.test.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,30 +1,35 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { CodeBlock } from '../CodeBlock'; | ||
import { CodeBlockAction } from '../CodeBlockAction'; | ||
import { CodeBlockCode } from '../CodeBlockCode'; | ||
import styles from '@patternfly/react-styles/css/components/CodeBlock/code-block'; | ||
|
||
test('CodeBlock renders successfully', () => { | ||
const { asFragment } = render(<CodeBlock>test text</CodeBlock>); | ||
expect(asFragment()).toMatchSnapshot(); | ||
test('CodeBlock renders', () => { | ||
render(<CodeBlock>test text</CodeBlock>); | ||
expect(screen.getByText('test text')).toBeVisible(); | ||
}); | ||
|
||
test('CodeBlockAction renders successfully', () => { | ||
const { asFragment } = render(<CodeBlockAction>action</CodeBlockAction>); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
test(`CodeBlock content renders with class ${styles.codeBlockContent} by default`, () => { | ||
render(<CodeBlock>Test</CodeBlock>); | ||
|
||
test('CodeBlockCode renders successfully', () => { | ||
const { asFragment } = render(<CodeBlockCode>action</CodeBlockCode>); | ||
expect(asFragment()).toMatchSnapshot(); | ||
expect(screen.getByText('Test')).toHaveClass(styles.codeBlockContent); | ||
}); | ||
|
||
test('CodeBlock with components renders successfully', () => { | ||
const { asFragment } = render( | ||
<CodeBlock actions={<CodeBlockAction>button</CodeBlockAction>}> | ||
<CodeBlockCode>inside pre/code tags</CodeBlockCode> | ||
test outer text | ||
test('CodeBlock renders with custom class', () => { | ||
render( | ||
<CodeBlock data-testid="code-block" className="tester"> | ||
Test | ||
</CodeBlock> | ||
); | ||
|
||
expect(screen.getByTestId('code-block')).toHaveClass('tester'); | ||
}); | ||
|
||
test('Renders when actions are passed to CodeBlock', () => { | ||
render(<CodeBlock actions={<div>actions</div>} />); | ||
expect(screen.getByText('actions')).toBeVisible(); | ||
}); | ||
|
||
test('Matches the snapshot', () => { | ||
const { asFragment } = render(<CodeBlock actions={<div>actions</div>}>children</CodeBlock>); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/react-core/src/components/CodeBlock/__tests__/CodeBlockAction.test.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,26 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { CodeBlockAction } from '../CodeBlockAction'; | ||
import styles from '@patternfly/react-styles/css/components/CodeBlock/code-block'; | ||
|
||
test('CodeBlockAction renders', () => { | ||
render(<CodeBlockAction>action</CodeBlockAction>); | ||
expect(screen.getByText('action')).toBeVisible(); | ||
}); | ||
|
||
test(`CodeBlockAction renders with class ${styles.codeBlockActions}-item by default`, () => { | ||
render(<CodeBlockAction>Test</CodeBlockAction>); | ||
|
||
expect(screen.getByText('Test')).toHaveClass(`${styles.codeBlockActions}-item`); | ||
}); | ||
|
||
test('CodeBlockAction renders with custom class', () => { | ||
render(<CodeBlockAction className="tester">Test</CodeBlockAction>); | ||
|
||
expect(screen.getByText('Test')).toHaveClass('tester'); | ||
}); | ||
|
||
test('Matches the snapshot', () => { | ||
const { asFragment } = render(<CodeBlockAction>children</CodeBlockAction>); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); |
36 changes: 36 additions & 0 deletions
36
packages/react-core/src/components/CodeBlock/__tests__/CodeBlockCode.test.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,36 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { CodeBlockCode } from '../CodeBlockCode'; | ||
import styles from '@patternfly/react-styles/css/components/CodeBlock/code-block'; | ||
|
||
test('CodeBlockCode renders', () => { | ||
render(<CodeBlockCode>action</CodeBlockCode>); | ||
expect(screen.getByText('action')).toBeVisible(); | ||
}); | ||
|
||
test(`Renders with class ${styles.codeBlockPre} by default`, () => { | ||
render( | ||
<CodeBlockCode data-testid="code-block-code" className="test"> | ||
Test | ||
</CodeBlockCode> | ||
); | ||
|
||
expect(screen.getByTestId('code-block-code')).toHaveClass(`${styles.codeBlockPre} test`); | ||
}); | ||
|
||
test(`Renders with class ${styles.codeBlockCode} by default`, () => { | ||
render(<CodeBlockCode>Test</CodeBlockCode>); | ||
|
||
expect(screen.getByText('Test')).toHaveClass(styles.codeBlockCode); | ||
}); | ||
|
||
test('Renders with custom class', () => { | ||
render(<CodeBlockCode codeClassName="tester">Test</CodeBlockCode>); | ||
|
||
expect(screen.getByText('Test')).toHaveClass('tester'); | ||
}); | ||
|
||
test('Matches the snapshot', () => { | ||
const { asFragment } = render(<CodeBlockCode>children</CodeBlockCode>); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); |
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
11 changes: 11 additions & 0 deletions
11
...react-core/src/components/CodeBlock/__tests__/__snapshots__/CodeBlockAction.test.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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Matches the snapshot 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="pf-v5-c-code-block__actions-item" | ||
> | ||
children | ||
</div> | ||
</DocumentFragment> | ||
`; |
15 changes: 15 additions & 0 deletions
15
...s/react-core/src/components/CodeBlock/__tests__/__snapshots__/CodeBlockCode.test.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,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Matches the snapshot 1`] = ` | ||
<DocumentFragment> | ||
<pre | ||
class="pf-v5-c-code-block__pre" | ||
> | ||
<code | ||
class="pf-v5-c-code-block__code" | ||
> | ||
children | ||
</code> | ||
</pre> | ||
</DocumentFragment> | ||
`; |