Skip to content

Commit

Permalink
fix test regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
peterMuriuki committed Sep 29, 2023
1 parent 10056d9 commit 1d3b1da
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`components/CreateEditUserGroup renders correctly: full user group form 1`] = `"Edit User Group | AdminNameRealm Roles2 itemsAvailable RolesEDIT_KEYCLOAK_USERSVIEW_KEYCLOAK_USERS6 itemsAssigned RolesOPENMRSALL_EVENTSPLANS_FOR_USERrealm-adminoffline_accessuma_authorizationEffective RolesOPENMRSALL_EVENTSPLANS_FOR_USERrealm-adminoffline_accessuma_authorizationSaveCancel"`;
exports[`components/CreateEditUserGroup renders correctly: full user group form 1`] = `"Edit User Group | AdminNameRealm Roles2 itemsAvailable RolesEDIT_KEYCLOAK_USERSVIEW_KEYCLOAK_USERS6 itemsAssigned RolesOPENMRSALL_EVENTSPLANS_FOR_USERrealm-adminoffline_accessuma_authorizationSaveCancel"`;
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ describe('components/CreateEditUserGroup', () => {
});

it('handles error if fetch user group fails when page reloads', async () => {
fetch.mockRejectOnce(new Error('API is down'));
fetch.mockReject(new Error('API is down'));
const mockNotificationError = jest.spyOn(notifications, 'sendErrorNotification');

const wrapper = mount(
Expand All @@ -236,7 +236,10 @@ describe('components/CreateEditUserGroup', () => {
wrapper.update();
});

expect(mockNotificationError).toHaveBeenCalledWith('There was a problem fetching User Group');
expect(mockNotificationError.mock.calls).toEqual([
['There was a problem fetching role mappings'],
['There was a problem fetching role mappings'],
]);
wrapper.unmount();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Col, Space, Spin } from 'antd';
import { Col, Space, Spin, Typography } from 'antd';
import { CloseOutlined } from '@ant-design/icons';
import { Resource404 } from '@opensrp/react-utils';
import { Button } from 'antd';
Expand All @@ -10,6 +10,8 @@ import { useTranslation } from '../../mls';
import { KeycloakUserGroup } from '../../ducks/userGroups';
import { KeycloakUserRole } from 'keycloak-user-management/src/ducks/userRoles';

const { Text } = Typography;

/** typings for the view details component */
export interface ViewDetailsProps {
loading: boolean;
Expand Down Expand Up @@ -59,22 +61,16 @@ const ViewDetails = (props: ViewDetailsProps) => {
</div>
<div className="mb-2 medium mt-2">
<p className="mb-0 font-weight-bold">{t('Roles')}</p>
{effectiveRoles?.length ? (
effectiveRoles.map((role, indx) => {
// append word break to wrap underscored strings with css
const wordBreakRoleName = role.name.split('_').join('_<wbr/>');
return (
<p
key={`${role}-${indx}`}
className="mb-2"
id="realRole"
dangerouslySetInnerHTML={{ __html: wordBreakRoleName }}
/>
);
})
) : (
<p id="noRealRole">{t('No assigned roles')}</p>
)}
<Space direction="vertical" size={1}>
{effectiveRoles?.length ? (
effectiveRoles.map((role) => {
// append word break to wrap underscored strings with css
return <Text key={role.name}>{role.name}</Text>;
})
) : (
<p id="noRealRole">{t('No assigned roles')}</p>
)}
</Space>
</div>
<div className="mb-2 medium mt-2">
<p className="mb-0 font-weight-bold">{t('Members')}</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`View User Group Details works correctly: nominal display 1`] = `"Group uuid123-some-group-uuid-456NameGroup NameRolesROLE_ONEROLE_TWOROLE_THREEMembersname 1 (name-1)undefined undefined (name-2)undefined undefined (name-3)undefined undefined (name-4)"`;
exports[`View User Group Details works correctly: nominal display 1`] = `"Group uuid123-some-group-uuid-456NameGroup NameRolesEDIT_KEYCLOAK_USERSVIEW_KEYCLOAK_USERSMembersname 1 (name-1)undefined undefined (name-2)undefined undefined (name-3)undefined undefined (name-4)"`;

exports[`View User Group Details works correctly: space element 1`] = `
Object {
Expand Down Expand Up @@ -43,33 +43,17 @@ Object {
>
Roles
</p>
<p
className="mb-2"
dangerouslySetInnerHTML={
Object {
"__html": "ROLE_<wbr/>ONE",
}
}
id="realRole"
/>
<p
className="mb-2"
dangerouslySetInnerHTML={
Object {
"__html": "ROLE_<wbr/>TWO",
}
}
id="realRole"
/>
<p
className="mb-2"
dangerouslySetInnerHTML={
Object {
"__html": "ROLE_<wbr/>THREE",
}
}
id="realRole"
/>
<Space
direction="vertical"
size={1}
>
<ForwardRef(Text)>
EDIT_KEYCLOAK_USERS
</ForwardRef(Text)>
<ForwardRef(Text)>
VIEW_KEYCLOAK_USERS
</ForwardRef(Text)>
</Space>
</div>,
<div
className="mb-2 medium mt-2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import flushPromises from 'flush-promises';
import { KeycloakUserGroup } from '../../../ducks/userGroups';
import { UserGroupMembers } from '../../UserGroupsList';
import { Resource404 } from '@opensrp/react-utils';
import { effectiveRoles } from '../../UserGroupsList/tests/fixtures';

const history = createMemoryHistory();
history.push(URL_USER_GROUPS);
Expand Down Expand Up @@ -44,6 +45,7 @@ describe('View User Group Details', () => {
username: 'name-4',
},
] as UserGroupMembers[],
effectiveRoles,
onClose: jest.fn(),
};

Expand All @@ -61,7 +63,7 @@ describe('View User Group Details', () => {

expect(wrapper.text()).toMatchSnapshot('nominal display');
// att test case to capture space element props snapshot
expect(wrapper.find('ViewDetails Space').props()).toMatchSnapshot('space element');
expect(wrapper.find('ViewDetails Space').first().props()).toMatchSnapshot('space element');
wrapper.unmount();
});

Expand Down Expand Up @@ -119,6 +121,7 @@ describe('View User Group Details', () => {
...props.GroupDetails,
realmRoles: [],
},
effectiveRoles: [],
userGroupMembers: [],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,22 @@ export const userGroup1 = {
subGroups: [],
access: { view: true, manage: true, manageMembership: true },
};

export const effectiveRoles = [
{
id: 'cb4d5fc9-3b05-4514-b007-5971adba6d2f',
name: 'EDIT_KEYCLOAK_USERS',
description: 'Allows the management of keycloak users',
composite: true,
clientRole: false,
containerId: 'FHIR_Android',
},
{
id: '55c89f15-94b4-4395-b343-fb57740ff234',
name: 'VIEW_KEYCLOAK_USERS',
description: 'Allows the user to view the users created in keycloak',
composite: true,
clientRole: false,
containerId: 'FHIR_Android',
},
];

0 comments on commit 1d3b1da

Please sign in to comment.