-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
349 additions
and
164 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
46 changes: 46 additions & 0 deletions
46
...ader/SubHeader/SettingsModalButton/SettingsModal/hooks/useSettingsModalMenuTabConfigs.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,46 @@ | ||
import React from 'react'; | ||
import type { SettingsModalTabId } from '../../../../../../types/SettingsModalTabId'; | ||
import { | ||
InformationSquareIcon, | ||
SidebarBothIcon, | ||
ShieldLockIcon, | ||
TimerStartIcon, | ||
} from '@studio/icons'; | ||
import { useTranslation } from 'react-i18next'; | ||
import type { StudioMenuTabType } from '@studio/components'; | ||
|
||
const aboutTabId: SettingsModalTabId = 'about'; | ||
const setupTabId: SettingsModalTabId = 'setup'; | ||
const policyTabId: SettingsModalTabId = 'policy'; | ||
const accessControlTabId: SettingsModalTabId = 'access_control'; | ||
|
||
export const useSettingsModalMenuTabConfigs = () => { | ||
const { t } = useTranslation(); | ||
|
||
const getMenuTabConfigs = (): StudioMenuTabType<SettingsModalTabId>[] => { | ||
return [ | ||
{ | ||
tabId: aboutTabId, | ||
tabName: t(`settings_modal.left_nav_tab_${aboutTabId}`), | ||
icon: <InformationSquareIcon />, | ||
}, | ||
{ | ||
tabId: setupTabId, | ||
tabName: t(`settings_modal.left_nav_tab_${setupTabId}`), | ||
icon: <SidebarBothIcon />, | ||
}, | ||
{ | ||
tabId: policyTabId, | ||
tabName: t(`settings_modal.left_nav_tab_${policyTabId}`), | ||
icon: <ShieldLockIcon />, | ||
}, | ||
{ | ||
tabId: accessControlTabId, | ||
tabName: t(`settings_modal.left_nav_tab_${accessControlTabId}`), | ||
icon: <TimerStartIcon />, | ||
}, | ||
]; | ||
}; | ||
|
||
return { getMenuTabConfigs }; | ||
}; |
41 changes: 0 additions & 41 deletions
41
...nt/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/utils/menuTabConfigs.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { SettingsModalTab } from './SettingsModalTab'; | ||
import type { SettingsModalTabId } from './SettingsModalTabId'; | ||
|
||
export type SettingsModalHandle = { | ||
openSettings: (tab?: SettingsModalTab) => void; | ||
openSettings: (tab?: SettingsModalTabId) => void; | ||
}; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...tend/libs/studio-components/src/components/StudioContentMenu/StudioContentMenu.module.css
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 @@ | ||
.pagesRouterContainer { | ||
.tabsContainer { | ||
background-color: var(--fds-semantic-surface-action-second-subtle); | ||
height: 100%; | ||
} |
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,157 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { userEvent } from '@testing-library/user-event'; | ||
import type { StudioContentMenuProps } from './StudioContentMenu'; | ||
import { StudioContentMenu } from './StudioContentMenu'; | ||
import type { StudioMenuTabType } from './types/StudioMenuTabType'; | ||
|
||
type StudioMenuTabName = 'tab1' | 'tab2' | 'tab3'; | ||
|
||
const onChangeTabMock = jest.fn(); | ||
|
||
const tab1Name = 'My tab'; | ||
const tab1Id: StudioMenuTabName = 'tab1'; | ||
const tab1: StudioMenuTabType<StudioMenuTabName> = { | ||
tabName: tab1Name, | ||
tabId: tab1Id, | ||
icon: <svg></svg>, | ||
}; | ||
const tab2Name = 'My second tab'; | ||
const tab2: StudioMenuTabType<StudioMenuTabName> = { | ||
tabName: tab2Name, | ||
tabId: 'tab2', | ||
icon: <svg></svg>, | ||
}; | ||
|
||
describe('StudioContentMenu', () => { | ||
afterEach(jest.clearAllMocks); | ||
|
||
it('renders an empty contentMenu when there is no provided tabs', () => { | ||
renderStudioContentMenu({ contentTabs: [] }); | ||
const emptyMenu = screen.getByRole('tablist'); | ||
expect(emptyMenu).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the title and icon of a given menu tab', () => { | ||
const iconTitle = 'My icon'; | ||
renderStudioContentMenu({ | ||
contentTabs: [ | ||
{ | ||
...tab1, | ||
icon: <svg data-testid={iconTitle}></svg>, | ||
}, | ||
], | ||
}); | ||
const menuTab = screen.getByRole('tab', { name: tab1Name }); | ||
const menuIcon = screen.getByTestId(iconTitle); | ||
expect(menuTab).toBeInTheDocument(); | ||
expect(menuIcon).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders a tab with "to" prop as a link element', () => { | ||
const link = 'url-link'; | ||
renderStudioContentMenu({ | ||
contentTabs: [ | ||
{ | ||
...tab1, | ||
to: link, | ||
}, | ||
], | ||
}); | ||
const menuTab = screen.getByRole('tab', { name: tab1Name }); | ||
const linkTab = screen.getByRole('link', { name: tab1Name }); | ||
expect(menuTab).toBeInTheDocument(); | ||
expect(linkTab).toBeInTheDocument(); | ||
expect(linkTab).toHaveAttribute('href', link); | ||
}); | ||
|
||
it('allows changing focus to next tab using keyboard', async () => { | ||
const user = userEvent.setup(); | ||
renderStudioContentMenu({ | ||
contentTabs: [tab1, tab2], | ||
}); | ||
const tab1Element = screen.getByRole('tab', { name: tab1Name }); | ||
await user.click(tab1Element); | ||
const tab2Element = screen.getByRole('tab', { name: tab2Name }); | ||
expect(tab2Element).not.toHaveFocus(); | ||
await user.keyboard('{ArrowDown}'); | ||
expect(tab2Element).toHaveFocus(); | ||
}); | ||
|
||
it('keeps focus on current tab if pressing keyDown when focus is on last tab in menu', async () => { | ||
const user = userEvent.setup(); | ||
renderStudioContentMenu({ | ||
contentTabs: [tab1, tab2], | ||
}); | ||
const tab2Element = screen.getByRole('tab', { name: tab2Name }); | ||
await user.click(tab2Element); | ||
expect(tab2Element).toHaveFocus(); | ||
await user.keyboard('{ArrowDown}'); | ||
expect(tab2Element).toHaveFocus(); | ||
}); | ||
|
||
it('allows changing focus to previous tab using keyboard', async () => { | ||
const user = userEvent.setup(); | ||
renderStudioContentMenu({ | ||
contentTabs: [tab1, tab2], | ||
}); | ||
const tab2Element = screen.getByRole('tab', { name: tab2Name }); | ||
await user.click(tab2Element); | ||
const tab1Element = screen.getByRole('tab', { name: tab1Name }); | ||
expect(tab1Element).not.toHaveFocus(); | ||
await user.keyboard('{ArrowUp}'); | ||
expect(tab1Element).toHaveFocus(); | ||
}); | ||
|
||
it('keeps focus on current tab if pressing keyUp when focus is on first tab in menu', async () => { | ||
const user = userEvent.setup(); | ||
renderStudioContentMenu({ | ||
contentTabs: [tab1, tab2], | ||
}); | ||
const tab1Element = screen.getByRole('tab', { name: tab1Name }); | ||
await user.click(tab1Element); | ||
expect(tab1Element).toHaveFocus(); | ||
await user.keyboard('{ArrowUp}'); | ||
expect(tab1Element).toHaveFocus(); | ||
}); | ||
|
||
it('calls onChangeTab when clicking on a menu tab', async () => { | ||
const user = userEvent.setup(); | ||
renderStudioContentMenu({ | ||
contentTabs: [tab1], | ||
}); | ||
const menuTab = screen.getByRole('tab', { name: tab1Name }); | ||
await user.click(menuTab); | ||
expect(onChangeTabMock).toHaveBeenCalledTimes(1); | ||
expect(onChangeTabMock).toHaveBeenCalledWith(tab1Id); | ||
}); | ||
|
||
it('calls onChangeTab when clicking on a menu tab with link', async () => { | ||
const link = 'url-link'; | ||
const user = userEvent.setup(); | ||
renderStudioContentMenu({ | ||
contentTabs: [ | ||
{ | ||
...tab1, | ||
to: link, | ||
}, | ||
], | ||
}); | ||
const menuTab = screen.getByRole('tab', { name: tab1Name }); | ||
await user.click(menuTab); | ||
expect(onChangeTabMock).toHaveBeenCalledTimes(1); | ||
expect(onChangeTabMock).toHaveBeenCalledWith(tab1Id); | ||
}); | ||
}); | ||
|
||
const renderStudioContentMenu = ({ | ||
contentTabs, | ||
}: Partial<StudioContentMenuProps<StudioMenuTabName>> = {}) => { | ||
render( | ||
<StudioContentMenu | ||
contentTabs={contentTabs} | ||
selectedTabId={undefined} | ||
onChangeTab={onChangeTabMock} | ||
/>, | ||
); | ||
}; |
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
12 changes: 4 additions & 8 deletions
12
...tend/libs/studio-components/src/components/StudioContentMenu/StudioContentMenuWrapper.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
Oops, something went wrong.