--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import * as React from 'react';
+import { shallow } from 'enzyme';
+import Header from '../Header';
+import { click } from '../../../helpers/testUtils';
+
+it('should render correctly', () => {
+ expect(getWrapper()).toMatchSnapshot();
+});
+
+it('should open the user creation form', () => {
+ const wrapper = getWrapper();
+ click(wrapper.find('#users-create'));
+ expect(wrapper.find('UserForm').exists()).toBeTruthy();
+});
+
+function getWrapper(props = {}) {
+ return shallow(<Header loading={true} onUpdateUsers={jest.fn()} {...props} />);
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+/* eslint-disable import/order */
+import * as React from 'react';
+import { Location } from 'history';
+import { shallow } from 'enzyme';
+import UsersApp from '../UsersApp';
+
+jest.mock('../../../api/users', () => ({
+ getIdentityProviders: jest.fn(() =>
+ Promise.resolve({
+ identityProviders: [
+ {
+ backgroundColor: 'blue',
+ iconPath: 'icon/path',
+ key: 'foo',
+ name: 'Foo Provider'
+ }
+ ]
+ })
+ ),
+ searchUsers: jest.fn(() =>
+ Promise.resolve({
+ paging: {
+ pageIndex: 1,
+ pageSize: 1,
+ total: 2
+ },
+ users: [
+ {
+ login: 'luke',
+ name: 'Luke',
+ active: true,
+ scmAccounts: [],
+ local: false
+ }
+ ]
+ })
+ )
+}));
+
+const getIdentityProviders = require('../../../api/users').getIdentityProviders as jest.Mock<any>;
+const searchUsers = require('../../../api/users').searchUsers as jest.Mock<any>;
+
+const currentUser = { isLoggedIn: true, login: 'luke' };
+const location = { pathname: '', query: {} } as Location;
+
+beforeEach(() => {
+ getIdentityProviders.mockClear();
+ searchUsers.mockClear();
+});
+
+it('should render correctly', async () => {
+ const wrapper = getWrapper();
+ expect(wrapper).toMatchSnapshot();
+ expect(getIdentityProviders).toHaveBeenCalled();
+ expect(searchUsers).toHaveBeenCalled();
+ await new Promise(setImmediate);
+ wrapper.update();
+ expect(wrapper).toMatchSnapshot();
+});
+
+function getWrapper(props = {}) {
+ return shallow(
+ <UsersApp
+ currentUser={currentUser}
+ location={location}
+ organizationsEnabled={true}
+ {...props}
+ />,
+ {
+ context: { router: {} }
+ }
+ );
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import * as React from 'react';
+import { shallow } from 'enzyme';
+import UsersList from '../UsersList';
+
+const users = [
+ {
+ login: 'luke',
+ name: 'Luke',
+ active: true,
+ scmAccounts: [],
+ local: false
+ },
+ {
+ login: 'obi',
+ name: 'One',
+ active: true,
+ scmAccounts: [],
+ local: false
+ }
+];
+
+it('should render correctly', () => {
+ expect(getWrapper()).toMatchSnapshot();
+});
+
+it('should show a group column', () => {
+ const wrapper = getWrapper({ organizationsEnabled: false });
+ expect(wrapper.find('th').filterWhere(elem => elem.text() === 'my_profile.groups')).toHaveLength(
+ 1
+ );
+});
+
+function getWrapper(props = {}) {
+ return shallow(
+ <UsersList
+ currentUser={{ isLoggedIn: true, login: 'luke' }}
+ identityProviders={[
+ {
+ backgroundColor: 'blue',
+ iconPath: 'icon/path',
+ key: 'foo',
+ name: 'Foo Provider'
+ }
+ ]}
+ onUpdateUsers={jest.fn()}
+ organizationsEnabled={true}
+ users={users}
+ {...props}
+ />
+ );
+}
--- /dev/null
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly 1`] = `
+<header
+ className="page-header"
+ id="users-header"
+>
+ <h1
+ className="page-title"
+ >
+ users.page
+ </h1>
+ <DeferredSpinner
+ loading={true}
+ timeout={100}
+ />
+ <div
+ className="page-actions"
+ >
+ <button
+ id="users-create"
+ onClick={[Function]}
+ >
+ users.create_user
+ </button>
+ </div>
+ <p
+ className="page-description"
+ >
+ users.page.description
+ </p>
+</header>
+`;
--- /dev/null
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly 1`] = `
+<div
+ className="page page-limited"
+ id="users-page"
+>
+ <HelmetWrapper
+ defer={true}
+ encodeSpecialCharacters={true}
+ title="users.page"
+ />
+ <Header
+ loading={true}
+ onUpdateUsers={[Function]}
+ />
+ <Search
+ query={
+ Object {
+ "search": "",
+ }
+ }
+ updateQuery={[Function]}
+ />
+ <UsersList
+ currentUser={
+ Object {
+ "isLoggedIn": true,
+ "login": "luke",
+ }
+ }
+ identityProviders={Array []}
+ onUpdateUsers={[Function]}
+ organizationsEnabled={true}
+ users={Array []}
+ />
+</div>
+`;
+
+exports[`should render correctly 2`] = `
+<div
+ className="page page-limited"
+ id="users-page"
+>
+ <HelmetWrapper
+ defer={true}
+ encodeSpecialCharacters={true}
+ title="users.page"
+ />
+ <Header
+ loading={false}
+ onUpdateUsers={[Function]}
+ />
+ <Search
+ query={
+ Object {
+ "search": "",
+ }
+ }
+ updateQuery={[Function]}
+ />
+ <UsersList
+ currentUser={
+ Object {
+ "isLoggedIn": true,
+ "login": "luke",
+ }
+ }
+ identityProviders={
+ Array [
+ Object {
+ "backgroundColor": "blue",
+ "iconPath": "icon/path",
+ "key": "foo",
+ "name": "Foo Provider",
+ },
+ ]
+ }
+ onUpdateUsers={[Function]}
+ organizationsEnabled={true}
+ users={
+ Array [
+ Object {
+ "active": true,
+ "local": false,
+ "login": "luke",
+ "name": "Luke",
+ "scmAccounts": Array [],
+ },
+ ]
+ }
+ />
+ <ListFooter
+ count={1}
+ loadMore={[Function]}
+ ready={true}
+ total={2}
+ />
+</div>
+`;
--- /dev/null
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly 1`] = `
+<table
+ className="data zebra"
+ id="users-list"
+>
+ <thead>
+ <tr>
+ <th />
+ <th
+ className="nowrap"
+ />
+ <th
+ className="nowrap"
+ >
+ my_profile.scm_accounts
+ </th>
+ <th
+ className="nowrap"
+ >
+ users.tokens
+ </th>
+ <th
+ className="nowrap"
+ >
+
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ <UserListItem
+ isCurrentUser={true}
+ key="luke"
+ onUpdateUsers={[Function]}
+ organizationsEnabled={true}
+ user={
+ Object {
+ "active": true,
+ "local": false,
+ "login": "luke",
+ "name": "Luke",
+ "scmAccounts": Array [],
+ }
+ }
+ />
+ <UserListItem
+ isCurrentUser={false}
+ key="obi"
+ onUpdateUsers={[Function]}
+ organizationsEnabled={true}
+ user={
+ Object {
+ "active": true,
+ "local": false,
+ "login": "obi",
+ "name": "One",
+ "scmAccounts": Array [],
+ }
+ }
+ />
+ </tbody>
+</table>
+`;
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import * as React from 'react';
+import { shallow } from 'enzyme';
+import { click } from '../../../../helpers/testUtils';
+import UserActions from '../UserActions';
+
+const user = {
+ login: 'obi',
+ name: 'One',
+ active: true,
+ scmAccounts: [],
+ local: false
+};
+
+it('should render correctly', () => {
+ expect(getWrapper()).toMatchSnapshot();
+});
+
+it('should display change password action', () => {
+ expect(
+ getWrapper({ user: { ...user, local: true } })
+ .find('.js-user-change-password')
+ .exists()
+ ).toBeTruthy();
+});
+
+it('should open the update form', () => {
+ const wrapper = getWrapper();
+ click(wrapper.find('.js-user-update'));
+ expect(
+ wrapper
+ .first()
+ .find('UserForm')
+ .exists()
+ ).toBeTruthy();
+});
+
+function getWrapper(props = {}) {
+ return shallow(
+ <UserActions isCurrentUser={false} onUpdateUsers={jest.fn()} user={user} {...props} />
+ );
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import * as React from 'react';
+import { shallow } from 'enzyme';
+import { click } from '../../../../helpers/testUtils';
+import UserGroups from '../UserGroups';
+
+const user = {
+ login: 'obi',
+ name: 'One',
+ active: true,
+ scmAccounts: [],
+ local: false
+};
+
+const groups = ['foo', 'bar', 'baz', 'plop'];
+
+it('should render correctly', () => {
+ expect(getWrapper()).toMatchSnapshot();
+});
+
+it('should show all groups', () => {
+ const wrapper = getWrapper();
+ expect(wrapper.find('li')).toHaveLength(3);
+ click(wrapper.find('.js-user-more-groups'));
+ expect(wrapper.find('li')).toHaveLength(5);
+});
+
+it('should open the groups form', () => {
+ const wrapper = getWrapper();
+ click(wrapper.find('.js-user-groups'));
+ expect(wrapper.find('GroupsForm').exists()).toBeTruthy();
+});
+
+function getWrapper(props = {}) {
+ return shallow(<UserGroups groups={groups} onUpdateUsers={jest.fn()} user={user} {...props} />);
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import * as React from 'react';
+import { shallow } from 'enzyme';
+import { click } from '../../../../helpers/testUtils';
+import UserListItem from '../UserListItem';
+
+const user = {
+ login: 'obi',
+ name: 'One',
+ active: true,
+ scmAccounts: [],
+ local: false
+};
+
+it('should render correctly', () => {
+ expect(getWrapper()).toMatchSnapshot();
+});
+
+it('should display a change password button', () => {
+ expect(
+ getWrapper({ organizationsEnabled: true })
+ .find('UserGroups')
+ .exists()
+ ).toBeFalsy();
+});
+
+it('should open the correct forms', () => {
+ const wrapper = getWrapper();
+ click(wrapper.find('.js-user-tokens'));
+ expect(wrapper.find('TokensForm').exists()).toBeTruthy();
+});
+
+function getWrapper(props = {}) {
+ return shallow(
+ <UserListItem
+ isCurrentUser={false}
+ onUpdateUsers={jest.fn()}
+ organizationsEnabled={false}
+ user={user}
+ {...props}
+ />
+ );
+}
--- /dev/null
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly 1`] = `
+<ActionsDropdown
+ key="actions"
+ menuClassName="dropdown-menu-right"
+>
+ <ActionsDropdownItem
+ className="js-user-update"
+ onClick={[Function]}
+ >
+ update_details
+ </ActionsDropdownItem>
+ <ActionsDropdownDivider />
+ <ActionsDropdownItem
+ className="js-user-deactivate"
+ destructive={true}
+ onClick={[Function]}
+ >
+ users.deactivate
+ </ActionsDropdownItem>
+</ActionsDropdown>
+`;
--- /dev/null
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly 1`] = `
+<ul>
+ <li
+ className="little-spacer-bottom"
+ key="foo"
+ >
+ foo
+ </li>
+ <li
+ className="little-spacer-bottom"
+ key="bar"
+ >
+ bar
+ </li>
+ <li
+ className="little-spacer-bottom"
+ >
+ <a
+ className="js-user-more-groups spacer-right"
+ href="#"
+ onClick={[Function]}
+ >
+ more_x.2
+ </a>
+ <ButtonIcon
+ className="js-user-groups button-small"
+ onClick={[Function]}
+ tooltip="users.update_groups"
+ >
+ <BulletListIcon />
+ </ButtonIcon>
+ </li>
+</ul>
+`;
--- /dev/null
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly 1`] = `
+<tr>
+ <td
+ className="thin nowrap"
+ >
+ <Connect(Avatar)
+ name="One"
+ size={36}
+ />
+ </td>
+ <UserListItemIdentity
+ user={
+ Object {
+ "active": true,
+ "local": false,
+ "login": "obi",
+ "name": "One",
+ "scmAccounts": Array [],
+ }
+ }
+ />
+ <td>
+ <UserScmAccounts
+ scmAccounts={Array []}
+ />
+ </td>
+ <td>
+ <UserGroups
+ groups={Array []}
+ onUpdateUsers={[Function]}
+ user={
+ Object {
+ "active": true,
+ "local": false,
+ "login": "obi",
+ "name": "One",
+ "scmAccounts": Array [],
+ }
+ }
+ />
+ </td>
+ <td>
+ <ButtonIcon
+ className="js-user-tokens spacer-left button-small"
+ onClick={[Function]}
+ tooltip="users.update_tokens"
+ >
+ <BulletListIcon />
+ </ButtonIcon>
+ </td>
+ <td
+ className="thin nowrap text-right"
+ >
+ <UserActions
+ isCurrentUser={false}
+ onUpdateUsers={[Function]}
+ user={
+ Object {
+ "active": true,
+ "local": false,
+ "login": "obi",
+ "name": "One",
+ "scmAccounts": Array [],
+ }
+ }
+ />
+ </td>
+</tr>
+`;