Skip to content
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

chore(SimpleDropdown):add tests, also some lints #300

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions src/app/appLayout/AppToolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import * as React from 'react';
import { useNavigate } from 'react-router-dom';
import {
Checkbox,
Dropdown,
DropdownItem,
Icon,
MenuToggle,
Radio,
ToggleGroup,
ToggleGroupItem,
Toolbar,
Expand All @@ -24,9 +22,11 @@ const AppToolbar: React.FunctionComponent = () => {
const [helpOpen, setHelpOpen] = React.useState<boolean>(false);
const [userDropdownOpen, setUserDropdownOpen] = React.useState<boolean>(false);
const [kebabDropdownOpen, setKebabDropdownOpen] = React.useState<boolean>(false);
const [isDarkTheme, setIsDarkTheme] = React.useState(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches);
const [isDarkTheme, setIsDarkTheme] = React.useState(
window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
);

const applyTheme = (isDark) => {
const applyTheme = isDark => {
const htmlElement = document.getElementsByTagName('html')[0];
if (htmlElement) {
if (isDark) {
Expand Down Expand Up @@ -87,14 +87,32 @@ const AppToolbar: React.FunctionComponent = () => {
>
<ToolbarItem>
<ToggleGroup aria-label="Dark theme toggle group">
<ToggleGroupItem aria-label="light theme toggle" icon={<Icon size="md"><SunIcon /></Icon>} isSelected={!isDarkTheme} onChange={() => {
setIsDarkTheme(false);
applyTheme(false);
}} />
<ToggleGroupItem aria-label="dark theme toggle" icon={<Icon size="md"><MoonIcon /></Icon>} isSelected={isDarkTheme} onChange={() => {
setIsDarkTheme(true);
applyTheme(true);
}} />
<ToggleGroupItem
aria-label="light theme toggle"
icon={
<Icon size="md">
<SunIcon />
</Icon>
}
isSelected={!isDarkTheme}
onChange={() => {
setIsDarkTheme(false);
applyTheme(false);
}}
/>
<ToggleGroupItem
aria-label="dark theme toggle"
icon={
<Icon size="md">
<MoonIcon />
</Icon>
}
isSelected={isDarkTheme}
onChange={() => {
setIsDarkTheme(true);
applyTheme(true);
}}
/>
</ToggleGroup>
</ToolbarItem>
<ToolbarItem>
Expand Down
5 changes: 4 additions & 1 deletion src/components/SimpleDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export const SimpleDropdown: React.FC<ISimpleDropdownProps> = ({
<Dropdown
isOpen={isOpen}
onOpenChange={isOpen => setIsOpen(isOpen)}
onSelect={onSelect}
onSelect={() => {
setIsOpen(false);
onSelect && onSelect();
}}
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle
isFullWidth={isFullWidth}
Expand Down
217 changes: 217 additions & 0 deletions src/components/__tests__/__snapshots__/simpleDropdown.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders proper dom snapshot 1`] = `
<DocumentFragment>
<button
aria-expanded="false"
aria-label="Dropdown menu"
class="pf-v5-c-menu-toggle pf-m-full-width"
type="button"
>
<span
class="pf-v5-c-menu-toggle__text"
>
dropdown label
</span>
<span
class="pf-v5-c-menu-toggle__controls"
>
<span
class="pf-v5-c-menu-toggle__toggle-icon"
>
<svg
aria-hidden="true"
class="pf-v5-svg"
fill="currentColor"
height="1em"
role="img"
viewBox="0 0 320 512"
width="1em"
>
<path
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
/>
</svg>
</span>
</span>
</button>
</DocumentFragment>
`;

exports[`snaptshot after toggle is clicked 1`] = `
<DocumentFragment>
<button
aria-expanded="true"
aria-label="Dropdown menu"
class="pf-v5-c-menu-toggle pf-m-expanded pf-m-full-width"
type="button"
>
<span
class="pf-v5-c-menu-toggle__text"
>
dropdown label
</span>
<span
class="pf-v5-c-menu-toggle__controls"
>
<span
class="pf-v5-c-menu-toggle__toggle-icon"
>
<svg
aria-hidden="true"
class="pf-v5-svg"
fill="currentColor"
height="1em"
role="img"
viewBox="0 0 320 512"
width="1em"
>
<path
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
/>
</svg>
</span>
</span>
</button>
<div
class="pf-v5-c-menu"
data-ouia-component-id="OUIA-Generated-Dropdown-4"
data-ouia-component-type="PF5/Dropdown"
data-ouia-safe="true"
data-popper-escaped="true"
data-popper-placement="bottom-start"
data-popper-reference-hidden="true"
style="position: absolute; left: 0px; top: 0px; z-index: 9999; opacity: 1; transition: opacity 0ms cubic-bezier(.54, 1.5, .38, 1.11); min-width: 0px; transform: translate(0px, 0px);"
>
<div
class="pf-v5-c-menu__content"
>
<ul
class="pf-v5-c-menu__list"
role="menu"
>
<li
class="pf-v5-c-menu__list-item"
data-ouia-component-id="OUIA-Generated-DropdownItem-1"
data-ouia-component-type="PF5/DropdownItem"
data-ouia-safe="true"
role="none"
>
<button
class="pf-v5-c-menu__item"
role="menuitem"
tabindex="0"
type="button"
>
<span
class="pf-v5-c-menu__item-main"
>
<span
class="pf-v5-c-menu__item-text"
>
SSLv23
</span>
</span>
</button>
</li>
<li
class="pf-v5-c-menu__list-item"
data-ouia-component-id="OUIA-Generated-DropdownItem-2"
data-ouia-component-type="PF5/DropdownItem"
data-ouia-safe="true"
role="none"
>
<button
class="pf-v5-c-menu__item"
role="menuitem"
tabindex="-1"
type="button"
>
<span
class="pf-v5-c-menu__item-main"
>
<span
class="pf-v5-c-menu__item-text"
>
TLSv1
</span>
</span>
</button>
</li>
<li
class="pf-v5-c-menu__list-item"
data-ouia-component-id="OUIA-Generated-DropdownItem-3"
data-ouia-component-type="PF5/DropdownItem"
data-ouia-safe="true"
role="none"
>
<button
class="pf-v5-c-menu__item"
role="menuitem"
tabindex="-1"
type="button"
>
<span
class="pf-v5-c-menu__item-main"
>
<span
class="pf-v5-c-menu__item-text"
>
TLSv1.1
</span>
</span>
</button>
</li>
<li
class="pf-v5-c-menu__list-item"
data-ouia-component-id="OUIA-Generated-DropdownItem-4"
data-ouia-component-type="PF5/DropdownItem"
data-ouia-safe="true"
role="none"
>
<button
class="pf-v5-c-menu__item"
role="menuitem"
tabindex="-1"
type="button"
>
<span
class="pf-v5-c-menu__item-main"
>
<span
class="pf-v5-c-menu__item-text"
>
TLSv1.2
</span>
</span>
</button>
</li>
<li
class="pf-v5-c-menu__list-item"
data-ouia-component-id="OUIA-Generated-DropdownItem-5"
data-ouia-component-type="PF5/DropdownItem"
data-ouia-safe="true"
role="none"
>
<button
class="pf-v5-c-menu__item"
role="menuitem"
tabindex="-1"
type="button"
>
<span
class="pf-v5-c-menu__item-main"
>
<span
class="pf-v5-c-menu__item-text"
>
Disable SSL
</span>
</span>
</button>
</li>
</ul>
</div>
</div>
</DocumentFragment>
`;
Loading