-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(structure): Add groundwork for routing and navigation of content (…
…#5) * feat(structure): Add groundwork for routing and navigation of content * feat(navigation): convert tests back to Jest, add RTL and nav tests
- Loading branch information
1 parent
3888dc6
commit 665c4d2
Showing
31 changed files
with
11,040 additions
and
5,481 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,4 @@ | ||
module.exports = { | ||
presets: ['@babel/preset-typescript', '@babel/preset-react'], | ||
plugins: ['@babel/plugin-transform-modules-commonjs'] | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* For a detailed explanation regarding each configuration property, visit: | ||
* https://jestjs.io/docs/configuration | ||
*/ | ||
import type { Config } from 'jest' | ||
|
||
const config: Config = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'jsdom', | ||
roots: ['<rootDir>/src'], | ||
transform: { | ||
'^.+\\.tsx?$': ['ts-jest', { tsconfig: 'tsconfig.jest.json' }], | ||
'^.+\\.m?jsx?$': 'babel-jest', | ||
}, | ||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
moduleNameMapper: { | ||
'\\.(css|less)$': '<rootDir>/src/__mocks__/styleMock.ts', | ||
}, | ||
setupFilesAfterEnv: ['<rootDir>/test.setup.ts'], | ||
transformIgnorePatterns: [ | ||
'/node_modules/(?!(change-case|@?nanostores)/)', | ||
], | ||
} | ||
|
||
export default config |
Large diffs are not rendered by default.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 { NavItem } from '@patternfly/react-core' | ||
|
||
export interface TextContentEntry { | ||
id: string | ||
data: { | ||
id: string | ||
section: string | ||
} | ||
collection: string | ||
} | ||
|
||
interface NavEntryProps { | ||
entry: TextContentEntry | ||
isActive: boolean | ||
} | ||
|
||
export const NavEntry = ({ entry, isActive }: NavEntryProps) => { | ||
const { id } = entry | ||
const { id: entryTitle, section } = entry.data | ||
|
||
return ( | ||
<NavItem itemId={id} to={`/${section}/${id}`} isActive={isActive} id={`nav-entry-${id}`}> | ||
{entryTitle} | ||
</NavItem> | ||
) | ||
} |
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,38 @@ | ||
import { NavExpandable } from '@patternfly/react-core' | ||
import { sentenceCase } from 'change-case' | ||
import { NavEntry, type TextContentEntry } from './NavEntry' | ||
|
||
interface NavSectionProps { | ||
entries: TextContentEntry[] | ||
sectionId: string | ||
activeItem: string | ||
} | ||
|
||
export const NavSection = ({ | ||
entries, | ||
sectionId, | ||
activeItem, | ||
}: NavSectionProps) => { | ||
const isExpanded = window.location.pathname.includes(sectionId) | ||
|
||
const sortedNavEntries = entries.sort((a, b) => | ||
a.data.id.localeCompare(b.data.id), | ||
) | ||
|
||
const isActive = sortedNavEntries.some((entry) => entry.id === activeItem) | ||
|
||
const items = sortedNavEntries.map((entry) => ( | ||
<NavEntry key={entry.id} entry={entry} isActive={activeItem === entry.id} /> | ||
)) | ||
|
||
return ( | ||
<NavExpandable | ||
title={sentenceCase(sectionId)} | ||
isActive={isActive} | ||
isExpanded={isExpanded} | ||
id={`nav-section-${sectionId}`} | ||
> | ||
{items} | ||
</NavExpandable> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
import { NavEntry, TextContentEntry } from '../NavEntry'; | ||
|
||
const mockEntry: TextContentEntry = { | ||
id: 'entry1', | ||
data: { id: 'Entry1', section: 'section1' }, | ||
collection: 'textContent', | ||
}; | ||
|
||
describe('NavEntry', () => { | ||
it('renders without crashing', () => { | ||
render(<NavEntry entry={mockEntry} isActive={false} />); | ||
expect(screen.getByText('Entry1')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the correct link', () => { | ||
render(<NavEntry entry={mockEntry} isActive={false} />); | ||
expect(screen.getByRole('link')).toHaveAttribute('href', '/section1/entry1'); | ||
}); | ||
|
||
it('marks the entry as active if isActive is true', () => { | ||
render(<NavEntry entry={mockEntry} isActive={true} />); | ||
expect(screen.getByRole('link')).toHaveClass('pf-m-current'); | ||
}); | ||
|
||
it('does not mark the entry as active if isActive is false', () => { | ||
render(<NavEntry entry={mockEntry} isActive={false} />); | ||
expect(screen.getByRole('link')).not.toHaveClass('pf-m-current'); | ||
}); | ||
|
||
it('matches snapshot', () => { | ||
const { asFragment } = render(<NavEntry entry={mockEntry} isActive={false} />); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.