diff --git a/frontend/kesaseteli/shared/src/__tests__/utils/component-apis/header-api.ts b/frontend/kesaseteli/shared/src/__tests__/utils/component-apis/header-api.ts index 655252a58b..d3303a7fb2 100644 --- a/frontend/kesaseteli/shared/src/__tests__/utils/component-apis/header-api.ts +++ b/frontend/kesaseteli/shared/src/__tests__/utils/component-apis/header-api.ts @@ -13,12 +13,6 @@ const defaultTranslations = { en: 'In English', }; -const languageMenuButtonAriaLabels = { - fi: 'Valitse kieli', - sv: 'Ändra språk', - en: 'Select language', -}; - const expectations = { userIsLoggedIn: async (expectedUser?: User): Promise => { await screen.findByRole('button', { @@ -79,7 +73,7 @@ const actions = { toLang: Language ): Promise => { return userEvent.click( - screen.getAllByRole('link', { + screen.getAllByRole('button', { name: new RegExp( `(${defaultTranslations[toLang]})|(languages.${toLang})`, 'i' diff --git a/frontend/shared/browser-tests/page-models/Header.ts b/frontend/shared/browser-tests/page-models/Header.ts index 4261fa3a9d..c146b18c86 100644 --- a/frontend/shared/browser-tests/page-models/Header.ts +++ b/frontend/shared/browser-tests/page-models/Header.ts @@ -30,14 +30,8 @@ class Header< .nth(0); } - private languageSelector(): SelectorPromise { - return this.withinNavigationActions.findByRole('button', { - name: this.translations.header.languageMenuButtonAriaLabel, - }); - } - private languageSelectorItem(toLang: Language): SelectorPromise { - return this.withinNavigationActions.findByRole('link', { + return this.withinNavigationActions.findByRole('button', { name: this.translations.languages[toLang], }); } @@ -74,9 +68,7 @@ class Header< } public async changeLanguage(toLang: Language): Promise { - return t - .click(this.languageSelector()) - .click(this.languageSelectorItem(toLang)); + return t.click(this.languageSelectorItem(toLang)); } public clickLoginButton(): Promise { diff --git a/frontend/shared/src/components/header/Header.tsx b/frontend/shared/src/components/header/Header.tsx deleted file mode 100644 index 8b814ead22..0000000000 --- a/frontend/shared/src/components/header/Header.tsx +++ /dev/null @@ -1,175 +0,0 @@ -import { IconGlobe, IconSignout, LogoLanguage, Navigation } from 'hds-react'; -import React from 'react'; -import { MAIN_CONTENT_ID } from 'shared/constants'; -import useGoToPage from 'shared/hooks/useGoToPage'; -import { - NavigationItem, - NavigationVariant, - OptionType, - ThemeOption, -} from 'shared/types/common'; -import { isTabActive } from 'shared/utils/menu.utils'; - -import { useHeader } from './useHeader'; - -export type HeaderProps = { - title?: string; - titleUrl?: string; - skipToContentLabel?: string; - menuToggleAriaLabel?: string; - languages?: OptionType[]; - isNavigationVisible?: boolean; - navigationItems?: NavigationItem[]; - customItems?: React.ReactNode[]; - navigationVariant?: NavigationVariant; - onLanguageChange?: ( - e: React.SyntheticEvent, - language: OptionType - ) => void; - login?: { - isAuthenticated: boolean; - loginLabel: string; - logoutLabel: string; - userAriaLabelPrefix: string; - onLogin: () => void; - onLogout: () => void; - userName?: string; - }; - theme?: ThemeOption; - hideLogin?: boolean; - onTitleClick?: () => void; - className?: string; - customActiveItemFn?: (url: string) => boolean; -}; - -const Header: React.FC = ({ - skipToContentLabel, - title, - titleUrl, - menuToggleAriaLabel, - languages, - isNavigationVisible = true, - navigationItems, - navigationVariant, - customItems, - onLanguageChange, - login, - hideLogin, - theme, - onTitleClick, - className, - customActiveItemFn, -}) => { - const { - locale, - logoLang, - menuOpen, - toggleMenu, - closeMenu, - handleLogin, - handleLogout, - t, - } = useHeader(login); - - const goToPage = useGoToPage(); - - const handleClickLink = React.useCallback( - (url = '/') => - (event?: Event | MouseEvent) => { - event?.preventDefault(); - closeMenu(); - goToPage(url as string); - }, - [closeMenu, goToPage] - ); - - return ( -
- - {isNavigationVisible && navigationItems && ( - - {navigationItems?.map((item) => ( - handleClickLink(item.url)} - icon={item.icon} - > - {item.label} - - ))} - - )} - - - {customItems?.map((item, index) => ( - // eslint-disable-next-line react/no-array-index-key - - {item} - - ))} - {login && !hideLogin && ( - - } - /> - - )} - {languages && onLanguageChange && ( - } - closeOnItemClick - > - {languages.map((option) => ( - ) => - onLanguageChange(e, option) - } - /> - ))} - - )} - - -
- ); -}; - -export default Header; diff --git a/frontend/shared/src/components/header/__tests__/Header.test.tsx b/frontend/shared/src/components/header/__tests__/Header.test.tsx index b943aa8b93..12af7ce866 100644 --- a/frontend/shared/src/components/header/__tests__/Header.test.tsx +++ b/frontend/shared/src/components/header/__tests__/Header.test.tsx @@ -2,7 +2,7 @@ import { axe } from 'jest-axe'; import React from 'react'; import { render } from 'shared/__tests__/utils/test-utils'; -import Header from '../Header'; +import Header from '../HeaderV3'; // "svg elements with an img role have an alternative text (svg-img-alt)" test.skip('test for accessibility violations', async () => { diff --git a/frontend/shared/src/components/header/useHeader.ts b/frontend/shared/src/components/header/useHeader.ts index 80e7b40c62..d0765a7763 100644 --- a/frontend/shared/src/components/header/useHeader.ts +++ b/frontend/shared/src/components/header/useHeader.ts @@ -1,6 +1,6 @@ import { TFunction, useTranslation } from 'next-i18next'; import { useState } from 'react'; -import { HeaderProps } from 'shared/components/header/Header'; +import { HeaderProps } from 'shared/components/header/HeaderV3'; import useLocale from 'shared/hooks/useLocale'; import { Language } from 'shared/i18n/i18n';