diff --git a/__tests__/components/NavExpandableGroup.test.jsx b/__tests__/components/NavExpandableGroup.test.jsx
new file mode 100644
index 0000000000..68cf571f7d
--- /dev/null
+++ b/__tests__/components/NavExpandableGroup.test.jsx
@@ -0,0 +1,63 @@
+import React from 'react';
+import { MemoryRouter } from 'react-router-dom';
+import { mount } from 'enzyme';
+
+import { Nav } from '@patternfly/react-core';
+import NavExpandableGroup from '../../src/components/NavExpandableGroup';
+
+describe('NavExpandableGroup', () => {
+ test('initialization and render', () => {
+ const component = mount(
+
+
+
+ ).find('NavExpandableGroup').instance();
+
+ expect(component.navItemPaths).toEqual(['/foo', '/bar', '/fiz']);
+ expect(component.isActiveGroup()).toEqual(true);
+ });
+
+ describe('isActivePath', () => {
+ const params = [
+ ['/fo', '/foo', false],
+ ['/foo', '/foo', true],
+ ['/foo/1/bar/fiz', '/foo', true],
+ ['/foo/1/bar/fiz', 'foo', false],
+ ['/foo/1/bar/fiz', 'foo/', false],
+ ['/foo/1/bar/fiz', '/bar', false],
+ ['/foo/1/bar/fiz', '/fiz', false],
+ ];
+
+ params.forEach(([location, path, expected]) => {
+ test(`when location is ${location}', isActivePath('${path}') returns ${expected} `, () => {
+ const component = mount(
+
+
+
+ ).find('NavExpandableGroup').instance();
+
+ expect(component.isActivePath(path)).toEqual(expected);
+ });
+ });
+ });
+});
diff --git a/__tests__/pages/Organizations/views/Organization.add.test.jsx b/__tests__/pages/Organizations/views/Organization.add.test.jsx
index 38a16e732e..30990942a4 100644
--- a/__tests__/pages/Organizations/views/Organization.add.test.jsx
+++ b/__tests__/pages/Organizations/views/Organization.add.test.jsx
@@ -1,5 +1,6 @@
import React from 'react';
import { mount } from 'enzyme';
+import { MemoryRouter } from 'react-router-dom';
let OrganizationAdd;
const getAppWithConfigContext = (context = {
@@ -26,19 +27,23 @@ beforeEach(() => {
describe('', () => {
test('initially renders succesfully', () => {
mount(
-
+
+
+
);
});
test('calls "handleChange" when input values change', () => {
- const spy = jest.spyOn(OrganizationAdd.prototype, 'handleChange');
+ const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'handleChange');
const wrapper = mount(
-
+
+
+
);
expect(spy).not.toHaveBeenCalled();
wrapper.find('input#add-org-form-name').simulate('change', { target: { value: 'foo' } });
@@ -46,15 +51,31 @@ describe('', () => {
expect(spy).toHaveBeenCalledTimes(2);
});
test('calls "onSubmit" when Save button is clicked', () => {
- const spy = jest.spyOn(OrganizationAdd.prototype, 'onSubmit');
+ const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'onSubmit');
const wrapper = mount(
-
+
+
+
);
expect(spy).not.toHaveBeenCalled();
wrapper.find('button.at-C-SubmitButton').prop('onClick')();
expect(spy).toBeCalled();
});
+ test('calls "onCancel" when Cancel button is clicked', () => {
+ const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'onCancel');
+ const wrapper = mount(
+
+
+
+ );
+ expect(spy).not.toHaveBeenCalled();
+ wrapper.find('button.at-C-CancelButton').prop('onClick')();
+ expect(spy).toBeCalled();
+ });
});
diff --git a/src/App.jsx b/src/App.jsx
index dce2891380..6646f6e93e 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -13,9 +13,7 @@ import {
BackgroundImage,
BackgroundImageSrc,
Nav,
- NavExpandable,
NavList,
- NavItem,
Page,
PageHeader,
PageSidebar,
@@ -32,6 +30,7 @@ import HelpDropdown from './components/HelpDropdown';
import LogoutButton from './components/LogoutButton';
import TowerLogo from './components/TowerLogo';
import ConditionalRedirect from './components/ConditionalRedirect';
+import NavExpandableGroup from './components/NavExpandableGroup';
import Applications from './pages/Applications';
import Credentials from './pages/Credentials';
@@ -69,41 +68,6 @@ const language = (navigator.languages && navigator.languages[0])
const languageWithoutRegionCode = language.toLowerCase().split(/[_-]+/)[0];
-const SideNavItems = ({ items, history }) => {
- const currentPath = history.location.pathname.split('/')[1];
- let activeGroup;
- if (currentPath !== '') {
- [{ groupName: activeGroup }] = items
- .map(({ groupName, routes }) => ({
- groupName,
- paths: routes.map(({ path }) => path)
- }))
- .filter(({ paths }) => paths.indexOf(currentPath) > -1);
- } else {
- activeGroup = 'views';
- }
-
- return (items.map(({ title, groupName, routes }) => (
-
- {routes.map(({ path, title: itemTitle }) => (
-
- {itemTitle}
-
- ))}
-
- )));
-};
class App extends React.Component {
constructor(props) {
@@ -176,7 +140,12 @@ class App extends React.Component {
}}
/>
- api.isAuthenticated()} redirectPath="/" path="/login" component={() => } />
+ api.isAuthenticated()}
+ redirectPath="/"
+ path="/login"
+ component={() => }
+ />
(