Skip to content

Commit

Permalink
feat(core): create <UserMenu /> component
Browse files Browse the repository at this point in the history
  • Loading branch information
aneurysmjs committed Aug 19, 2019
1 parent 72cf431 commit 7e293c1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/app/components/core/UserMenu/UserMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @flow strict
import React from 'react';

import Icon from '@/components/base/Icon/Icon';

import './UserMenu.scss';

type PropsType = {
onClick?: () => void,
};

const UserMenu = ({
onClick = () => {},
}: PropsType) => (
<div className="user-menu">
<span
tabIndex="-1"
role="button"
onKeyPress={() => {}}
onClick={onClick}
>
<Icon
size="20"
path="icons/cart"
/>
</span>
</div>
);

export default UserMenu;
9 changes: 9 additions & 0 deletions src/app/components/core/UserMenu/UserMenu.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import '~styles/functions/px-to-rem';
@import '~styles/mixins';
@import '~styles/variables';

.user-menu {
align-items: center;
display: flex;
padding: 0 px-to-rem(16);
}
21 changes: 21 additions & 0 deletions src/app/components/core/UserMenu/UserMenu.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @flow strict
import React from 'react';
import { act } from 'react-dom/test-utils';
// $FlowFixMe
import { fireEvent, render } from '@testing-library/react';

import UserMenu from './UserMenu';

describe('UserMenu', () => {
it('should call \'onClick\' prop', async () => {
const mockOnClick = jest.fn();
let testRenderer = {};
await act(async () => {
testRenderer = render(<UserMenu onClick={mockOnClick} />);
});
const { queryByRole } = testRenderer;
const button = queryByRole('button');
fireEvent.click(button);
expect(mockOnClick.mock.calls.length).toBe(1);
});
});
3 changes: 3 additions & 0 deletions src/app/components/core/UserMenu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @flow strict
// eslint-disable-next-line import/prefer-default-export
export { default as UserMenu } from './UserMenu';

0 comments on commit 7e293c1

Please sign in to comment.