};
type Props = {
+ appState: {
+ organizationsEnabled: boolean
+ },
currentUser: CurrentUser,
fetchMyOrganizations: () => Promise<*>,
location: Object,
};
openDropdown = () => {
- this.props.fetchMyOrganizations().then(() => {
+ this.fetchMyOrganizations().then(() => {
window.addEventListener('click', this.handleClickOutside, true);
this.setState({ open: true });
});
this.setState({ open: false });
};
+ fetchMyOrganizations = () => {
+ if (this.props.appState.organizationsEnabled) {
+ return this.props.fetchMyOrganizations();
+ }
+ return Promise.resolve();
+ };
+
renderAuthenticated() {
const { currentUser, organizations } = this.props;
- const hasOrganizations = organizations.length > 0;
+ const hasOrganizations = this.props.appState.organizationsEnabled && organizations.length > 0;
return (
<li
className={classNames('dropdown js-user-authenticated', { open: this.state.open })}
{ key: 'foo', name: 'Foo' },
{ key: 'bar', name: 'bar' }
];
+const appState = { organizationsEnabled: true };
it('should render the right interface for anonymous user', () => {
const currentUser = { isLoggedIn: false };
const wrapper = shallow(
- <GlobalNavUser currentUser={currentUser} fetchMyOrganizations={() => {}} organizations={[]} />
+ <GlobalNavUser
+ appState={appState}
+ currentUser={currentUser}
+ fetchMyOrganizations={() => {}}
+ organizations={[]}
+ />
);
expect(wrapper).toMatchSnapshot();
});
it('should render the right interface for logged in user', () => {
const wrapper = shallow(
- <GlobalNavUser currentUser={currentUser} fetchMyOrganizations={() => {}} organizations={[]} />
+ <GlobalNavUser
+ appState={appState}
+ currentUser={currentUser}
+ fetchMyOrganizations={() => {}}
+ organizations={[]}
+ />
);
wrapper.setState({ open: true });
expect(wrapper).toMatchSnapshot();
it('should render the users organizations', () => {
const wrapper = shallow(
<GlobalNavUser
+ appState={appState}
+ currentUser={currentUser}
+ fetchMyOrganizations={() => {}}
+ organizations={organizations}
+ />
+ );
+ wrapper.setState({ open: true });
+ expect(wrapper).toMatchSnapshot();
+});
+
+it('should not render the users organizations when they are not activated', () => {
+ const wrapper = shallow(
+ <GlobalNavUser
+ appState={{ organizationsEnabled: false }}
currentUser={currentUser}
fetchMyOrganizations={() => {}}
organizations={organizations}
const fetchMyOrganizations = jest.fn();
const wrapper = shallow(
<GlobalNavUser
+ appState={appState}
currentUser={currentUser}
fetchMyOrganizations={fetchMyOrganizations}
organizations={[]}
const fetchMyOrganizations = jest.fn(() => Promise.resolve());
const wrapper = shallow(
<GlobalNavUser
+ appState={appState}
currentUser={currentUser}
fetchMyOrganizations={fetchMyOrganizations}
organizations={organizations}
const fetchMyOrganizations = jest.fn(() => Promise.resolve());
const wrapper = shallow(
<GlobalNavUser
+ appState={appState}
currentUser={currentUser}
fetchMyOrganizations={fetchMyOrganizations}
organizations={organizations}
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`should not render the users organizations when they are not activated 1`] = `
+<li
+ className="dropdown js-user-authenticated open"
+>
+ <a
+ className="dropdown-toggle navbar-avatar"
+ href="#"
+ onClick={[Function]}
+ >
+ <Connect(Avatar)
+ email="foo@bar.baz"
+ name="foo"
+ size={24}
+ />
+ </a>
+ <ul
+ className="dropdown-menu dropdown-menu-right"
+ >
+ <li
+ className="dropdown-item"
+ >
+ <div
+ className="text-ellipsis text-muted"
+ title="foo"
+ >
+ <strong>
+ foo
+ </strong>
+ </div>
+ <div
+ className="little-spacer-top text-ellipsis text-muted"
+ title="foo@bar.baz"
+ >
+ foo@bar.baz
+ </div>
+ </li>
+ <li
+ className="divider"
+ />
+ <li>
+ <Link
+ onClick={[Function]}
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to="/account"
+ >
+ my_account.page
+ </Link>
+ </li>
+ <li>
+ <a
+ href="#"
+ onClick={[Function]}
+ >
+ layout.logout
+ </a>
+ </li>
+ </ul>
+</li>
+`;
+
exports[`should render the right interface for anonymous user 1`] = `
<li>
<a