Skip to content

Commit

Permalink
feat: review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Naomi Aro committed Apr 16, 2021
1 parent 610608a commit f3cc819
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 39 deletions.
12 changes: 9 additions & 3 deletions app/components/Layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import {faBars, faUser} from '@fortawesome/free-solid-svg-icons';

const DESKTOP_BREAKPOINT_QUERY = '(min-width: 992px)';

const HeaderLayout = ({
interface Props {
isLoggedIn?: boolean;
isRegistered?: boolean;
fixed?: boolean;
userProfileDropdown?: React.ReactNode;
}
const HeaderLayout: React.FunctionComponent<Props> = ({
isLoggedIn = false,
isRegistered = false,
fixed = false,
userProfileDropdown = null,
userProfileDropdown,
children
}) => {
let mediaMatch;
Expand Down Expand Up @@ -87,7 +93,7 @@ const HeaderLayout = ({
</li>
) : null}
{isLoggedIn ? (
<>{isRegistered && <>{userProfileDropdown}</>}</>
isRegistered && userProfileDropdown
) : (
<>
<li>
Expand Down
7 changes: 2 additions & 5 deletions app/layouts/default-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {graphql, createFragmentContainer} from 'react-relay';
import {defaultLayout_session} from '__generated__/defaultLayout_session.graphql';
import getConfig from 'next/config';
import Header from 'components/Layout/Header';
import UserProfileDropdownContainer from 'containers/User/UserProfileDropdown';
import UserProfileDropdown from 'containers/User/UserProfileDropdown';
import Footer from 'components/Layout/Footer';
import Subheader from 'components/Layout/Subheader';
import Help from 'components/helpers/Help';
Expand Down Expand Up @@ -51,9 +51,7 @@ const DefaultLayout: React.FunctionComponent<Props> = ({
isLoggedIn={Boolean(session)}
isRegistered={Boolean(session?.ciipUserBySub)}
userProfileDropdown={
<UserProfileDropdownContainer
user={session ? session.ciipUserBySub : null}
/>
<UserProfileDropdown user={session ? session.ciipUserBySub : null} />
}
>
{runtimeConfig.SITEWIDE_NOTICE && (
Expand Down Expand Up @@ -201,7 +199,6 @@ export default createFragmentContainer(DefaultLayout, {
session: graphql`
fragment defaultLayout_session on JwtToken {
ciipUserBySub {
__typename
...UserProfileDropdown_user
}
userGroups
Expand Down
24 changes: 16 additions & 8 deletions app/tests/unit/containers/User/UserProfileDropdown.test.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import React from 'react';
import {shallow} from 'enzyme';
import {UserProfileDropdownComponent} from 'containers/User/UserProfileDropdown';
import {UserProfileDropdown_user} from '__generated__/UserProfileDropdown_user.graphql';

// https://github.com/facebook/relay/issues/2394#issuecomment-379590645
const mockRefType: any = null;
const user = {
firstName: 'Hamza',
lastName: 'Javed',
emailAddress: 'hamza@button.is',
' $refType': mockRefType
firstName: 'Test',
lastName: 'Tester',
emailAddress: 'really-long-email-to-see-wrapping@button.is',
' $refType': 'UserProfileDropdown_user'
};
let render;
describe('UserProfileDropdown', () => {
it('matches snapshot', () => {
render = shallow(<UserProfileDropdownComponent user={user} />);
it('matches mobile snapshot', () => {
render = shallow(
<UserProfileDropdownComponent user={user as UserProfileDropdown_user} />
);
expect(render).toMatchSnapshot();
});

it('matches desktop snapshot', () => {
render = shallow(
<UserProfileDropdownComponent user={user as UserProfileDropdown_user} />
);
expect(render).toMatchSnapshot();
});
});
Loading

0 comments on commit f3cc819

Please sign in to comment.