Skip to content

Commit

Permalink
Fixed Bug #2455 (#2991)
Browse files Browse the repository at this point in the history
* Fixed Bug #2455

* Added test for interface
  • Loading branch information
AryanSwaroop authored Dec 31, 2024
1 parent 6349f3f commit 4713884
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
57 changes: 57 additions & 0 deletions src/screens/UserPortal/People/People.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Provider } from 'react-redux';
import { store } from 'state/store';
import i18nForTest from 'utils/i18nForTest';
import { StaticMockLink } from 'utils/StaticMockLink';
import type { InterfaceMember } from './People';
import People from './People';
import userEvent from '@testing-library/user-event';
import { vi } from 'vitest';
Expand Down Expand Up @@ -167,6 +168,62 @@ describe('Testing People Screen [User Portal]', () => {
expect(screen.queryAllByText('Noble Mittal')).not.toBe([]);
});

function compareProperties(
expectedProps: string[],
actualObject: object,
): boolean {
const actualProps = Object.keys(actualObject);
return expectedProps.every((prop) => actualProps.includes(prop));
}

describe('InterfaceMember properties comparison', () => {
it('should have all required properties', () => {
const expectedProperties = [
'firstName',
'lastName',
'image',
'_id',
'email',
'__typename',
];

const mockValidData: InterfaceMember = {
firstName: 'John',
lastName: 'Doe',
image: 'https://example.com/john.jpg',
_id: '1',
email: '[email protected]',
__typename: 'User',
};

const result = compareProperties(expectedProperties, mockValidData);
expect(result).toBe(true);
});

it('should fail if __typename is replaced with username', () => {
const expectedProperties = [
'firstName',
'lastName',
'image',
'_id',
'email',
'__typename', // Expect this property
];

const mockInvalidData = {
firstName: 'John',
lastName: 'Doe',
image: 'https://example.com/john.jpg',
_id: '1',
email: '[email protected]',
username: 'Member', // Incorrect property
};

const result = compareProperties(expectedProperties, mockInvalidData);
expect(result).toBe(false);
});
});

it('Search works properly by pressing enter', async () => {
render(
<MockedProvider addTypename={false} link={link}>
Expand Down
6 changes: 3 additions & 3 deletions src/screens/UserPortal/People/People.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ interface InterfaceOrganizationCardProps {
sno: string;
}

interface InterfaceMember {
export interface InterfaceMember {
firstName: string;
lastName: string;
image: string;
_id: string;
email: string;
userType: string;
__typename: string;
}

/**
Expand Down Expand Up @@ -243,7 +243,7 @@ export default function people(): JSX.Element {
image: member.image,
id: member._id,
email: member.email,
role: member.userType,
role: member.__typename,
sno: (index + 1).toString(),
};
return <PeopleCard key={index} {...cardProps} />;
Expand Down

0 comments on commit 4713884

Please sign in to comment.