diff --git a/__tests__/components/__snapshots__/NotificationListItem.test.jsx.snap b/__tests__/components/__snapshots__/NotificationListItem.test.jsx.snap index 775e151b0a..35d0b8a450 100644 --- a/__tests__/components/__snapshots__/NotificationListItem.test.jsx.snap +++ b/__tests__/components/__snapshots__/NotificationListItem.test.jsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` initially renders succesfully 1`] = ` +exports[` initially renders succesfully 1`] = ` initially renders succesfully 1`] = ` `; - -exports[` initially renders succesfully 1`] = ` - - - - - - - - - - Foo - - - - - - slack - - - - - - - - - - - - Successful - - - Successful - - - - - - - - - Failure - - - Failure - - - - - - - - - -`; diff --git a/__tests__/pages/Organizations/components/OrganizationAccessList.test.jsx b/__tests__/pages/Organizations/components/OrganizationAccessList.test.jsx deleted file mode 100644 index 1ea9dc9868..0000000000 --- a/__tests__/pages/Organizations/components/OrganizationAccessList.test.jsx +++ /dev/null @@ -1,205 +0,0 @@ -import React from 'react'; - -import { mountWithContexts } from '../../../enzymeHelpers'; -import OrganizationAccessList, { _OrganizationAccessList } from '../../../../src/pages/Organizations/components/OrganizationAccessList'; - -const mockData = [ - { - id: 1, - username: 'boo', - url: '/foo/bar/', - first_name: 'john', - last_name: 'smith', - summary_fields: { - foo: [ - { - role: { - name: 'foo', - id: 2, - user_capabilities: { - unattach: true - } - } - } - ] - } - } -]; - -const organization = { - id: 1, - name: 'Default', - summary_fields: { - object_roles: {}, - user_capabilities: { - edit: true - } - } -}; - -const api = { - foo: () => {} -}; - -describe('', () => { - afterEach(() => { - jest.restoreAllMocks(); - }); - - test('initially renders succesfully', () => { - mountWithContexts( - {}} - removeRole={() => {}} - organization={organization} - />, { context: { network: { api } } } - ); - }); - - test('api response data passed to component gets set to state properly', (done) => { - const wrapper = mountWithContexts( - ({ data: { count: 1, results: mockData } })} - removeRole={() => {}} - organization={organization} - />, { context: { network: { api } } } - ).find('OrganizationAccessList'); - - setImmediate(() => { - expect(wrapper.state().results).toEqual(mockData); - done(); - }); - }); - - test('onSort being passed properly to DataListToolbar component', async (done) => { - const onSort = jest.spyOn(_OrganizationAccessList.prototype, 'onSort'); - const wrapper = mountWithContexts( - ({ data: { count: 1, results: mockData } })} - removeRole={() => {}} - organization={organization} - />, { context: { network: { api } } } - ).find('OrganizationAccessList'); - expect(onSort).not.toHaveBeenCalled(); - - setImmediate(() => { - const rendered = wrapper.update(); - rendered.find('button[aria-label="Sort"]').simulate('click'); - expect(onSort).toHaveBeenCalled(); - done(); - }); - }); - - test('getTeamRoles returns empty array if dataset is missing team_id attribute', (done) => { - const wrapper = mountWithContexts( - ({ data: { count: 1, results: mockData } })} - removeRole={() => {}} - organization={organization} - />, { context: { network: { api } } } - ).find('OrganizationAccessList'); - - setImmediate(() => { - const { results } = wrapper.state(); - results.forEach(result => { - expect(result.teamRoles).toEqual([]); - }); - done(); - }); - }); - - test('test handleWarning, confirmDelete, and removeRole methods for Alert component', (done) => { - const handleWarning = jest.spyOn(_OrganizationAccessList.prototype, 'handleWarning'); - const confirmDelete = jest.spyOn(_OrganizationAccessList.prototype, 'confirmDelete'); - const removeRole = jest.spyOn(_OrganizationAccessList.prototype, 'removeAccessRole'); - const wrapper = mountWithContexts( - ({ data: { count: 1, results: mockData } })} - removeRole={() => {}} - organization={organization} - />, { context: { network: { api } } } - ).find('OrganizationAccessList'); - expect(handleWarning).not.toHaveBeenCalled(); - expect(confirmDelete).not.toHaveBeenCalled(); - expect(removeRole).not.toHaveBeenCalled(); - - setImmediate(() => { - const rendered = wrapper.update().find('ChipButton'); - rendered.find('button[aria-label="close"]').simulate('click'); - expect(handleWarning).toHaveBeenCalled(); - const alertModal = wrapper.update().find('Modal'); - alertModal.find('button[aria-label="Confirm delete"]').simulate('click'); - expect(confirmDelete).toHaveBeenCalled(); - expect(removeRole).toHaveBeenCalled(); - done(); - }); - }); - - test('state is set appropriately when a user tries deleting a role', (done) => { - const wrapper = mountWithContexts( - ({ data: { count: 1, results: mockData } })} - removeRole={() => {}} - organization={organization} - />, { context: { network: { api } } } - ).find('OrganizationAccessList'); - - setImmediate(() => { - const expected = [ - { - deleteType: 'users' - }, - { - deleteRoleId: mockData[0].summary_fields.foo[0].role.id - }, - { - deleteResourceId: mockData[0].id - } - ]; - const rendered = wrapper.update().find('ChipButton'); - rendered.find('button[aria-label="close"]').simulate('click'); - const alertModal = wrapper.update().find('Modal'); - alertModal.find('button[aria-label="Confirm delete"]').simulate('click'); - expect(wrapper.state().warningTitle).not.toBe(null); - expect(wrapper.state().warningMsg).not.toBe(null); - expected.forEach(criteria => { - Object.keys(criteria).forEach(key => { - expect(wrapper.state()[key]).toEqual(criteria[key]); - }); - }); - done(); - }); - }); - - test('add role button visible for user that can edit org', () => { - const wrapper = mountWithContexts( - ({ data: { count: 1, results: mockData } })} - removeRole={() => {}} - organization={organization} - />, { context: { network: { api } } } - ).find('OrganizationAccessList'); - - setImmediate(() => { - const addRole = wrapper.update().find('DataListToolbar').find('PlusIcon'); - expect(addRole.length).toBe(1); - }); - }); - - test('add role button hidden for user that cannot edit org', () => { - const readOnlyOrg = { ...organization }; - readOnlyOrg.summary_fields.user_capabilities.edit = false; - const wrapper = mountWithContexts( - ({ data: { count: 1, results: mockData } })} - removeRole={() => {}} - organization={readOnlyOrg} - />, { context: { network: { api } } } - ).find('OrganizationAccessList'); - - setImmediate(() => { - const addRole = wrapper.update().find('DataListToolbar').find('PlusIcon'); - expect(addRole.length).toBe(0); - }); - }); -}); diff --git a/__tests__/pages/Organizations/screens/Organization/OrganizationAccess.test.jsx b/__tests__/pages/Organizations/screens/Organization/OrganizationAccess.test.jsx index 0c81e9fc55..9956b10100 100644 --- a/__tests__/pages/Organizations/screens/Organization/OrganizationAccess.test.jsx +++ b/__tests__/pages/Organizations/screens/Organization/OrganizationAccess.test.jsx @@ -7,7 +7,13 @@ describe('', () => { let network; const organization = { id: 1, - name: 'Default' + name: 'Default', + summary_fields: { + object_roles: {}, + user_capabilities: { + edit: true + } + } }; const data = { diff --git a/__tests__/pages/Organizations/screens/Organization/__snapshots__/OrganizationAccess.test.jsx.snap b/__tests__/pages/Organizations/screens/Organization/__snapshots__/OrganizationAccess.test.jsx.snap index 3f2019669a..26134846de 100644 --- a/__tests__/pages/Organizations/screens/Organization/__snapshots__/OrganizationAccess.test.jsx.snap +++ b/__tests__/pages/Organizations/screens/Organization/__snapshots__/OrganizationAccess.test.jsx.snap @@ -26,6 +26,12 @@ exports[` initially renders succesfully 1`] = ` Object { "id": 1, "name": "Default", + "summary_fields": Object { + "object_roles": Object {}, + "user_capabilities": Object { + "edit": true, + }, + }, } } > diff --git a/src/components/NotificationsList/NotificationListItem.jsx b/src/components/NotificationsList/NotificationListItem.jsx index b45037b122..5d417cb093 100644 --- a/src/components/NotificationsList/NotificationListItem.jsx +++ b/src/components/NotificationsList/NotificationListItem.jsx @@ -76,10 +76,10 @@ function NotificationListItem (props) { NotificationListItem.propTypes = { notification: shape({ id: number.isRequired, - canToggleNotifications: bool.isRequired, name: string.isRequired, notification_type: string.isRequired, }).isRequired, + canToggleNotifications: bool.isRequired, detailUrl: string.isRequired, errorTurnedOn: bool, successTurnedOn: bool,