-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a `Help` component that fetches and renders help content from the server. * rename HelpContent to TextualHelp to clarify the type of content it is responsible for rendering * add styling for handling help content overflow * update documentation
- Loading branch information
1 parent
107f43a
commit d438e0f
Showing
13 changed files
with
173 additions
and
78 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"type": "text", | ||
"content": "Hello, World!" | ||
"content": "Welcome to the Manifest Game!\n\n This interactive decision tree will help guide you through common questions and scenarios when using the Environmental Protection Agency's (EPA) e-Manifest system." | ||
} |
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 '@testing-library/jest-dom'; | ||
import { cleanup, render, screen, waitFor } from '@testing-library/react'; | ||
import { Help } from 'components/Help/Help'; | ||
import { delay, http, HttpResponse } from 'msw'; | ||
import { setupServer } from 'msw/node'; | ||
import useTreeStore from 'store'; | ||
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest'; | ||
|
||
const handlers = [ | ||
http.get('/help/:nodeId.json', async (info) => { | ||
const nodeId = info.params.nodeId; | ||
await delay(500); | ||
|
||
return HttpResponse.json({ | ||
type: 'text', | ||
content: `Help Text ${nodeId}`, | ||
}); | ||
}), | ||
]; | ||
|
||
const server = setupServer(...handlers); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
server.resetHandlers(...handlers); | ||
}); | ||
beforeAll(() => server.listen()); | ||
afterAll(() => server.close()); | ||
|
||
describe('Help', () => { | ||
test('renders error message when help content ID is undefined', () => { | ||
render(<Help />); | ||
expect(screen.getByText(/problem/i)).toBeInTheDocument(); | ||
}); | ||
test('renders loader while fetching content', () => { | ||
const helpContentId = 'root'; | ||
useTreeStore.setState({ isOpen: true, helpContentId }); | ||
render(<Help />); | ||
expect(screen.getByTestId(/helpSpinner/i)).toBeInTheDocument(); | ||
}); | ||
test('renders help content after fetch', async () => { | ||
const helpContentId = 'root'; | ||
useTreeStore.setState({ isOpen: true, helpContentId }); | ||
render(<Help />); | ||
await waitFor(() => expect(screen.queryByTestId(/helpSpinner/i)).not.toBeInTheDocument()); | ||
expect(screen.getByText(/Help Text root/i)).toBeInTheDocument(); | ||
}); | ||
}); |
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,28 @@ | ||
import { TextualHelp } from 'components/Help/HelpContent/TextualHelp'; | ||
import { Spinner } from 'components/Spinner/Spinner'; | ||
import { useFetchHelp } from 'hooks'; | ||
import { useHelp } from 'hooks/useHelp/useHelp'; | ||
import React from 'react'; | ||
|
||
/** | ||
* Responsible for retrieving, and displaying information to help users made decisions | ||
* @constructor | ||
*/ | ||
export const Help = () => { | ||
const { helpContentId } = useHelp(); | ||
const { help, error, isLoading } = useFetchHelp(helpContentId); | ||
|
||
if (helpContentId === undefined || error) { | ||
return <p>There was a problem fetching help.</p>; | ||
} | ||
|
||
if (isLoading) { | ||
return <Spinner testId={'helpSpinner'} />; | ||
} | ||
|
||
return ( | ||
<> | ||
<TextualHelp help={help} /> | ||
</> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
14 changes: 7 additions & 7 deletions
14
...nts/Help/HelpContent/HelpContent.spec.tsx → ...nts/Help/HelpContent/TextualHelp.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,25 +1,25 @@ | ||
import '@testing-library/jest-dom'; | ||
import { cleanup, render, screen } from '@testing-library/react'; | ||
import { TextHelp, TextualHelp } from 'components/Help/HelpContent/TextualHelp'; | ||
import { afterEach, describe, expect, test } from 'vitest'; | ||
import { HelpContent, TextHelp } from './HelpContent'; | ||
|
||
afterEach(() => cleanup()); | ||
|
||
describe('HelpContent', () => { | ||
describe('TextualHelp', () => { | ||
test('renders', () => { | ||
render(<HelpContent />); | ||
render(<TextualHelp />); | ||
expect(screen.getByTestId(/help-content/i)).toBeInTheDocument(); | ||
}); | ||
test('returns a friendly message if help prop is empty', () => { | ||
render(<HelpContent />); | ||
render(<TextualHelp />); | ||
expect(screen.getByText(/unavailable/i, { exact: false })).toBeInTheDocument(); | ||
}); | ||
test('accepts an TextHelp object and displays the data as text', () => { | ||
const help: TextHelp = { | ||
type: 'text', | ||
data: 'This is a help message', | ||
content: 'This is a help message', | ||
}; | ||
render(<HelpContent help={help} />); | ||
expect(screen.getByText(help.data)).toBeInTheDocument(); | ||
render(<TextualHelp help={help} />); | ||
expect(screen.getByText(help.content)).toBeInTheDocument(); | ||
}); | ||
}); |
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,29 @@ | ||
import React from 'react'; | ||
|
||
export interface TextHelp { | ||
type: 'text'; | ||
content: string; | ||
} | ||
|
||
interface HelpContentProps { | ||
help?: TextHelp; | ||
} | ||
|
||
/** | ||
* Renders the textual help content | ||
* @constructor | ||
*/ | ||
export const TextualHelp = ({ help }: HelpContentProps) => { | ||
return ( | ||
<div | ||
data-testid={'help-content'} | ||
style={{ | ||
whiteSpace: 'pre-line', | ||
fontSize: '1.2rem', | ||
maxHeight: '100%', | ||
}} | ||
> | ||
{help ? <p>{help.content}</p> : <p> Help is unavailable for this node.</p>} | ||
</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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { useDecisionTree } from './useDecisionTree/useDecisionTree'; | ||
export { useFetchConfig } from './useFetchConfig/useFetchConfig'; | ||
export { useFetchHelp } from './useFetchHelp/useFetchHelp'; | ||
export { useTreeDirection } from './useTreeDirection/useTreeDirection'; | ||
export { useTreeViewport } from './useTreeViewport/useTreeViewport'; |
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