diff options
Diffstat (limited to 'server/sonar-web/src/main/js/apps/users')
12 files changed, 701 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/apps/users/__tests__/Header-test.tsx b/server/sonar-web/src/main/js/apps/users/__tests__/Header-test.tsx new file mode 100644 index 00000000000..4cfe8b1b42a --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/__tests__/Header-test.tsx @@ -0,0 +1,37 @@ +/* + * 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} />); +} diff --git a/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-test.tsx b/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-test.tsx new file mode 100644 index 00000000000..eae63060e53 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-test.tsx @@ -0,0 +1,92 @@ +/* + * 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: {} } + } + ); +} diff --git a/server/sonar-web/src/main/js/apps/users/__tests__/UsersList.tsx b/server/sonar-web/src/main/js/apps/users/__tests__/UsersList.tsx new file mode 100644 index 00000000000..aa3ed1b718a --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/__tests__/UsersList.tsx @@ -0,0 +1,70 @@ +/* + * 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} + /> + ); +} diff --git a/server/sonar-web/src/main/js/apps/users/__tests__/__snapshots__/Header-test.tsx.snap b/server/sonar-web/src/main/js/apps/users/__tests__/__snapshots__/Header-test.tsx.snap new file mode 100644 index 00000000000..6e38124302c --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/__tests__/__snapshots__/Header-test.tsx.snap @@ -0,0 +1,33 @@ +// 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> +`; diff --git a/server/sonar-web/src/main/js/apps/users/__tests__/__snapshots__/UsersApp-test.tsx.snap b/server/sonar-web/src/main/js/apps/users/__tests__/__snapshots__/UsersApp-test.tsx.snap new file mode 100644 index 00000000000..8aff49f07ed --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/__tests__/__snapshots__/UsersApp-test.tsx.snap @@ -0,0 +1,100 @@ +// 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> +`; diff --git a/server/sonar-web/src/main/js/apps/users/__tests__/__snapshots__/UsersList.tsx.snap b/server/sonar-web/src/main/js/apps/users/__tests__/__snapshots__/UsersList.tsx.snap new file mode 100644 index 00000000000..4b732ab0f36 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/__tests__/__snapshots__/UsersList.tsx.snap @@ -0,0 +1,64 @@ +// 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> +`; diff --git a/server/sonar-web/src/main/js/apps/users/components/__tests__/UserActions-test.tsx b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserActions-test.tsx new file mode 100644 index 00000000000..4e215347a51 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserActions-test.tsx @@ -0,0 +1,60 @@ +/* + * 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} /> + ); +} diff --git a/server/sonar-web/src/main/js/apps/users/components/__tests__/UserGroups-test.tsx b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserGroups-test.tsx new file mode 100644 index 00000000000..bc87f01dad8 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserGroups-test.tsx @@ -0,0 +1,54 @@ +/* + * 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} />); +} diff --git a/server/sonar-web/src/main/js/apps/users/components/__tests__/UserListItem-test.tsx b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserListItem-test.tsx new file mode 100644 index 00000000000..632020a9068 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserListItem-test.tsx @@ -0,0 +1,61 @@ +/* + * 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} + /> + ); +} diff --git a/server/sonar-web/src/main/js/apps/users/components/__tests__/__snapshots__/UserActions-test.tsx.snap b/server/sonar-web/src/main/js/apps/users/components/__tests__/__snapshots__/UserActions-test.tsx.snap new file mode 100644 index 00000000000..6328daaf8e0 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/components/__tests__/__snapshots__/UserActions-test.tsx.snap @@ -0,0 +1,23 @@ +// 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> +`; diff --git a/server/sonar-web/src/main/js/apps/users/components/__tests__/__snapshots__/UserGroups-test.tsx.snap b/server/sonar-web/src/main/js/apps/users/components/__tests__/__snapshots__/UserGroups-test.tsx.snap new file mode 100644 index 00000000000..cbc45cc9034 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/components/__tests__/__snapshots__/UserGroups-test.tsx.snap @@ -0,0 +1,36 @@ +// 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> +`; diff --git a/server/sonar-web/src/main/js/apps/users/components/__tests__/__snapshots__/UserListItem-test.tsx.snap b/server/sonar-web/src/main/js/apps/users/components/__tests__/__snapshots__/UserListItem-test.tsx.snap new file mode 100644 index 00000000000..c7e647b57dd --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/components/__tests__/__snapshots__/UserListItem-test.tsx.snap @@ -0,0 +1,71 @@ +// 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> +`; |