Skip to content

Conversation

@dlabaj
Copy link
Contributor

@dlabaj dlabaj commented Feb 6, 2025

This closes issue patternfly/patternfly-doc-core#9. Hardens the page template code, and adds unit testing.

@dlabaj dlabaj self-assigned this Feb 6, 2025
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/consistent-type-definitions': 'off',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious on the "why" behind this eslint config change

<KebabDropdownItems />
</DropdownList>
</Dropdown>
<GithubIcon />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think the icon should be passed to an icon prop rather than as a child

Comment on lines +14 to +21
const latestRelease = versions.Releases.find(
(release) => release.latest,
) as Release
const previousReleases = Object.values(versions.Releases).filter(
(release) => !release.hidden && !release.latest,
) as Release []

const previousVersions = Object.values(versions.ArchivedReleases) as Release[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: is there a way we could avoid all these type casts?

itemId={`${version.name}-latest-release`}
key={`${version.name}-latest`}
// eslint-disable-next-line no-nested-ternary
to={isLatest ? '/' : version.href ? version.href : `/${version.name}`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't love this nested ternary either

<DropdownGroup key="Previous releases" label="Previous releases">
<DropdownList>
{previousReleases
.slice(0, 3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: is this slice just a magic number sort of thing where we're grabbing the last three versions just because 3, 4 and 5 are the only previous versions we care about? If so I don't love that.


fireEvent.click(screen.getByText('Release 1.0.0'));

const release2Link = screen.getByText('Release 1.1.0').closest('a');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: instead of using closest could we use a getByRole to grab the anchor element directly?

it('does not render when searchEnabled is false', () => {
render(<SearchComponent searchEnabled={false} />)

const searchInput = screen.queryByPlaceholderText('Search')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I find it odd that the way we're trying to get the searchInput is so different in this test vs the previous test

it('updates the search value when user types', () => {
render(<SearchComponent />)
waitFor(() => {
const searchInput = screen.getByPlaceholderText('Search')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also could we use a getByRole for these queries?

Comment on lines +3 to +20
export const updateThemePreference = (theme: Theme) => {
if(typeof window !== undefined) {
window?.localStorage?.setItem('theme-preference', theme)
document?.querySelector('html')?.classList.toggle('pf-v6-theme-dark', theme === 'dark' );
};
};
export const getThemePreference = (): Theme => {
const theme = window?.localStorage?.getItem ('theme-preference');
return theme !== undefined ? (theme as Theme) : 'system';
};

export const themeLoader = () => {
if(typeof window !== 'undefined') {
window.addEventListener('DOMContentLoaded', ()=> {
updateThemePreference(getThemePreference());
})
};
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add tests for these utils?

</ToolbarItem>
</ToolbarContent>
</PFToolbar>
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add tests for the Toolbar component itself?

@dlabaj dlabaj merged commit 7efdbdd into main Feb 28, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants