Files
freeCodeCamp/client/src/components/Header/header.test.tsx
Bruce Blaser d2332093f6 fix(a11y): main menu a11y updates (#45137)
* fix: main menu a11y updates

* update font menu

* fix: sign in button text alignment

* fix: disabled button font

* fix: language menu font

* remove sign-in from main menu

* fix: add section dividers to menu

* fix: height on language selector menu

* fix: alignment of Menu button text

* fix: language globe icon

* refactor: remove dup selector

* update language menu colors

* refactor: clearer name for language menu display state

* fix: don't close onBlur if Menu button is clicked

* refactor: move globe icon styling to CSS

* refactor: get rid of switch statements

* refactor: remove try catch block

* fix: translate Change language button

* fix: move search into nav menu for mobile layout

* fix: forgot a merge

* refactor: updates for changes in i18n/all-langs

* fix: prevent menu from collapsing when focus is on change language button and user clicks into search

* fix: translate cancel change option in language picker

* feat: add cypress tests

* feat: display the complete language list

* fix: fix TS typing

* fix: force scrollbar on lang menu

* fix: remove scroll bar from lang menu

* fix: close menu when user tabs away from last menu item

* add list role to navigation list to appease Safari

* chore: capitalize Change Language/remove CSS comment

* fix: right side search box alignment in narrow view

* remove extraneous list role

* fix: cypress

Co-authored-by: ahmad abdolsaheb <ahmad.abdolsaheb@gmail.com>
Co-authored-by: moT01 <20648924+moT01@users.noreply.github.com>
2022-06-01 10:39:26 +03:00

93 lines
2.6 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-return */
import React from 'react';
import { create, ReactTestRendererJSON } from 'react-test-renderer';
import AuthOrProfile from './components/auth-or-profile';
jest.mock('../../analytics');
describe('<AuthOrProfile />', () => {
it('has avatar with default border for default users', () => {
const defaultUserProps = {
user: {
username: 'test-user',
picture: 'https://freecodecamp.org/image.png'
},
pending: false,
pathName: '/learn'
};
const componentTree = create(
<AuthOrProfile {...defaultUserProps} />
).toJSON();
expect(avatarHasClass(componentTree, 'default-border')).toBeTruthy();
});
it('has avatar with gold border for donating users', () => {
const donatingUserProps = {
user: {
username: 'test-user',
picture: 'https://freecodecamp.org/image.png',
isDonating: true
},
pending: false,
pathName: '/learn'
};
const componentTree = create(
<AuthOrProfile {...donatingUserProps} />
).toJSON();
expect(avatarHasClass(componentTree, 'gold-border')).toBeTruthy();
});
it('has avatar with blue border for top contributors', () => {
const topContributorUserProps = {
user: {
username: 'test-user',
picture: 'https://freecodecamp.org/image.png',
yearsTopContributor: [2020]
},
pending: false,
pathName: '/learn'
};
const componentTree = create(
<AuthOrProfile {...topContributorUserProps} />
).toJSON();
expect(avatarHasClass(componentTree, 'blue-border')).toBeTruthy();
});
it('has avatar with purple border for donating top contributors', () => {
const topDonatingContributorUserProps = {
user: {
username: 'test-user',
picture: 'https://freecodecamp.org/image.png',
isDonating: true,
yearsTopContributor: [2020]
},
pending: false,
pathName: '/learn'
};
const componentTree = create(
<AuthOrProfile {...topDonatingContributorUserProps} />
).toJSON();
expect(avatarHasClass(componentTree, 'purple-border')).toBeTruthy();
});
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const profileNavItem = (component: any) => component.children[0];
const avatarHasClass = (
componentTree: ReactTestRendererJSON | ReactTestRendererJSON[] | null,
classes: string
) => {
return (
profileNavItem(componentTree).props.className ===
'avatar-container ' + classes
);
};