-
Notifications
You must be signed in to change notification settings - Fork 18
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
Get tests up to ~20% #252
Open
rebeccaalpert
wants to merge
13
commits into
patternfly:main
Choose a base branch
from
rebeccaalpert:sources-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,007
−62
Open
Get tests up to ~20% #252
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8873289
chore(SourcesCard): Add tests
rebeccaalpert 1a85c24
chore(docs): Get jest to spit out coverage correctly
rebeccaalpert 17a3845
chore(FileDetails): Add tests
rebeccaalpert a91e7e6
chore(FileDetailsLabel): Add tests
rebeccaalpert 0b8f9e7
chore(FileDropZone): Add tests
rebeccaalpert 3167412
chore(LoadingMessage): Add tests
rebeccaalpert 760b901
chore(ChatbotWelcomePrompt): Add tests
rebeccaalpert 4e6512e
chore(JumpButton): Add tests
rebeccaalpert 920a786
chore(docs): Remove unused Cypress test
rebeccaalpert 648cb6f
chore(ResponseActions): Add tests
rebeccaalpert 845360a
chore(Message): Add tests
rebeccaalpert fd962b4
chore(docs): Fix typos
rebeccaalpert 4c97fc7
chore(docs): Rework data-testid
rebeccaalpert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
59 changes: 59 additions & 0 deletions
59
packages/module/src/ChatbotWelcomePrompt/ChatbotWelcomePrompt.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,59 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import ChatbotWelcomePrompt from './ChatbotWelcomePrompt'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
describe('ChatbotWelcomePrompt', () => { | ||
it('should render welcome prompt', () => { | ||
const { container } = render( | ||
<ChatbotWelcomePrompt title="Hello, Chatbot User" description="How may I help you today?" /> | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render correctly', () => { | ||
render(<ChatbotWelcomePrompt title="Hello, Chatbot User" description="How may I help you today?" />); | ||
expect(screen.getByText('Hello, Chatbot User')).toBeTruthy(); | ||
expect(screen.getByText('How may I help you today?')).toBeTruthy(); | ||
}); | ||
it('should render prompts with titles correctly', () => { | ||
render( | ||
<ChatbotWelcomePrompt | ||
title="Hello, Chatbot User" | ||
description="How may I help you today?" | ||
prompts={[{ title: 'Topic 1' }]} | ||
/> | ||
); | ||
expect(screen.getByText('Topic 1')).toBeTruthy(); | ||
}); | ||
it('should render prompts with messages correctly', () => { | ||
render( | ||
<ChatbotWelcomePrompt | ||
title="Hello, Chatbot User" | ||
description="How may I help you today?" | ||
prompts={[{ title: 'Topic 1', message: 'Helpful prompt for Topic 1' }]} | ||
/> | ||
); | ||
expect(screen.getByText('Helpful prompt for Topic 1')).toBeTruthy(); | ||
}); | ||
it('should render prompts with onClick correctly', async () => { | ||
const spy = jest.fn(); | ||
render( | ||
<ChatbotWelcomePrompt | ||
title="Hello, Chatbot User" | ||
description="How may I help you today?" | ||
prompts={[{ title: 'Topic 1', message: 'Helpful prompt for Topic 1', onClick: spy }]} | ||
/> | ||
); | ||
await userEvent.click(screen.getByRole('button', { name: /Topic 1/i })); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
it('should apply className appropriately', () => { | ||
render( | ||
<ChatbotWelcomePrompt title="Hello, Chatbot User" description="How may I help you today?" className="test" /> | ||
); | ||
const element = screen.getByTestId('welcome-prompt'); | ||
expect(element).toHaveClass('test'); | ||
}); | ||
}); |
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
33 changes: 33 additions & 0 deletions
33
packages/module/src/ChatbotWelcomePrompt/__snapshots__/ChatbotWelcomePrompt.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,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ChatbotWelcomePrompt should render welcome prompt 1`] = ` | ||
<div> | ||
<div | ||
class="pf-chatbot--layout--welcome " | ||
data-testid="welcome-prompt" | ||
> | ||
<h1 | ||
class="pf-v6-c-content--h1" | ||
data-ouia-component-id="OUIA-Generated-Content-1" | ||
data-ouia-component-type="PF6/Content" | ||
data-ouia-safe="true" | ||
data-pf-content="true" | ||
> | ||
<span | ||
class="pf-chatbot__hello" | ||
> | ||
Hello, Chatbot User | ||
</span> | ||
<br /> | ||
<span | ||
class="pf-chatbot__question" | ||
> | ||
How may I help you today? | ||
</span> | ||
</h1> | ||
<div | ||
class="pf-chatbot__prompt-suggestions" | ||
/> | ||
</div> | ||
</div> | ||
`; |
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,22 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import FileDetails from './FileDetails'; | ||
|
||
describe('FileDetails', () => { | ||
it('should render file details', () => { | ||
const { container } = render(<FileDetails fileName="test.txt" />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render file details correctly if an extension we support is passed in', () => { | ||
render(<FileDetails fileName="test.txt" />); | ||
expect(screen.getByText('test')).toBeTruthy(); | ||
expect(screen.getByText('TEXT')).toBeTruthy(); | ||
}); | ||
it('should skip language if we do not support an extension', () => { | ||
render(<FileDetails fileName="test.joke" />); | ||
expect(screen.getByText('test')).toBeTruthy(); | ||
expect(screen.queryByTestId('language')).toBeFalsy(); | ||
}); | ||
}); |
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
63 changes: 63 additions & 0 deletions
63
packages/module/src/FileDetails/__snapshots__/FileDetails.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,63 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`FileDetails should render file details 1`] = ` | ||
<div> | ||
<div | ||
class="pf-v6-l-flex pf-m-gap-sm" | ||
> | ||
<div | ||
class="pf-v6-l-flex pf-m-align-items-center pf-m-align-self-center pf-m-justify-content-center pf-chatbot__code-icon" | ||
> | ||
<svg | ||
fill="currentColor" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
width="24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M0 4C0 1.79086 1.79086 0 4 0H20C22.2091 0 24 1.79086 24 4V20C24 22.2091 22.2091 24 20 24H4C1.79086 24 0 22.2091 0 20V4Z" | ||
fill="currentColor" | ||
/> | ||
<g | ||
clip-path="url(#clip0_3280_27505)" | ||
> | ||
<path | ||
d="M13.8204 5.63002C13.3954 5.50752 12.9529 5.75502 12.8304 6.18002L9.63035 17.38C9.50785 17.805 9.75535 18.2475 10.1804 18.37C10.6054 18.4925 11.0479 18.245 11.1704 17.82L14.3704 6.62002C14.4929 6.19502 14.2454 5.75252 13.8204 5.63002ZM15.8354 8.63252C15.5229 8.94502 15.5229 9.45252 15.8354 9.76502L18.0679 12L15.8329 14.235C15.5204 14.5475 15.5204 15.055 15.8329 15.3675C16.1454 15.68 16.6529 15.68 16.9654 15.3675L19.7654 12.5675C20.0779 12.255 20.0779 11.7475 19.7654 11.435L16.9654 8.63502C16.6529 8.32252 16.1454 8.32252 15.8329 8.63502L15.8354 8.63252ZM8.16785 8.63252C7.85535 8.32002 7.34785 8.32002 7.03535 8.63252L4.23535 11.4325C3.92285 11.745 3.92285 12.2525 4.23535 12.565L7.03535 15.365C7.34785 15.6775 7.85535 15.6775 8.16785 15.365C8.48035 15.0525 8.48035 14.545 8.16785 14.2325L5.93285 12L8.16785 9.76502C8.48035 9.45252 8.48035 8.94502 8.16785 8.63252Z" | ||
fill="white" | ||
/> | ||
</g> | ||
<defs> | ||
<clippath> | ||
<rect | ||
fill="white" | ||
height="12.8" | ||
transform="translate(4 5.60001)" | ||
width="16" | ||
/> | ||
</clippath> | ||
</defs> | ||
</svg> | ||
</div> | ||
<div | ||
class="pf-v6-l-stack" | ||
> | ||
<div | ||
class="pf-v6-l-stack__item" | ||
> | ||
<span | ||
class="pf-chatbot__code-fileName" | ||
> | ||
test | ||
</span> | ||
</div> | ||
<div | ||
class="pf-v6-l-stack__item pf-chatbot__code-language" | ||
data-testid="language" | ||
> | ||
TEXT | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
48 changes: 48 additions & 0 deletions
48
packages/module/src/FileDetailsLabel/FileDetailsLabel.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,48 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import FileDetailsLabel from './FileDetailsLabel'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
describe('FileDetailsLabel', () => { | ||
it('should render file details label', () => { | ||
const { container } = render(<FileDetailsLabel fileName="test.txt" />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
it('should render file details correctly if an extension we support is passed in', () => { | ||
render(<FileDetailsLabel fileName="test.txt" />); | ||
expect(screen.getByText('test')).toBeTruthy(); | ||
expect(screen.getByText('TEXT')).toBeTruthy(); | ||
}); | ||
it('should skip language if we do not support an extension', () => { | ||
render(<FileDetailsLabel fileName="test.joke" />); | ||
expect(screen.getByText('test')).toBeTruthy(); | ||
expect(screen.queryByTestId('language')).toBeFalsy(); | ||
}); | ||
it('should not show spinner by default', () => { | ||
render(<FileDetailsLabel fileName="test.txt" />); | ||
expect(screen.queryByTestId('spinner')).toBeFalsy(); | ||
}); | ||
it('should show spinner if loading', () => { | ||
render(<FileDetailsLabel fileName="test.txt" isLoading />); | ||
expect(screen.getByText('test')).toBeTruthy(); | ||
expect(screen.getByText('TEXT')).toBeTruthy(); | ||
expect(screen.queryByTestId('spinner')).toBeTruthy(); | ||
}); | ||
it('should call onClick prop', async () => { | ||
const spy = jest.fn(); | ||
render(<FileDetailsLabel fileName="test.txt" onClick={spy} />); | ||
await userEvent.click(screen.getByRole('button')); | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should call onClose prop', async () => { | ||
const spy = jest.fn(); | ||
render(<FileDetailsLabel fileName="test.txt" onClose={spy} />); | ||
await userEvent.click(screen.getByRole('button', { name: /Close test.txt/i })); | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should use closeButtonAriaLabel prop appropriately', () => { | ||
render(<FileDetailsLabel fileName="test.txt" onClose={jest.fn()} closeButtonAriaLabel="Delete file" />); | ||
screen.getByRole('button', { name: /Delete file/i }); | ||
}); | ||
}); |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is what I changed; rest is formatter.